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

Given that I have an interface that 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 to create a proxy server for the actual implementation of the service, if I need to use Jersey as the JAX-RS platform of the / REST provider in my web application.

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

Basically I am looking for a Jersey equivalent for 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 just spent the last hour searching on Google and keep returning to the standard Jersey client API, which seems to require a lot of boiler stove to achieve the same. Can someone point me in the right direction?

+4
source share
2 answers

After some further googling, I found that the answer is that 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

+3
source

This link seems more practical: http://blog.alutam.com/2012/05/04/proxy-client-on-top-of-jax-rs-2-0-client-api/

 // configure Jersey client ClientConfig cc = new ClientConfig().register(JacksonFeature.class) .register(AnotherFeature.class) .register(SomeFilter.class); Client resource = ClientBuilder.newClient(cc); // create client proxy ServiceInterface proxy = WebResourceFactory.newResource(ServiceInterface.class, resource.target(ServiceURI); // invoke service MyType result = proxy.someMethod(); 

For the maven project, you will need the following dependencies:

  <dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-proxy-client</artifactId> <version>${jersey.version}</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>${jersey.version}</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>${jersey.version}</version> </dependency> 
+5
source

Source: https://habr.com/ru/post/1485783/


All Articles