How to add a http proxy for Jersey2 Client

feuyeux picture feuyeux · Sep 22, 2013 · Viewed 25.5k times · Source

It's easy to set a proxy for client on Jersey1.x:

config.getProperties().put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, proxyUrl);

But how to add a http proxy for Jersey2.x client? I checked the source code and didn't find the implementation does that in:

org.glassfish.jersey.client.HttpUrlConnector

Thanks!

Answer

NGloom picture NGloom · May 15, 2015

thanks @feuyeux, the solution is work for me, ps, the code below is works in the proxy with http basic auth:

    ClientConfig config = new ClientConfig();
    config.connectorProvider(new ApacheConnectorProvider());
    config.property(ClientProperties.PROXY_URI, proxy);
    config.property(ClientProperties.PROXY_USERNAME,user);
    config.property(ClientProperties.PROXY_PASSWORD,pass);
    Client client = JerseyClientBuilder.newClient(config);

hope to help others