Search in sources :

Example 1 with ConnectionFactory

use of org.glassfish.jersey.client.HttpUrlConnectorProvider.ConnectionFactory in project openstack4j by ContainX.

the class ClientFactory method addProxy.

private static void addProxy(ClientConfig cc, Config config) {
    if (config.getProxy() != null) {
        HttpUrlConnectorProvider cp = new HttpUrlConnectorProvider();
        cc.connectorProvider(cp);
        final Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(config.getProxy().getRawHost(), config.getProxy().getPort()));
        cp.connectionFactory(new ConnectionFactory() {

            @Override
            public HttpURLConnection getConnection(URL url) throws IOException {
                return (HttpURLConnection) url.openConnection(proxy);
            }
        });
    }
}
Also used : Proxy(java.net.Proxy) ConnectionFactory(org.glassfish.jersey.client.HttpUrlConnectorProvider.ConnectionFactory) HttpURLConnection(java.net.HttpURLConnection) HttpUrlConnectorProvider(org.glassfish.jersey.client.HttpUrlConnectorProvider) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 URL (java.net.URL)1 HttpUrlConnectorProvider (org.glassfish.jersey.client.HttpUrlConnectorProvider)1 ConnectionFactory (org.glassfish.jersey.client.HttpUrlConnectorProvider.ConnectionFactory)1