Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public class Configuration {
*/
public static final String PROPERTY_LOG_HTTP_REQUESTS = "com.microsoft.windowsazure.Configuration.logHttpRequests";

/**
* Property name to control whether the Rest client uses a Proxy connection to the remote resources. Defines the host
* of the proxy to use
*/
public static final String PROPERTY_HTTP_PROXY_HOST = "http.proxyHost";

/**
* Property name to control whether the Rest client uses a Proxy connection to the remote resources. Defines the port
* of the proxy to use
*/
public static final String PROPERTY_HTTP_PROXY_PORT = "http.proxyPort";

/**
* The configuration instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;

import static com.microsoft.windowsazure.core.utils.ExportUtils.getPropertyIfExists;
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;

public class Exports implements Builder.Exports {

Expand Down Expand Up @@ -69,7 +70,18 @@ public <S> Client create(String profile, Class<S> service,
ClientConfig.class, properties);
ClientConfigSettings settings = builder.build(profile, service,
ClientConfigSettings.class, properties);
Client client = Client.create(clientConfig);
Client client;
String proxyHost = (String) getPropertyIfExists(profile,
properties, Configuration.PROPERTY_HTTP_PROXY_HOST);
Integer proxyPort = (Integer) getPropertyIfExists(profile,
properties, Configuration.PROPERTY_HTTP_PROXY_PORT);
if ((proxyHost != null) && (proxyPort != null)) {
URLConnectionClientHandler clientHandler = new URLConnectionClientHandler(
new ProxyConnectionFactory(proxyHost, proxyPort));
client = new Client(clientHandler, clientConfig);
} else {
client = Client.create(clientConfig);
}
settings.applyConfig(client);
return client;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.windowsazure.core.pipeline.jersey;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;

import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;

/**
* Extends <code>HttpURLConnectionFactory</code> so that an HTTP Proxy can be used when connecting to the
* remote resource.
*
* @author Ed Hillmann
*/
public class ProxyConnectionFactory implements HttpURLConnectionFactory {

private final String proxyHost;
private final int proxyPort;

public ProxyConnectionFactory(String proxyHost, int proxyPort) {
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
}

@Override
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
return (HttpURLConnection) url.openConnection(proxy);
}

}