diff --git a/core/src/main/java/org/jclouds/Constants.java b/core/src/main/java/org/jclouds/Constants.java index 12494314aa..f4092ccd8d 100644 --- a/core/src/main/java/org/jclouds/Constants.java +++ b/core/src/main/java/org/jclouds/Constants.java @@ -87,6 +87,31 @@ public interface Constants { * Whether or not to use the proxy setup from the underlying operating system. */ public static final String PROPERTY_PROXY_SYSTEM = "jclouds.use_system_proxy"; + /** + * String property. + *
+ *Explicitly sets the host name of a HTTP proxy server. + */ + public static final String PROPERTY_PROXY_HOST = "jclouds.proxy_host"; + /** + * Integer property. + * + * Explicitly sets the port number of a HTTP proxy server. + */ + public static final String PROPERTY_PROXY_PORT = "jclouds.proxy_port"; + /** + * String property. + * + * Explicitly sets the user name credential for proxy authentication. + */ + public static final String PROPERTY_PROXY_USER = "jclouds.proxy_user"; + /** + * String property. + * + * Explicitly sets the password credential for proxy authentication. + */ + public static final String PROPERTY_PROXY_PASSWORD = "jclouds.proxy_password"; + /** * Integer property. * @@ -125,9 +150,9 @@ public interface Constants { * Name of the logger that records the steps of the request signing process of the HTTP_service. */ public static final String LOGGER_SIGNATURE = "jclouds.signature"; - /** - * Name of the custom adapter bindings map for Gson - */ + /** + * Name of the custom adapter bindings map for Gson + */ public static final String PROPERTY_GSON_ADAPTERS = "jclouds.gson.adapters"; } diff --git a/core/src/main/java/org/jclouds/PropertiesBuilder.java b/core/src/main/java/org/jclouds/PropertiesBuilder.java index b05c7cdc0c..96888da645 100755 --- a/core/src/main/java/org/jclouds/PropertiesBuilder.java +++ b/core/src/main/java/org/jclouds/PropertiesBuilder.java @@ -26,7 +26,11 @@ import static org.jclouds.Constants.PROPERTY_MAX_CONNECTION_REUSE; import static org.jclouds.Constants.PROPERTY_MAX_REDIRECTS; import static org.jclouds.Constants.PROPERTY_MAX_RETRIES; import static org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES; +import static org.jclouds.Constants.PROPERTY_PROXY_HOST; +import static org.jclouds.Constants.PROPERTY_PROXY_PASSWORD; +import static org.jclouds.Constants.PROPERTY_PROXY_PORT; import static org.jclouds.Constants.PROPERTY_PROXY_SYSTEM; +import static org.jclouds.Constants.PROPERTY_PROXY_USER; import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT; import static org.jclouds.Constants.PROPERTY_USER_THREADS; @@ -59,6 +63,38 @@ public abstract class PropertiesBuilder { return this; } + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_HOST + */ + public PropertiesBuilder withProxyHost(String proxyHost) { + properties.setProperty(PROPERTY_PROXY_HOST, proxyHost); + return this; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_PORT + */ + public PropertiesBuilder withProxyPort(int proxyPort) { + properties.setProperty(PROPERTY_PROXY_PORT, Integer.toString(proxyPort)); + return this; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_USER + */ + public PropertiesBuilder withProxyUser(String proxyUser) { + properties.setProperty(PROPERTY_PROXY_USER, proxyUser); + return this; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_PASSWORD + */ + public PropertiesBuilder withProxyPassword(String proxyPassword) { + properties.setProperty(PROPERTY_PROXY_PASSWORD, proxyPassword); + return this; + } + /** * @see org.jclouds.Constants.PROPERTY_SO_TIMEOUT */ diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index 826aaed0d9..ed54d71062 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -74,6 +74,18 @@ public class HttpUtils { private final int globalMaxConnectionsPerHost; private final int connectionTimeout; private final int soTimeout; + @Inject(optional = true) + @Named(Constants.PROPERTY_PROXY_HOST) + private String proxyHost; + @Inject(optional = true) + @Named(Constants.PROPERTY_PROXY_PORT) + private Integer proxyPort; + @Inject(optional = true) + @Named(Constants.PROPERTY_PROXY_USER) + private String proxyUser; + @Inject(optional = true) + @Named(Constants.PROPERTY_PROXY_PASSWORD) + private String proxyPassword; @Inject public HttpUtils(@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout, @@ -86,6 +98,34 @@ public class HttpUtils { this.globalMaxConnectionsPerHost = globalMaxConnectionsPerHost; } + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_HOST + */ + public String getProxyHost() { + return proxyHost; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_PORT + */ + public Integer getProxyPort() { + return proxyPort; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_USER + */ + public String getProxyUser() { + return proxyUser; + } + + /** + * @see org.jclouds.Constants.PROPERTY_PROXY_PASSWORD + */ + public String getProxyPassword() { + return proxyPassword; + } + public int getSocketOpenTimeout() { return soTimeout; } diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 44fc93e4b9..51e8a245c6 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -23,9 +23,13 @@ import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.Authenticator; import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.PasswordAuthentication; import java.net.Proxy; import java.net.ProxySelector; +import java.net.SocketAddress; import java.net.URL; import java.util.concurrent.ExecutorService; @@ -105,7 +109,6 @@ public class JavaUrlHttpCommandExecutorService extends response.setMessage(connection.getResponseMessage()); return response; } - public InputStream consumeOnClose(InputStream in) { return new ConsumeOnCloseInputStream(in); @@ -138,7 +141,6 @@ public class JavaUrlHttpCommandExecutorService extends } - private InputStream bufferAndCloseStream(InputStream inputStream) throws IOException { InputStream in = null; try { @@ -161,6 +163,17 @@ public class JavaUrlHttpCommandExecutorService extends Iterable