Comment #1 on issue 449 by kodemaniak: Servlet match on a servlet path, not the actual request path
http://code.google.com/p/google-guice/issues/detail?id=449

I have the same issue using Jersey (1.4) with Guice (from trunk) and the jersey-guice integration within OSGi. I do not use a web.xml descriptor, but register GuiceFilter programatically using the Apache Felix ExtHttpService. I basically have the following code in my activator:

Guice.createInjector(new RestModule());
                
try {
    httpService.registerFilter(new GuiceFilter(), "/.*", null, 0, null);
} catch (ServletException e) {
    e.printStackTrace();
}

The rest module binds a JerseyResource as follows:


protected void configureServlets() {
    bind(GuiceJerseyResource.class);
    serve("/rest/*").with(GuiceContainer.class);
}

The resource is annotated with @Path("/guicejersey"). So I would expect to be to access the rsource under http://localhost:8181/rest/guicejersey. However, that's not the case by default. If I use a match-all pattern (serve("*")) it matches when I access http://localhost:8181/guicejersey.

Some debugging showed me that the guice-servlet extension matches patterns agains servlet path, which seems to be empty all the time. I fixed the issue by changing ServletDefintion.java at two places:

In getPathInfo() I changed

pathInfo = getServletPath().substring(getContextPath().length()).replaceAll("[/]{2,}","/").substring(servletPathLength);

to

pathInfo = getRequestURI().substring(getContextPath().length()).replaceAll("[/]{2,}", "/").substring(servletPathLength);

and in computePath() I changed


String servletPath = super.getServletPath();

to


String servletPath = super.getRequestURI();

I am actually not sure whether this breaks something else. But from my understanding of getServletPath and getRequestUri it seems to me that the latter is correct method to use. But I have hardly any experience with servlets so far, so I don't know exactly how the behaviour is in other contexts (e.g. the role of the contextPath).

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to google-guice-...@googlegroups.com.
To unsubscribe from this group, send email to 
google-guice-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to