users@jersey.java.net

ServletContainer and relative path resolution

From: Ryan Heaton <ryan_at_webcohesion.com>
Date: Tue, 5 Aug 2008 11:28:32 -0600

Hello.

I was surprised to find that the paths to the resource classes are
resolved relative to the servlet path. Is there a way to override
this behavior?

For example, if my servlet mapping is defined like this (standard
petclinic example)

<web-app>
  ...
  <servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/clinic/*</url-pattern>
  </servlet-mapping>
  ...
</web-app>

And my resource class:

@Path("/clinic/")
public class Clinic {
  ...

  @Path("owner/{id}")
  public Owner getOwner(@PathParam( "id" ) String id) {
    ...
  }
}

Then the "owner" method will be mounted at "/clinic/clinic/owner/id".
I guess I expected paths to be resolved relative to the servlet
context path, rather than the context path + servlet path. I'd like
to define my web.xml file to be narrow so as to allow the default
servlet to handle things like jsp pages and static files.

Thanks!

-Ryan