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

发布于 2024-12-11 16:22:07 字数 316 浏览 0 评论 0原文

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

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

有人知道泽西岛有类似的实现吗?

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

有人有想法吗?

the Apache CXF project offers a proxy based client implementation for REST services. This looks like:

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

Does anyone know a similar implementation for Jersey?

I spotted an approach using @HyperMediaController annotations, but I want to stick to JSR-311 default annotations like @Path and @Get ...

Has anyone an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情魔剑神 2024-12-18 16:22:07

存在代理实现,但不幸的是 Jersey Client API 文档 中甚至没有提及它(自版本 2.22.1 起,Jersey 用户指南中均未包含此内容。

我发现的是 WebResourceFactory,更好的是 包 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>

A proxy implementation exists, but unfortunately it's not even mentioned in Jersey Client API documentation (neither in Jersey User Guide) as of version 2.22.1.

What I found was JavaDoc for WebResourceFactory, even better is the package JavaDoc. Here's a snippet from the JavaDoc on the usage of the WebResourceFactory:

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

In Maven you then need:

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

in addition to

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>2.22.1</version>
    </dependency>
愁以何悠 2024-12-18 16:22:07

我发现 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 客户端 api 的建议,您应该在停止使用资源后将其关闭。

resource.close()

更多详细信息请参见 github projet 页面。

I found WebResourceFactory miss generic types supports and it's source code was really hard to understand. So we created https://github.com/adaptris/jaxrs-client-proxy and we are currently devloping it.

To use it you need to build a resource:

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

Then you can call client - which is proxy of your jax-rs annotation described interface (Resource.class). You should close a resource after stoping using it as it is recommended by jax-rs client api.

resource.close()

More details on github projet page.

舂唻埖巳落 2024-12-18 16:22:07

我创建了一个自己的实现。请参阅 utils-apl-衍生 Wiki 页面

I created an own implementation. See utils-apl-derived wiki page therefore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文