Configure proxy to Jersey client
java, jersey, proxy
Solution
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.
Problem
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), and Id'e rather not use Apache client. I read here that there is an option to do it by providing HttpUrlConnection via HttpUrlConnectionFactory, but I couldn't find any code example. Does anyone know how can I do it? Thanks!