mirror of https://github.com/apache/jclouds.git
Issue 122: updated http proxy
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2650 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
7559ba165e
commit
e330360f64
|
@ -24,9 +24,7 @@ package org.jclouds.http;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public interface HttpConstants {
|
public interface HttpConstants {
|
||||||
public static final String PROPERTY_HTTP_PROXY_ADDRESS = "jclouds.http.proxy.address";
|
|
||||||
public static final String PROPERTY_HTTP_PROXY_SYSTEM = "jclouds.http.proxy.system";
|
public static final String PROPERTY_HTTP_PROXY_SYSTEM = "jclouds.http.proxy.system";
|
||||||
public static final String PROPERTY_HTTP_PROXY_PORT = "jclouds.http.proxy.port";
|
|
||||||
public static final String PROPERTY_HTTP_MAX_RETRIES = "jclouds.http.max-retries";
|
public static final String PROPERTY_HTTP_MAX_RETRIES = "jclouds.http.max-retries";
|
||||||
public static final String PROPERTY_HTTP_MAX_REDIRECTS = "jclouds.http.max-redirects";
|
public static final String PROPERTY_HTTP_MAX_REDIRECTS = "jclouds.http.max-redirects";
|
||||||
public static final String HTTP_HEADERS_LOGGER = "jclouds.http.headers";
|
public static final String HTTP_HEADERS_LOGGER = "jclouds.http.headers";
|
||||||
|
|
|
@ -20,8 +20,6 @@ package org.jclouds.http;
|
||||||
|
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_REDIRECTS;
|
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_REDIRECTS;
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES;
|
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_MAX_RETRIES;
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_PROXY_ADDRESS;
|
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_PROXY_PORT;
|
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_PROXY_SYSTEM;
|
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_PROXY_SYSTEM;
|
||||||
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_RELAX_HOSTNAME;
|
import static org.jclouds.http.HttpConstants.PROPERTY_HTTP_RELAX_HOSTNAME;
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_IO_WORKER_THREADS;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_IO_WORKER_THREADS;
|
||||||
|
@ -30,7 +28,6 @@ import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_CONNECTION_R
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_MAX_SESSION_FAILURES;
|
||||||
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS;
|
import static org.jclouds.http.pool.PoolConstants.PROPERTY_POOL_REQUEST_INVOKER_THREADS;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
@ -50,21 +47,11 @@ public class HttpPropertiesBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpPropertiesBuilder withProxyAddress(InetAddress proxyAddress) {
|
|
||||||
properties.setProperty(PROPERTY_HTTP_PROXY_ADDRESS, proxyAddress.getHostAddress());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpPropertiesBuilder useSystemProxies(boolean useSystemProxies) {
|
public HttpPropertiesBuilder useSystemProxies(boolean useSystemProxies) {
|
||||||
properties.setProperty(PROPERTY_HTTP_PROXY_SYSTEM, useSystemProxies+"");
|
properties.setProperty(PROPERTY_HTTP_PROXY_SYSTEM, useSystemProxies+"");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpPropertiesBuilder withProxyPort(int proxyPort) {
|
|
||||||
properties.setProperty(PROPERTY_HTTP_PROXY_PORT, proxyPort+"");
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpPropertiesBuilder withHttpMaxRetries(int httpMaxRetries) {
|
public HttpPropertiesBuilder withHttpMaxRetries(int httpMaxRetries) {
|
||||||
properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, Integer.toString(httpMaxRetries));
|
properties.setProperty(PROPERTY_HTTP_MAX_RETRIES, Integer.toString(httpMaxRetries));
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -22,16 +22,12 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.ProxySelector;
|
import java.net.ProxySelector;
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
@ -68,20 +64,10 @@ public class JavaUrlHttpCommandExecutorService extends
|
||||||
private final Map<String, String> sslMap;
|
private final Map<String, String> sslMap;
|
||||||
|
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
@Named(HttpConstants.PROPERTY_HTTP_PROXY_ADDRESS)
|
@Named(HttpConstants.PROPERTY_HTTP_PROXY_SYSTEM)
|
||||||
@Nullable
|
|
||||||
private String proxyAddress = System.getProperty("http.proxyHost");
|
|
||||||
|
|
||||||
@Inject(optional = true)
|
|
||||||
@Named(HttpConstants.PROPERTY_HTTP_PROXY_ADDRESS)
|
|
||||||
private boolean systemProxies = System.getProperty("java.net.useSystemProxies") != null ?
|
private boolean systemProxies = System.getProperty("java.net.useSystemProxies") != null ?
|
||||||
Boolean.parseBoolean(System.getProperty("java.net.useSystemProxies")) : false;
|
Boolean.parseBoolean(System.getProperty("java.net.useSystemProxies")) : false;
|
||||||
|
|
||||||
@Inject(optional = true)
|
|
||||||
@Named(HttpConstants.PROPERTY_HTTP_PROXY_PORT)
|
|
||||||
private int proxyPort = System.getProperty("http.proxyPort") != null ?
|
|
||||||
Integer.parseInt(System.getProperty("http.proxyPort")) : 80;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public JavaUrlHttpCommandExecutorService(ExecutorService executorService,
|
public JavaUrlHttpCommandExecutorService(ExecutorService executorService,
|
||||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, HttpWire wire) {
|
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler, HttpWire wire) {
|
||||||
|
@ -133,10 +119,6 @@ public class JavaUrlHttpCommandExecutorService extends
|
||||||
Iterable<Proxy> proxies = ProxySelector.getDefault().select(request.getEndpoint());
|
Iterable<Proxy> proxies = ProxySelector.getDefault().select(request.getEndpoint());
|
||||||
Proxy proxy = Iterables.getLast(proxies);
|
Proxy proxy = Iterables.getLast(proxies);
|
||||||
connection = (HttpURLConnection) url.openConnection(proxy);
|
connection = (HttpURLConnection) url.openConnection(proxy);
|
||||||
} else if (proxyAddress != null) {
|
|
||||||
SocketAddress proxySocketAddress = new InetSocketAddress(InetAddress.getByName(proxyAddress), proxyPort);
|
|
||||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxySocketAddress);
|
|
||||||
connection = (HttpURLConnection) url.openConnection(proxy);
|
|
||||||
} else {
|
} else {
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
}
|
}
|
||||||
|
|
|
@ -430,15 +430,20 @@ pageTracker._trackPageview();
|
||||||
<systemProperties>
|
<systemProperties>
|
||||||
<!--
|
<!--
|
||||||
If you're behind a proxy, set this here
|
If you're behind a proxy, set this here
|
||||||
|
http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
<name>http.proxyHost</name>
|
<name>https.proxyHost</name>
|
||||||
<value>host</value>
|
<value>proxy</value>
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<property>
|
||||||
<name>http.proxyPort</name>
|
<name>https.proxyPort</name>
|
||||||
<value>port</value>
|
<value>port</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>https.noProxyHosts</name>
|
||||||
|
<value>localhost|10.150.4.49</value>
|
||||||
|
</property>
|
||||||
-->
|
-->
|
||||||
<property>
|
<property>
|
||||||
<name>file.encoding</name>
|
<name>file.encoding</name>
|
||||||
|
|
Loading…
Reference in New Issue