Package com.squareup.okhttp

Examples of com.squareup.okhttp.OkHttpClient


            untrustedSSLContextProvider, proxyForURI);
   }

   @Override
   protected HttpURLConnection initConnection(HttpRequest request) throws IOException {
      OkHttpClient client = new OkHttpClient();
      URL url = request.getEndpoint().toURL();
      client.setProxy(proxyForURI.apply(request.getEndpoint()));
      if (url.getProtocol().equalsIgnoreCase("https")) {
         if (utils.relaxHostname()) {
            client.setHostnameVerifier(verifier);
         }
         if (sslContextSupplier != null) {
            // used for providers which e.g. use certs for authentication (like
            // FGCP) Provider provides SSLContext impl (which inits context with
            // key manager)
            client.setSslSocketFactory(sslContextSupplier.get().getSocketFactory());
         } else if (utils.trustAllCerts()) {
            client.setSslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory());
         }
      }
      return client.open(url);
   }
View Full Code Here


            untrustedSSLContextProvider, proxyForURI);
   }

   @Override
   protected HttpURLConnection initConnection(HttpRequest request) throws IOException {
      OkHttpClient client = new OkHttpClient();
      URL url = request.getEndpoint().toURL();
      client.setProxy(proxyForURI.apply(request.getEndpoint()));
      if (url.getProtocol().equalsIgnoreCase("https")) {
         if (utils.relaxHostname()) {
            client.setHostnameVerifier(verifier);
         }
         if (sslContextSupplier != null) {
            // used for providers which e.g. use certs for authentication (like
            // FGCP) Provider provides SSLContext impl (which inits context with
            // key manager)
            client.setSslSocketFactory(sslContextSupplier.get().getSocketFactory());
         } else if (utils.trustAllCerts()) {
            client.setSslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory());
         }
      }
      return client.open(url);
   }
View Full Code Here

    return client;
  }

  public static OkHttpClient createClient() {
    final OkHttpClient client = new OkHttpClient();
    return configureClient(client);
  }
View Full Code Here

    };
  }

  public static WebHookService createWebHookService(final String url) {

    final OkHttpClient client = ProcessorHelper.createClient();

    final RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(url).setClient(new OkClient(client)).build();

    return restAdapter.create(WebHookService.class);
View Full Code Here

            untrustedSSLContextProvider, proxyForURI);
   }

   @Override
   protected HttpURLConnection initConnection(HttpRequest request) throws IOException {
      OkHttpClient client = new OkHttpClient();
      URL url = request.getEndpoint().toURL();
      client.setProxy(proxyForURI.apply(request.getEndpoint()));
      if (url.getProtocol().equalsIgnoreCase("https")) {
         if (utils.relaxHostname()) {
            client.setHostnameVerifier(verifier);
         }
         if (sslContextSupplier != null) {
            // used for providers which e.g. use certs for authentication (like
            // FGCP) Provider provides SSLContext impl (which inits context with
            // key manager)
            client.setSslSocketFactory(sslContextSupplier.get().getSocketFactory());
         } else if (utils.trustAllCerts()) {
            client.setSslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory());
         }
      }
      return client.open(url);
   }
View Full Code Here

        AlternativeHttpClientImpl http = callOembed();

        // check HTTP/2.0
        Field f = http.getClass().getDeclaredField("client");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNotNull("ensure that OkHttpClient is used", client);

        ConnectionPool p = client.getConnectionPool();
        assertEquals(1, p.getConnectionCount());
        assertEquals(0, p.getHttpConnectionCount());
        assertEquals(1, p.getSpdyConnectionCount());

        assertEquals("HTTP-draft-09/2.0", http.getLastRequestProtocol());
View Full Code Here

        AlternativeHttpClientImpl http = callOembed();

        // check SPDY
        Field f = http.getClass().getDeclaredField("client");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNotNull("ensure that OkHttpClient is used", client);

        ConnectionPool p = client.getConnectionPool();
        assertEquals(1, p.getConnectionCount());
        assertEquals(0, p.getHttpConnectionCount());
        assertEquals(1, p.getSpdyConnectionCount());

        assertEquals("spdy/3.1", http.getLastRequestProtocol());
View Full Code Here

        AlternativeHttpClientImpl http = callOembed();

        // check HTTP/2.0
        Field f = http.getClass().getDeclaredField("client");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNotNull("ensure that OkHttpClient is used", client);

        ConnectionPool p = client.getConnectionPool();
        assertEquals(1, p.getConnectionCount());
        assertEquals(0, p.getHttpConnectionCount());
        assertEquals(1, p.getSpdyConnectionCount());

        assertEquals("HTTP-draft-09/2.0", http.getLastRequestProtocol());
View Full Code Here

        AlternativeHttpClientImpl http = callOembed();

        // check not SPDY
        Field f = http.getClass().getDeclaredField("client");
        f.setAccessible(true);
        OkHttpClient client = (OkHttpClient) f.get(http);
        assertNull(client);     // OkHttpClient was NOT used
    }
View Full Code Here

    }

    private void prepareClient() {

        if (client == null) {
            client = new OkHttpClient();

            // set protocols
            List<Protocol> protocols = new ArrayList<Protocol>();
            protocols.add(Protocol.HTTP_11);
            if (sPreferHttp2) {
View Full Code Here

TOP

Related Classes of com.squareup.okhttp.OkHttpClient

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.