Jam*_*mes 8 java rest jax-rs jersey resteasy
鉴于我有一个代表我的RESET服务的接口
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);
}
Run Code Online (Sandbox Code Playgroud)
如果我需要在我的webapp中使用Jersey作为JAX-RS提供者/ REST框架,如何为实际服务实现创建代理.
这很容易使用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>
Run Code Online (Sandbox Code Playgroud)
我刚刚花了最后一小时谷歌搜索这个并继续回到泽西岛的标准客户端API,这似乎需要大量的锅炉板来实现相同的目标.谁能指出我正确的方向?
这个链接似乎更实用: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();
Run Code Online (Sandbox Code Playgroud)
对于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>
Run Code Online (Sandbox Code Playgroud)
经过进一步的谷歌搜索后,我发现答案是,如果您使用的是 jersey 2.0,则可以使用 jersey 代理客户端模块,可以在这里找到:-
https://jersey.java.net/project-info/2.0/jersey/project/jersey-proxy-client/dependency.html
| 归档时间: |
|
| 查看次数: |
7376 次 |
| 最近记录: |