Search code examples
eclipsejax-rsresteasyhttp-proxy

Using web proxy with Java 8 JAX-RS RESTEasy clients


I can't seem to get JAX-RS clients to use a web proxy on Java 8. I'm using RESTEasy 3.0.10.Final, and running from inside Eclipse 4.4.2 on Windows 7 Professional 64-bit.

I set up a FreeProxy server on localhost running at 192.168.1.123:3128. I turn logs on and telnet to 192.168.1.123 3128 and issue a manual GET. The request shows up in the logs.

I then fire up my Java application, setting http.proxyHost=192.168.1.123 and http.proxyPort=3128 in the system properties. (I've even tried it using -D when starting the JVM.) (Note that I wouldn't expect the localhost problem to come into play, as I'm connecting to an actual IP address, not to localhost.)

I create a JAX-RS client using ClientBuilder.newBuilder().build() and perform a GET to a resource. Nothing shows up in the FreeProxy logs.

What do I have to do in order to get JAX-RS clients to use a proxy?


Solution

  • The ResteasyClientBuilder provides a method to define the defaultProxy:

    ResteasyClient client = new ResteasyClientBuilder().defaultProxy("localhost", 8080, "http").build();