Jersey, Guice using non-root request paths

流过昼夜 提交于 2020-01-06 14:19:13

问题


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)


回答1:


Use serve instead of filter.

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

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



来源:https://stackoverflow.com/questions/9097238/jersey-guice-using-non-root-request-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!