List of usage examples for com.squareup.okhttp Response handshake
Handshake handshake
To view the source code for com.squareup.okhttp Response handshake.
Click Source Link
From source file:co.paralleluniverse.fibers.okhttp.CallTest.java
License:Open Source License
@Test public void matchingPinnedCertificate() throws Exception { server.get().useHttps(sslContext.getSocketFactory(), false); server.enqueue(new MockResponse()); server.enqueue(new MockResponse()); client.setSslSocketFactory(sslContext.getSocketFactory()); client.setHostnameVerifier(new RecordingHostnameVerifier()); // Make a first request without certificate pinning. Use it to collect certificates to pin. Request request1 = new Request.Builder().url(server.getUrl("/")).build(); Response response1 = FiberOkHttpUtil.executeInFiber(client, request1); CertificatePinner.Builder certificatePinnerBuilder = new CertificatePinner.Builder(); for (Certificate certificate : response1.handshake().peerCertificates()) { certificatePinnerBuilder.add(server.get().getHostName(), CertificatePinner.pin(certificate)); }//from ww w . ja v a 2 s . c o m // Make another request with certificate pinning. It should complete normally. client.setCertificatePinner(certificatePinnerBuilder.build()); Request request2 = new Request.Builder().url(server.getUrl("/")).build(); Response response2 = FiberOkHttpUtil.executeInFiber(client, request2); assertNotSame(response2.handshake(), response1.handshake()); }
From source file:com.anony.okhttp.sample.CertificatePinning.java
License:Apache License
public void run() throws Exception { Request request = new Request.Builder().url("https://publicobject.com/robots.txt").build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); for (Certificate certificate : response.handshake().peerCertificates()) { System.out.println(CertificatePinner.pin(certificate)); }// ww w . jav a 2 s .com }
From source file:io.fabric8.docker.client.utils.SSLUtils.java
License:Apache License
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withDockerUrl(URLUtils.withProtocol(config.getDockerUrl(), Config.HTTPS_PROTOCOL_PREFIX)) .withRequestTimeout(1000).withConnectionTimeout(1000).build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); Response response = null; try {/* www. j a v a 2 s . c o m*/ Request request = new Request.Builder().get().url(sslConfig.getDockerUrl()).build(); response = client.newCall(request).execute(); return response.handshake() != null; } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (response != null) { try { response.body().close(); } catch (IOException e) { //ignore } } if (client != null && client.getConnectionPool() != null) { client.getConnectionPool().evictAll(); } } return false; }
From source file:org.apache.nifi.processors.standard.InvokeHTTP.java
License:Apache License
/** * Returns a Map of flowfile attributes from the response http headers. Multivalue headers are naively converted to comma separated strings. *//*from w ww . j a v a 2s . c om*/ private Map<String, String> convertAttributesFromHeaders(URL url, Response responseHttp) { // create a new hashmap to store the values from the connection Map<String, String> map = new HashMap<>(); for (Map.Entry<String, List<String>> entry : responseHttp.headers().toMultimap().entrySet()) { String key = entry.getKey(); if (key == null) { continue; } List<String> values = entry.getValue(); // we ignore any headers with no actual values (rare) if (values == null || values.isEmpty()) { continue; } // create a comma separated string from the values, this is stored in the map String value = csv(values); // put the csv into the map map.put(key, value); } if ("HTTPS".equals(url.getProtocol().toUpperCase())) { map.put(REMOTE_DN, responseHttp.handshake().peerPrincipal().getName()); } return map; }
From source file:quickbeer.android.next.network.utils.LoginRedirectInterceptor.java
License:Open Source License
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); Response response = chain.proceed(request); if (request.uri().getPath().equals("/Signin_r.asp") && response.isRedirect()) { Log.d(TAG, "Modifying response for login request"); return new Response.Builder().request(request).protocol(response.protocol()).code(200) .message(response.message()).handshake(response.handshake()).headers(response.headers()) .body(response.body()).networkResponse(response.networkResponse()).build(); }//from w w w .jav a2s . co m return response; }