Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 599
Garret Wilson Avatar asked Mar 14 '15 00:03

Garret Wilson


People also ask

What is the difference between Jersey and RESTEasy?

Both Jersey and RESTEasy provide their own implementation. The difference is that Jersey additionally provides something called Chunked Output. It allows the server to send back to the client a response in parts (chunks).

What is RESTEasy in Jax RS?

Overview. JAX-RS, JSR-311, is a new JCP specification that provides a Java API for RESTful Web Services over the HTTP protocol. Resteasy is an portable implementation of this specification which can run in any Servlet container.

What is RESTEasy client?

RESTeasy is a Java library that provides a simple interface to the REST server. It supports all of the features of the Jakarta REST Services and includes support for both synchronous and asynchronous communication. Firstly, there are really two ways to create a REST Client. Use Jakarta REST Client API.

What is RESTEasy Web services?

RESTEasy is a JBoss / Red Hat project that provides various frameworks to help you build RESTful Web Services and RESTful Java applications. It is an implementation of the Jakarta RESTful Web Services, an Eclipse Foundation specification that provides a Java API for RESTful Web Services over the HTTP protocol.


1 Answers

It seems to be possible to make RESTeasy use Java's proxy properties (e.g. -Dhttp.proxyHost) by using a different engine instead of HttpClient. java.net.HttpURLConnection supports proxy properties out of the box:

ResteasyClient client = new ResteasyClientBuilder().httpEngine(new URLConnectionEngine()).build();
like image 172
Nikolai Prokoschenko Avatar answered Oct 11 '22 11:10

Nikolai Prokoschenko