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!
To set different proxy on runtime is not good solution. Accordingly, I used apache connector to do so:
add apache connector dependency defined:
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
</dependency>
add apache connector to client
config.property(ApacheClientProperties.PROXY_URI, proxyUrl);
Connector connector = new ApacheConnector(config);
config.connector(connector);