2013-06-12 20 views
4

鉴于本人表示使用有没有办法使用JAX-RS注释接口作为客户端?

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); 

} 

如何创建一个代理,以实际服务实现,如果我需要使用泽西作为JAX-RS提供商/ REST框架我RESET服务的接口我Web应用程序。

这很容易做到RESTEasy/Spring集成,并且意味着我可以直接使用我的JAX-RS接口,而无需将它包装起来并右对齐锅炉板来执行调用。

基本上我正在寻找一个泽西等同于以下内容: -

<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> 

我刚刚度过的最后一个小时google搜索这一点,并不断收到回泽西标准的客户端API,这似乎需要很多锅炉板实现相同。任何人都可以将我指向正确的方向吗?

回答

5

这种联系似乎更实用: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(); 

Maven的项目,你需要以下相关:

<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> 
+1

请考虑添加链接文章的相关部分,以防止将来的链接腐烂渲染你的答案无用。 – cdeszaq

相关问题