@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); }
/** * Gets the SOCKS proxy server port. */ private int socksGetServerPort() { // get socks server port from proxy. It is unnecessary to check // "socksProxyPort" property, since proxy setting should only be // determined by ProxySelector. InetSocketAddress addr = (InetSocketAddress) proxy.address(); return addr.getPort(); }
private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException { return proxy.type() != Proxy.Type.DIRECT ? ((InetSocketAddress) proxy.address()).getAddress() : InetAddress.getByName(url.host()); } }
@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"); }
/** * Gets the InetAddress of the SOCKS proxy server. */ private InetAddress socksGetServerAddress() throws UnknownHostException { String proxyName; // get socks server address from proxy. It is unnecessary to check // "socksProxyHost" property, since all proxy setting should be // determined by ProxySelector. InetSocketAddress addr = (InetSocketAddress) proxy.address(); proxyName = addr.getHostName(); if (proxyName == null) { proxyName = addr.getAddress().getHostAddress(); } return InetAddress.getByName(proxyName); }
private InetAddress getConnectToInetAddress(Proxy proxy, HttpUrl url) throws IOException { return (proxy != null && proxy.type() != Proxy.Type.DIRECT) ? ((InetSocketAddress) proxy.address()).getAddress() : InetAddress.getByName(url.host()); } }
@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"); }
private void connectHttpProxy(SocketAddress endpoint, int timeout) throws IOException { super.connect(httpProxy.address(), timeout); if (!(endpoint instanceof InetSocketAddress)) { throw new SocketException("Expected an InetSocketAddress to connect to, got: " + endpoint); } InetSocketAddress isa = (InetSocketAddress) endpoint; String httpConnect = "CONNECT " + isa.getHostName() + ":" + isa.getPort() + " HTTP/1.0\n\n"; getOutputStream().write(httpConnect.getBytes(IOUtils.UTF8)); checkAndFlushProxyResponse(); }
@VisibleForTesting static String getProxySynthesis(URI uri, ProxySelector proxySelector) { List<Proxy> proxies = proxySelector.select(uri); if (proxies.size() == 1 && proxies.get(0).type().equals(Proxy.Type.DIRECT)) { return "no proxy"; } List<String> descriptions = Lists.newArrayList(); for (Proxy proxy : proxies) { if (proxy.type() != Proxy.Type.DIRECT) { descriptions.add(proxy.type() + " proxy: " + proxy.address()); } } return Joiner.on(", ").join(descriptions); }
@Signature public String address() { return getWrappedObject().address().toString(); }
socketPort = address.url().port(); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException(
switch (proxy.type()) { case HTTP: if (!(proxy.address() instanceof InetSocketAddress)) { logger.warn("Don't know how to connect to address " + proxy.address()); return null; } else { InetSocketAddress address = (InetSocketAddress) proxy.address(); return proxyServer(address.getHostName(), address.getPort()).build();
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
socketPort = address.url().port(); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException(
private void configureProxy(ClientConfig clientConfig, URI originalUri, String protocol) { List<Proxy> proxies = ProxySelector.getDefault().select(originalUri); for (Proxy proxy : proxies) { InetSocketAddress address = (InetSocketAddress) proxy.address(); if (address != null) { String hostname = address.getHostName(); int port = address.getPort(); clientConfig.property(ClientProperties.PROXY_URI, "http://" + hostname + ":" + port); String httpProxyUser = System.getProperty(protocol + ".proxyUser"); if (httpProxyUser != null) { clientConfig.property(ClientProperties.PROXY_USERNAME, httpProxyUser); String httpProxyPassword = System.getProperty(protocol + ".proxyPassword"); if (httpProxyPassword != null) { clientConfig.property(ClientProperties.PROXY_PASSWORD, httpProxyPassword); } } } } }
/** * Clients should invoke this method when they encounter a connectivity failure on a connection * returned by this route selector. */ public void connectFailed(Route failedRoute, IOException failure) { if (failedRoute.proxy().type() != Proxy.Type.DIRECT && address.proxySelector() != null) { // Tell the proxy selector when we fail to connect on a fresh connection. address.proxySelector().connectFailed( address.url().uri(), failedRoute.proxy().address(), failure); } routeDatabase.failed(failedRoute); }
/** * Clients should invoke this method when they encounter a connectivity failure on a connection * returned by this route selector. */ public void connectFailed(Route failedRoute, IOException failure) { if (failedRoute.proxy().type() != Proxy.Type.DIRECT && address.proxySelector() != null) { // Tell the proxy selector when we fail to connect on a fresh connection. address.proxySelector().connectFailed( address.url().uri(), failedRoute.proxy().address(), failure); } routeDatabase.failed(failedRoute); }
@Test public void normal() { Proxy.Type type = Proxy.Type.HTTP; factoryBean.setType(type); String hostname = "example.com"; factoryBean.setHostname(hostname); int port = 8080; factoryBean.setPort(port); factoryBean.afterPropertiesSet(); Proxy result = factoryBean.getObject(); assertEquals(type, result.type()); InetSocketAddress address = (InetSocketAddress) result.address(); assertEquals(hostname, address.getHostName()); assertEquals(port, address.getPort()); }
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); auth = java.net.Authenticator.requestPasswordAuthentication( proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
/** * Clients should invoke this method when they encounter a connectivity failure on a connection * returned by this route selector. */ public void connectFailed(Route failedRoute, IOException failure) { if (failedRoute.proxy().type() != Proxy.Type.DIRECT && address.proxySelector() != null) { // Tell the proxy selector when we fail to connect on a fresh connection. address.proxySelector().connectFailed( address.url().uri(), failedRoute.proxy().address(), failure); } routeDatabase.failed(failedRoute); }