Domanda

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)

È stato utile?

Soluzione

Use serve instead of filter.

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top