@Override public Object getParameter(String name) { if (name.equals(ConnRouteParams.DEFAULT_PROXY)) { Proxy proxy = client.proxy(); if (proxy == null) { return null; } InetSocketAddress address = (InetSocketAddress) proxy.address(); return new HttpHost(address.getHostName(), address.getPort()); } throw new IllegalArgumentException(name); }
private Address createAddress(HttpUrl url) { SSLSocketFactory sslSocketFactory = null; HostnameVerifier hostnameVerifier = null; CertificatePinner certificatePinner = null; if (url.isHttps()) { sslSocketFactory = client.sslSocketFactory(); hostnameVerifier = client.hostnameVerifier(); certificatePinner = client.certificatePinner(); } return new Address(url.host(), url.port(), client.dns(), client.socketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner, client.proxyAuthenticator(), client.proxy(), client.protocols(), client.connectionSpecs(), client.proxySelector()); }
Proxy selectedProxy = route != null ? route.proxy() : client.proxy(); if (selectedProxy.type() != Proxy.Type.HTTP) { throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
public HttpURLConnection open(URL url) { return open(url, client.proxy()); }
private Address createAddress(HttpUrl url) { SSLSocketFactory sslSocketFactory = null; HostnameVerifier hostnameVerifier = null; CertificatePinner certificatePinner = null; if (url.isHttps()) { sslSocketFactory = client.sslSocketFactory(); hostnameVerifier = client.hostnameVerifier(); certificatePinner = client.certificatePinner(); } return new Address(url.host(), url.port(), client.dns(), client.socketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner, client.proxyAuthenticator(), client.proxy(), client.protocols(), client.connectionSpecs(), client.proxySelector()); }
Proxy selectedProxy = route != null ? route.proxy() : client.proxy(); if (selectedProxy.type() != Proxy.Type.HTTP) { throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
/** * Returns true if either: * * <ul> * <li>A specific proxy was explicitly configured for this connection. * <li>The response has already been retrieved, and a proxy was {@link * java.net.ProxySelector selected} in order to get it. * </ul> * * <p><strong>Warning:</strong> This method may return false before attempting to connect and true * afterwards. */ @Override public boolean usingProxy() { if (proxy != null) return true; Proxy clientProxy = client.proxy(); return clientProxy != null && clientProxy.type() != Proxy.Type.DIRECT; }
@Override public Permission getPermission() throws IOException { URL url = getURL(); String hostname = url.getHost(); int hostPort = url.getPort() != -1 ? url.getPort() : HttpUrl.defaultPort(url.getProtocol()); if (usingProxy()) { InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address(); hostname = proxyAddress.getHostName(); hostPort = proxyAddress.getPort(); } return new SocketPermission(hostname + ":" + hostPort, "connect, resolve"); }
@Test public void build_default_instance_of_OkHttpClient() { OkHttpClient okHttpClient = underTest.build(); assertThat(okHttpClient.proxy()).isNull(); assertThat(okHttpClient.networkInterceptors()).hasSize(1); assertThat(okHttpClient.sslSocketFactory()).isNotNull(); }
@Test public void provide_client_with_custom_settings() { Map<String, String> props = new HashMap<>(); props.put("sonar.host.url", "https://here/sonarqube"); props.put("sonar.login", "theLogin"); props.put("sonar.password", "thePassword"); props.put("sonar.ws.timeout", "42"); ScannerProperties settings = new ScannerProperties(props); ScannerWsClient client = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), mock(System2.class)); assertThat(client).isNotNull(); HttpConnector httpConnector = (HttpConnector) client.wsConnector(); assertThat(httpConnector.baseUrl()).isEqualTo("https://here/sonarqube/"); assertThat(httpConnector.okHttpClient().proxy()).isNull(); }
@Test public void createCreator_withBuilder_Assigned() throws IOException { final OkHttpClient.Builder builder = new OkHttpClient.Builder(); final Proxy proxy = mock(Proxy.class); builder.proxy(proxy); DownloadOkHttp3Connection.Factory factory = new DownloadOkHttp3Connection.Factory() .setBuilder(builder); assertThat(factory.builder()).isEqualTo(builder); DownloadOkHttp3Connection connection = (DownloadOkHttp3Connection) factory.create(URL); assertThat(connection.client.proxy()).isEqualTo(proxy); }
@Override public Object getParameter(String name) { if (name.equals(ConnRouteParams.DEFAULT_PROXY)) { Proxy proxy = client.proxy(); if (proxy == null) { return null; } InetSocketAddress address = (InetSocketAddress) proxy.address(); return new HttpHost(address.getHostName(), address.getPort()); } throw new IllegalArgumentException(name); }
public HttpURLConnection open(URL url) { return open(url, client.proxy()); }
@Override public Object getParameter(String name) { if (name.equals(ConnRouteParams.DEFAULT_PROXY)) { Proxy proxy = client.proxy(); if (proxy == null) { return null; } InetSocketAddress address = (InetSocketAddress) proxy.address(); return new HttpHost(address.getHostName(), address.getPort()); } throw new IllegalArgumentException(name); }
@Override public Permission getPermission() throws IOException { URL url = getURL(); String hostname = url.getHost(); int hostPort = url.getPort() != -1 ? url.getPort() : HttpUrl.defaultPort(url.getProtocol()); if (usingProxy()) { InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address(); hostname = proxyAddress.getHostName(); hostPort = proxyAddress.getPort(); } return new SocketPermission(hostname + ":" + hostPort, "connect, resolve"); }
@Override public Permission getPermission() throws IOException { URL url = getURL(); String hostname = url.getHost(); int hostPort = url.getPort() != -1 ? url.getPort() : HttpUrl.defaultPort(url.getProtocol()); if (usingProxy()) { InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address(); hostname = proxyAddress.getHostName(); hostPort = proxyAddress.getPort(); } return new SocketPermission(hostname + ":" + hostPort, "connect, resolve"); }
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) { RestClient client = restClientBuilder .withBaseUrl(credentials.environment(), endpoint) .withCredentials(credentials) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(); if (client.httpClient().proxy() != null) { credentials.withProxy(client.httpClient().proxy()); } return client; }
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) { RestClient client = restClientBuilder .withBaseUrl(credentials.environment(), endpoint) .withCredentials(credentials) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(); if (client.httpClient().proxy() != null) { credentials.withProxy(client.httpClient().proxy()); } return client; }
protected RestClient buildRestClient(AzureTokenCredentials credentials, AzureEnvironment.Endpoint endpoint) { RestClient client = restClientBuilder .withBaseUrl(credentials.environment(), endpoint) .withCredentials(credentials) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(); if (client.httpClient().proxy() != null) { credentials.withProxy(client.httpClient().proxy()); } return client; }
@Test public void defaultClient() { builder.build(); OkHttpClient client = builder.getClientBuilder().build(); assertEquals(EventSource.DEFAULT_CONNECT_TIMEOUT_MS, client.connectTimeoutMillis()); assertEquals(EventSource.DEFAULT_READ_TIMEOUT_MS, client.readTimeoutMillis()); assertEquals(EventSource.DEFAULT_WRITE_TIMEOUT_MS, client.writeTimeoutMillis()); assertNull(client.proxy()); }