List of usage examples for com.squareup.okhttp OkHttpClient getHostnameVerifier
public HostnameVerifier getHostnameVerifier()
From source file:com.digi.wva.internal.HttpClientTest.java
License:Mozilla Public License
public void testUnderlyingClient() { OkHttpClient okhttp = dut.getUnderlyingClient(); // Hostname verifier should return true for everything HostnameVerifier v = okhttp.getHostnameVerifier(); assertTrue(v.verify("foo", null)); assertTrue(v.verify("bar", null)); assertTrue(v.verify("https://google.c", null)); }
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()); }
From source file:org.apache.nifi.processors.standard.InvokeHTTP.java
License:Apache License
@OnScheduled public void setUpClient(final ProcessContext context) throws IOException { okHttpClientAtomicReference.set(null); OkHttpClient okHttpClient = new OkHttpClient(); // Add a proxy if set final String proxyHost = context.getProperty(PROP_PROXY_HOST).getValue(); final Integer proxyPort = context.getProperty(PROP_PROXY_PORT).asInteger(); if (proxyHost != null && proxyPort != null) { final Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); okHttpClient.setProxy(proxy);/*from w w w. java 2 s . co m*/ } // Set timeouts okHttpClient.setConnectTimeout( (context.getProperty(PROP_CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()), TimeUnit.MILLISECONDS); okHttpClient.setReadTimeout( context.getProperty(PROP_READ_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue(), TimeUnit.MILLISECONDS); // Set whether to follow redirects okHttpClient.setFollowRedirects(context.getProperty(PROP_FOLLOW_REDIRECTS).asBoolean()); final SSLContextService sslService = context.getProperty(PROP_SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); final SSLContext sslContext = sslService == null ? null : sslService.createSSLContext(ClientAuth.NONE); // check if the ssl context is set and add the factory if so if (sslContext != null) { okHttpClient.setSslSocketFactory(sslContext.getSocketFactory()); } // check the trusted hostname property and override the HostnameVerifier String trustedHostname = trimToEmpty(context.getProperty(PROP_TRUSTED_HOSTNAME).getValue()); if (!trustedHostname.isEmpty()) { okHttpClient.setHostnameVerifier( new OverrideHostnameVerifier(trustedHostname, okHttpClient.getHostnameVerifier())); } setAuthenticator(okHttpClient, context); useChunked = context.getProperty(PROP_USE_CHUNKED_ENCODING).asBoolean(); okHttpClientAtomicReference.set(okHttpClient); }