Search code examples
javarestjerseyjax-rsresteasy

Is there a way to use JAX-RS annotated interface with Jersey as the client?


Given that I have an interface which represents my RESET service using

public interface BookResource {

     @GET
     @Path("/book/isbn/{isbn}/")
     @Produces(value = { MediaType.APPLICATION_XML })
     public ClientResponse<Book> getBookByIsbn(@PathParam("isbn") String isbn, @QueryParam("releaseStatus") String releaseStatus);

}

How can I create a proxy to the actual service implementation if I am required to use Jersey as the JAX-RS provider/REST framework in my webapp.

This is easy to do with RESTEasy/Spring integration and means I can use my JAX-RS interface directly without having to wrap it and right boiler plate to do the invocation.

Basically I'm looking for a Jersey equivalent to the following: -

<bean id="bookResource" class="org.jboss.resteasy.client.spring.RestClientProxyFactoryBean">
    <property name="serviceInterface" value="my.company.book.service.BookResource" />
    <property name="baseUri" value="http://localhost:8181/books-service/" />
</bean>

I've just spent the last hour googling this and keep getting back to the standard client API in Jersey which seems to require a lot of boiler plate to achieve the same. Can anyone point me in the right direction?


Solution

  • After some further googling I found that the answer is, provided you are using jersey 2.0, to use the jersey proxy-client module which can be found here: -

    https://jersey.java.net/project-info/2.0/jersey/project/jersey-proxy-client/dependencies.html