/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
@Test public void httpProxyIsConfigurableOnClientRequests() { Optional<ProxySelector> httpProxySelector = Optional.of( ServiceCreator.createProxySelector(ProxyConfiguration.of(getHostAndPort(proxyPort)))); TestResource clientWithHttpProxy = AtlasDbHttpClients.createProxyWithFailover( new MetricRegistry(), NO_SSL, httpProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class); clientWithHttpProxy.getTestNumber(); String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE); proxyServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)) .withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent))); availableServer.verify(0, getRequestedFor(urlMatching(TEST_ENDPOINT))); }
private static Optional<HostAndPort> meshProxy(Optional<ProxyConfiguration> proxy) { if (proxy.isPresent() && proxy.get().type() == ProxyConfiguration.Type.MESH) { return Optional.of(HostAndPort.fromString(proxy.get().hostAndPort().get())); } else { return Optional.empty(); } }
/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); case MESH: return ProxySelector.getDefault(); // MESH proxy is not a Java proxy default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }