I would like to configure a proxy server to my Jersey client.
I don\'t want to configure the proxy to the whole application (using JVM arguments such as http.proxyHost),
With the help of Luca, I got it done:
Implement HttpURLConnectionFactory
, and override the method getHttpURLConnection
, my implementation is (thanks to Luca):
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128));
return new HttpURLConnection(url, proxy);
Before instantiating the Jersey Client, create a new URLConnectionClientHandler
, and provide your HttpURLConnectionFactory
in its constructor. Then create a new Client
, and provide your ClientHandler
in the Client
constructor. My code:
URLConnectionClientHandler urlConnectionClientHandler = new URLConnectionClientHandler(new MyHttpURLConnectionFactory());
_client = new Client(urlConnectionClientHandler);
Hope that's help.