Jersey、Guice 使用非根请求路径

发布于 2025-01-01 00:36:31 字数 891 浏览 4 评论 0原文

我在标准配置的 Tomcat 6.0.32 上使用 Jersey 1.11 而不是 Guice 3.0:

configureServlets() {
    filter("/ws/*").through(GuiceContainer.class);
}

和一个简单的资源类:

@Path("/resource")
public class Resource { ... }

鉴于此,我认为访问“/ws/resource”会起作用;但实际上并没有找到资源。问题似乎在于请求路径计算不正确。作为解决方法,我将参数 PROPERTY_FILTER_CONTEXT_PATH 设置为 /ws,这使得整个事情正常工作:

Map<String, String> jerseyConfig = new HashMap<String, String>();
jerseyConfig.put(ServletContainer.PROPERTY_FILTER_CONTEXT_PATH, "/ws");
filter("/ws/*").through(GuiceContainer.class, jerseyConfig);

因此我的问题是:

  1. 这真的是一个错误还是一个“功能”?
  2. 有其他解决方案或解决方法吗?

作为信息,我看到了一个可能相关的 Guice 错误,它似乎已合并到另一个错误中,但我想知道它是否已正确修复(链接)

I'm using Jersey 1.11 over Guice 3.0 on Tomcat 6.0.32 in a standard configuration:

configureServlets() {
    filter("/ws/*").through(GuiceContainer.class);
}

And a simple resource class:

@Path("/resource")
public class Resource { ... }

Given that, I would suppose that accessing "/ws/resource" would work; but actually no resources are found. The problem seems to lie in the request path not being computed correctly. As a workaround I have set the parameter PROPERTY_FILTER_CONTEXT_PATH to /ws, which make the whole thing work:

Map<String, String> jerseyConfig = new HashMap<String, String>();
jerseyConfig.put(ServletContainer.PROPERTY_FILTER_CONTEXT_PATH, "/ws");
filter("/ws/*").through(GuiceContainer.class, jerseyConfig);

Thus my questions are:

  1. Is this really a bug or a "feature" ?
  2. Is there another solution or workaround for this?

For info, I've seen one Guice bug that can be related, it seems to have been merged in another one but I'm wondering if it's properly fixed (link)

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

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

发布评论

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

评论(1

街角迷惘 2025-01-08 00:36:31

使用服务而不是过滤器。

configureServlets() {
    serve("/ws/*").with(GuiceContainer.class);
}

然后您就可以点击/ws/resource。

Use serve instead of filter.

configureServlets() {
    serve("/ws/*").with(GuiceContainer.class);
}

You will then be able to hit /ws/resource.

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