users@glassfish.java.net

Re: Possible bug in servlet

From: <Jan.Luehe_at_Sun.COM>
Date: Tue, 10 Jun 2008 14:40:09 -0700

Paul,

Paul Sandoz wrote:

> Jan.Luehe_at_Sun.COM wrote:
>
>> Paul Sandoz wrote:
>>
>>> Jan.Luehe_at_Sun.COM wrote:
>>>
>>>> A request for
>>>>
>>>> http://localhost:8080/HelloWorldWebApp
>>>>
>>>> will cause a redirect to
>>>>
>>>> http://localhost:8080/HelloWorldWebApp/
>>>>
>>>> which matches your servlet.
>>>>
>>>
>>> I still think there may be an issue because the information returned
>>> from HttpServletRequest is inconsistent. Namely, i observe:
>>>
>>> request.getPathInfo() = "/"
>>> request.getRequestURI() = "/HelloWorldWebApp"
>>> request.getRequestURL() = "http://localhost:8080/HelloWorldWebApp"
>>>
>>> i.e. the latter two should end in a '/' if redirection correctly is
>>> performed.
>>>
>>> I presume an internal redirect is performed: I just checked using
>>> curl and no 303 response is returned.
>>>
>>> Is the redirection GF specific behavior? Is it possible to switch it
>>> off?
>>
>>
>>
>> I'm trying to find the exact quote from the Servlet spec, but Section
>> 10.10 (Welcome Files) has this:
>>
>> A request URI of /foo will be redirected to a URI of /foo/.
>>
>
> Presumably that would only occur if one or more welcome files were
> present in the web.xml ?
>
>
>> I've verified (using telnet) that a redirect is actually being returned:
>>
>
> I don't observe that behavior. What version of GF are you using? I am
> using GF v2 UR2.
>
> See attached for about the simplest WebApplication possible created
> with NB 6.0. It contains just one servlet that prints out information
> in the servlet request.
>
> curl outputs the following:
>
> > curl -v http://localhost:8080/WebApplication14
> * About to connect() to localhost port 8080
> * Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 8080
> > GET /WebApplication14 HTTP/1.1
> > User-Agent: curl/7.15.5 (i386-pc-solaris2.11) libcurl/7.15.5
> OpenSSL/0.9.8a zlib/1.2.3 libidn/0.6.8
> > Host: localhost:8080
> > Accept: */*
> >
> < HTTP/1.1 200 OK
> < X-Powered-By: Servlet/2.5
> < Server: Sun Java System Application Server 9.1_02
> < Content-Type: text/html; charset=iso-8859-1
> < Content-Length: 0
> < Date: Mon, 09 Jun 2008 07:57:25 GMT
> * Connection #0 to host localhost left intact
> * Closing connection #0
>
> Curl by default does not follow redirects.
>
> The application prints out in the GF log:
>
> Request URI: /WebApplication14
> Request URL: http://localhost:8080/WebApplication14
> Path Info: /
>
> No redirection occurs and the information in the request is inconsistent.
>
> Can you test with the attached application to see if you observe the
> same behaviour as I?


Yes, I do observe the same behaviour as you.

The reason there is no redirect in the case of your webapp is because the
container appends "/" to the empty path info, which is then matched by
your servlet-mapping of the form "/*".

If there had not been any such servlet-mapping in your webapp, you would
have gotten a redirect.

This is identical to the problem Uday reported on the users_at_glassfish
alias, which I am cc'ing. Uday's web.xml also has a servlet-mapping
of the form "/*", and he also was observing request.getPathInfo()
returning "/",
when he was expecting null.

I'm not sure what should happen in this case, and the Servlet spec is not
very clear about this either.

I think the right thing would have been for the container to issue a
redirect to
"http://localhost:8080/HelloWorldWebApp/", which would have been matched
by your servlet-mapping of the form "/*", resulting in these return values:

   request.getPathInfo() = "/"
   request.getRequestURI() = "/HelloWorldWebApp/"
   request.getRequestURL() = "http://localhost:8080/HelloWorldWebApp/"

Paul and Uday, would you agree?

Thanks,


Jan

>
> Thanks,
> Paul.
>
>> GET /123 HTTP/1.0
>>
>> HTTP/1.1 302 Moved Temporarily
>> X-Powered-By: Servlet/2.5
>> Location: http://leah:8080/123/
>> Content-Type: text/html; charset=iso-8859-1
>> Date: Sat, 07 Jun 2008 00:37:17 GMT
>> Connection: close
>>
>>
>> Jan
>>
>>>
>>> Paul.
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>