users@jersey.java.net

Re: [Jersey] Trailing slash on root resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 21 May 2009 15:09:58 +0200

On May 21, 2009, at 1:42 PM, Charles Brooking wrote:

>> On May 21, 2009, at 3:11 AM, Charles Brooking wrote:
>>> Is there a way to respond to the "root" address without a trailing
>>> slash?
>>
>> No, it is one of those boundary cases with Servlet.
>>
>> What servlet container are you using?
>>
>> GF will redirect from http://localhost/app to http://localhost/app/
>
> I'm using Tomcat, which does redirect from /contextPath to /
> contextPath/.
>
> However, where the Jersey servlet is concerned /contextPath/
> servletPath
> simply returns a 404.
>

OK, got it now, and can reproduce it. Hmm.... strictly speaking the
path if the servlet pattern is /foo/* and the full path is /context/
foo then the servlet should not match, plus there is inconsistent
behavior with the "/*" and /foo/*" patterns, sigh...

I just looked at the ServletContainer code and see:

     @Override
     public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
         /**
          * There is an annoying edge case where the service method is
          * invoked for the case when the URI is equal to the
deployment URL
          * minus the '/', for example http://locahost:8080/HelloWorldWebApp
          */
         if (request.getPathInfo() != null &&
                 request.getPathInfo().equals("/") && !
request.getRequestURI().endsWith("/")) {
             response.setStatus(404);
             return;
         }

Could you log an issue to as a reminder to change this to redirection?

As a work around you can override the ServletContainer.service method
if you wish.

Thanks,
Paul.