I am using JAX-RS for a RESTful client in Java 8 with RESTEasy 3.0.10.Final as an implementation for 64-bit Windows windows. RESTEasy in turn uses Apache httpclient 4.2.6.
I separately learned how to manually specify a web proxy for httpclient, so if I manually configured ResteasyClientBuilder in my code using the specially configured ApacheHttpClient4Engine my ApacheHttpClient4Engine client connections correctly use proxies.
My problem is that I want to use the java.net.useSystemProxies system property so that my Java program uses any proxy server in the Windows Internet Options settings, so that my Java program will work without problems with other programs and does not require she was specially tuned. This is great for connections using native Java HTTP connections. But RESTEasy / Apache httpclient seems to open a direct socket and perform its HTTP connection at a low level.
When I say Java to use system proxies, Java does route httpclient connections to proxies. But for some reason, httpclient thinks it is talking to the SOCKS proxy --- or something like that, and the request expires:
java.net.SocketException: Can't connect to SOCKS proxy:Connection timed out: connect at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:429) at java.net.Socket.connect(Socket.java:589) at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:127) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:283) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:407) at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:159)
Someone else recommended disabling SOCKS routing in the default proxy selector, and this really prevents the httpclient socket from routing to the system proxy, but then the HTTP connection completely bypasses the proxy server, which defeats the target.
I assume that httpclient is just requesting a socket, and Java sees the system proxy and assumes socket connections for the SOCKS proxy. I would also suggest that even if Java sockets were passed to web proxies normally, httpclient knew nothing about this and therefore did not see the correct HTTP request proxy format. Or will httpclient somehow see that java.net.useSystemProxies enabled and change its request? But how would he even know if the system proxy really works?
So, I completely stalled. If I enable java.net.useSystemProxies and make normal HTTP requests in Java, they use the system proxy. How can I tell RESTEasy / httpclient to use the system web proxy?
Garret wilson
source share