2
votes

I am developing a simple web application that both offers and uses REST services on TomEE 1.7.4 plus, i.e. the version containing Jax-RS, among other things.

The services offered by my software are handled without problem. However, this TomEE version doesn't appear to bring a Jax-RS client, so some client needs to be added.

As most people recommend Jersey as a Jax-RS client, I first tried Jersey, but ran into quite a few nasty errors. The bottom line appeared to be that Jersey 2 uses Java EE 7, whereas TomEE is still Java EE 6. While there are older Jersey 1.x versions that might be Java EE 6, the Jax-RS client appears to me only to be available as part of Jersey 2. Therefore:

Question 1: Is there any Jersey client version that runs on Tomee 1.7.4, and if so, which is the Maven/Gradle pointer to get it?

In a next step, I observed that TomEE already brings Apache CXF 2.6.16 with it, but not the CXF client. So I tried several CXF client versions. Adding the following to my gradle.config worked:

providedCompile 'org.apache.cxf:cxf-rt-frontend-jaxrs:2.6.16'
providedCompile 'org.apache.cxf:cxf-rt-ws-policy:2.6.16'

(Entering just the first line ended up in a missing policy class, so I had to add the second line. Don't ask me why the Gradle dependency logic didn't recognize and resolve this dependency by itself.) This works, but 2.6.16 is ages old, and the API of CXF client 2.x is far from satisfactory. In particular, it appears not to be possible to get both the status and, if successful, the content of a GET request in one call. After setting up a WebClient, I can either call getStatus, which will yield the HTTP response status as an int, or get(String.class) that will yield the payload as a String (or something else), but not both. This API anomaly has been cured in CXF 3.x, but again this version isn't compabible with TomEE.

An alternative would be to get the result of the call as a javax.ws.rs.core.Response and scan the buffered reader myself. But in 2016, that shouldn't be necessary any more. For the same reason, I don't consider naked HttpResponse.

Question 2: Is there a way in CXF 2.x to acquire both HTTP response code, and, if okay, the actual GET result, in one call, without resorting to processing the raw incoming data stream?

I searched around for a proper solution for a few days, and I'm mainly puzzled because no one else appears to have this problem. Probably I'm missing something quite elementary. Therefore:

Question 3: Is there any package better suited to implement a REST client under TomEE? (I know that questions of this type aren't welcome here. But please note that I'm not asking for an opinion, but for a concrete proven solution, in the best case just one Maven/Gradle pointer.)

1

1 Answers

0
votes

Running jersey on tomee is possible but needs some advanced classloading configuration.

The easiest and efficient way to get a JAXRS client is to use CXF client which is built it. You are likely interested to use WebClient class (or JAXRSClientFactory directly). More on http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-CXFWebClientAPI