Package org.apache.http.conn.ssl

Examples of org.apache.http.conn.ssl.SSLSocketFactory


        }
    }

    public static Result login() {
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        try {
            HttpPost request = new HttpPost(baseRestUrl + "/login");
            //{"email":"admin@dspace.org","password":"s3cret"}
            //StringEntity params =new StringEntity("{\"email\":\"admin@dspace.org\",\"password\":\"s3cret\"} ");
View Full Code Here


        }
    }

    public static Result logout() {
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        try {
            HttpPost request = new HttpPost(baseRestUrl + "/logout");
            request.addHeader("Content-Type", "application/json");
            String token = session("userToken");
View Full Code Here

        }
    }

    public static Result status() {
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        try {
            HttpGet request = new HttpGet(baseRestUrl + "/status");
            request.setHeader("Accept", "application/json");
            request.addHeader("content-type", "application/json");
View Full Code Here

    }

    public RestResponse update(String token) throws IOException {
        //TODO insecure ssl hack
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        HttpPut request = new HttpPut(Application.baseRestUrl + "/communities/" + this.id);
        request.setHeader("Accept", "application/json");
        request.addHeader("Content-Type", "application/json");
        request.addHeader("rest-dspace-token", token);
View Full Code Here

    public static RestResponse findByID(Long id, String token) throws IOException {
        RestResponse restResponse = new RestResponse();
        //TODO insecure ssl hack
        HttpClient httpClient = new DefaultHttpClient();
        SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        HttpGet request = new HttpGet(Application.baseRestUrl + "/collections/" + id + "?expand=all");
        request.setHeader("Accept", "application/json");
        request.addHeader("Content-Type", "application/json");
        request.addHeader("rest-dspace-token", token);
View Full Code Here

          apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(sslConfiguration.getHostnameVerifier());
        } else {
          apacheHostnameVerifier = new ApacheHostnameVerifierAdapter(
              SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        }
        schemeSocketFactory = new SSLSocketFactory(sslSocketFactory, apacheHostnameVerifier);
      } catch (GeneralSecurityException e) {
        throw new IllegalArgumentException("Error building SSL client", e);
      }

      SchemeRegistry schemeRegistry = new SchemeRegistry();
View Full Code Here

            cookieParams.setSingleHeader(true);

            // Create and initialize scheme registry
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            SSLSocketFactory sf = null;

            for (String contextName : SSL_CONTEXT_NAMES) {
                try {
                    SSLContext sslContext = SSLContext.getInstance(contextName);
                    sslContext.init(null, new TrustManager[] { new DummyX509TrustManager(null) }, null);
                    sf = new SSLSocketFactory(sslContext);
                    break;
                } catch (NoSuchAlgorithmException e) {
                    LOGGER.debug("SSLContext algorithm not available: " + contextName);
                } catch (Exception e) {
                    LOGGER.debug("SSLContext can't be initialized: " + contextName, e);
                }
            }
           
            if (sf != null) {
                sf.setHostnameVerifier(new DummyX509HostnameVerifier());
                schemeRegistry.register(new Scheme("https", sf, 443));
            } else {
                LOGGER.warn("No valid SSLContext found for https");
            }
View Full Code Here

        hostnameVerifier = SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
      }
      javax.net.ssl.SSLSocketFactory sslSocketFactory = SslHelpers
          .buildSslSocketFactory(keyManager, trustManager);

      schemeSocketFactory = new SSLSocketFactory(sslSocketFactory, hostnameVerifier);
    } catch (GeneralSecurityException e) {
      throw new IllegalArgumentException("Error building SSL client", e);
    }

    SchemeRegistry schemeRegistry = new SchemeRegistry();
View Full Code Here

    public static Scheme getMockedScheme() throws NoSuchAlgorithmException, KeyManagementException {
  SSLContext sslcontext = SSLContext.getInstance("TLS");

  sslcontext.init(null, new TrustManager[] { new DummyX509TrustManager() }, null);
  SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
  Scheme https = new Scheme("https", 443, sf);

  return https;
    }
View Full Code Here

    }

    private DefaultHttpClient createClient() {
        try {
            DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
            SSLSocketFactory socketFactory = TrustedSSLSocketFactory.create();
            Scheme sch = new Scheme("https", 443, socketFactory);
            client.getConnectionManager().getSchemeRegistry().register(sch);
            return client;
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException(MessageFormat.format(
View Full Code Here

TOP

Related Classes of org.apache.http.conn.ssl.SSLSocketFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.