有没有人知道像Apache CXF为REST提供的Jersey客户端代理实现

时间:2011-10-24 19:20:34

标签: java rest jersey cxf

Apache CXF项目为REST服务提供基于代理的客户端实现。这看起来像:

Resource resource = JAXRSClientFactory.create( baseAddress, Resource.class )

有没有人知道泽西岛的类似实施?

我发现了使用@HyperMediaController注释的方法,但我想坚持使用JSR-311默认注释,例如@Path@Get ......

有人有想法吗?

3 个答案:

答案 0 :(得分:4)

存在代理实现,但不幸的是,在版本2.22.1中,Jersey Client API documentationJersey User Guide中都没有)提及它。

我发现的是WebResourceFactory的JavaDoc,更好的是package JavaDoc。这是JavaDoc关于WebResourceFactory使用的片段:

Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/");
MyResourceIfc resource = WebResourceFactory.newResource(MyResourceIfc.class, target);

在Maven,您需要:

    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-proxy-client</artifactId>
        <version>2.22.1</version>
    </dependency>

除了

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.22.1</version>
    </dependency>

答案 1 :(得分:1)

我发现WebResourceFactory错过了泛型类型支持,它的源代码真的很难理解。所以我们创建了https://github.com/adaptris/jaxrs-client-proxy,我们现在正在开发它。

要使用它,您需要构建资源:

ResourceBuilder builder = new ResourceBuilder();
resource = builder.
    url("https://host/api").
    build(Resource.class);
client = resource.get();

然后你可以调用client - 这是你的jax-rs注释描述接口(Resource.class)的代理。您应该在停止使用资源后关闭资源,因为jax-rs client api建议使用它。

resource.close()

有关github projet页面的更多详情。

答案 2 :(得分:0)

我创建了一个自己的实现。因此,请参阅utils-apl-derived wiki page