List of usage examples for com.squareup.okhttp OkHttpClient getProtocols
public List<Protocol> getProtocols()
From source file:client.lib.Client.java
private Response request(OkHttpClient client, URL url) { Response response = null;//from ww w. java2s. c o m try { System.out.println(client.getProtocols().get(0) + " => " + url.toString()); Request request = new Request.Builder().url(url.toString()).build(); response = client.newCall(request).execute(); System.out.println("> " + response.code() + " " + response.protocol()); } catch (ConnectException e) { System.out.println("ConnectException: " + e.getMessage()); } catch (IOException e) { System.out.println("IOException: " + e.getMessage()); } return response; }
From source file:client.ui.Container.java
private Response request(OkHttpClient client, URL url, String json) { Response response = null;// ww w. ja v a 2 s . c o m try { log("Requesting: " + client.getProtocols().get(0) + " => " + url.toString()); Builder builder = new Request.Builder().url(url.toString()); if (!"".equals(json)) { builder.post(RequestBody.create(MediaType.parse("application/json"), json)); } Request request = builder.build(); response = client.newCall(request).execute(); log("Completed: " + response.code()); } catch (ConnectException e) { log("\n" + "Failed: " + e.getMessage()); } catch (IOException e) { log("Failed: " + e.getMessage()); } return response; }
From source file:com.raskasa.metrics.okhttp.InstrumentedOkHttpClientsTest.java
License:Apache License
private void assertThatClientsAreEqual(OkHttpClient clientA, OkHttpClient clientB) { assertThat(clientA.getDispatcher()).isEqualTo(clientB.getDispatcher()); assertThat(clientA.getProxy()).isEqualTo(clientB.getProxy()); assertThat(clientA.getProtocols()).isEqualTo(clientB.getProtocols()); assertThat(clientA.getConnectionSpecs()).isEqualTo(clientB.getConnectionSpecs()); assertThat(clientA.getProxySelector()).isEqualTo(clientB.getProxySelector()); assertThat(clientA.getCookieHandler()).isEqualTo(clientB.getCookieHandler()); assertThat(clientA.getCache()).isEqualTo(clientB.getCache()); assertThat(clientA.getSocketFactory()).isEqualTo(clientB.getSocketFactory()); assertThat(clientA.getSslSocketFactory()).isEqualTo(clientB.getSslSocketFactory()); assertThat(clientA.getHostnameVerifier()).isEqualTo(clientB.getHostnameVerifier()); assertThat(clientA.getCertificatePinner()).isEqualTo(clientB.getCertificatePinner()); assertThat(clientA.getAuthenticator()).isEqualTo(clientB.getAuthenticator()); assertThat(clientA.getConnectionPool()).isEqualTo(clientB.getConnectionPool()); assertThat(clientA.getFollowSslRedirects()).isEqualTo(clientB.getFollowSslRedirects()); assertThat(clientA.getFollowRedirects()).isEqualTo(clientB.getFollowRedirects()); assertThat(clientA.getRetryOnConnectionFailure()).isEqualTo(clientB.getRetryOnConnectionFailure()); assertThat(clientA.getConnectTimeout()).isEqualTo(clientB.getConnectTimeout()); assertThat(clientA.getReadTimeout()).isEqualTo(clientB.getReadTimeout()); assertThat(clientA.getWriteTimeout()).isEqualTo(clientB.getWriteTimeout()); }