Skip to main content

[Jersey] Pointing web app welcome-file to Jersey Application causes StringIndexOutOfBoundsException

3 replies [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Paul Sandoz

Hi,

I can reproduce this behavior on Tomcat 6, GF v3 and JBoss 5. But i do
and wonder if this is a bug. Including GF users list for more help.

When i have my own project set up to reproduce with the following in
the web.xml


Jersey Web Application
/webresources/*


webresources/myresource

The servlet request information from the Jersey servlet is as follows:

getContextPath: /mavenproject13
getServletPath: /webresources
getPathInfo: /myresource
getRequestURL: http://localhost:8080/mavenproject13/
getRequestURI: /mavenproject13/

This is confusing the heck out of Jersey because it expects the
request URI to be logically composed of:

context path + servlet path + path info

(ignoring the case that such paths are in decoded form and the requets
URI is in the original encoded form)

It is like the web container is making an internal forwarding request
but with inconsistent information.

Is that the expected behavior?

Note that this whole area of managing this information from servlet is
very fragile. There are a number of edge cases to deal with. It is
actually damn hard to consistently produce the *encoded* base URI and
request URI from HttpServletRequest.

Paul.

On Apr 15, 2010, at 12:54 PM, Alex Treppass wrote:

> All,
>
> I've got my Web Project setup at /foo/WebProject/ and deployed to a
> Tomcat 5.5 server. My Jersey Application lives at /foo/WebProject/
> bar/ws/. I'm using Jersey 1.1.5.
>
> Wanting to have requests to foo/WebProject/ map to the response
> returned at /foo/WebProject/bar/ws/collections/list, I've added the
> following welcome-file- entry to my web.xml:
>
> ws/bar/collections/list
>

>
> This passes off to my Jersey webapp seamlessly, however when it gets
> to
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:
> 632), the requestURI variable is shorter than baseUri:
>
> baseURI: http://localhost:8080/foo/WebProject/ws/bar/
> requestURI: http://localhost:8080/foo/WebProject/
>
> This causes a StringIndexOutOfBoundsException further down when
> resolving the encoded Path at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEncodedPath(ContainerRequest.java:
> 359):
>
> java.lang.StringIndexOutOfBoundsException: String index out of
> range: -7
> at java.lang.String.substring(Unknown Source)
> at java.lang.String.substring(Unknown Source)
> at
> com
> .sun
> .jersey
> .spi.container.ContainerRequest.getEncodedPath(ContainerRequest.java:
> 359)
> at
> com
> .sun
> .jersey.spi.container.ContainerRequest.getPath(ContainerRequest.java:
> 352)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:984)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
> 384)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:451)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:632)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> ... (Catalina stack omitted for brevity).
>
> Offending code at ContainerRequest.java:359:
> return encodedPath =
> getRequestUri
> ().getRawPath().substring(getBaseUri().getRawPath().length());
>
> Has anyone come across this problem before? In the meantime I think
> I'm going to have to hook up a dummy servlet in my web.xml that
> takes an init-param "ws/bar/collections/list" and does a simple HTTP
> redirect to get around this.
>
> Regards,

[att1.html]

Dominik Dorn

hmm... as far as I understand, welcome-files are things that get
resolved if just
a directory is specified, like index.html, index.php, etc. and they are FILES!

so if you have
http://localhost:8080/yourapp/
it will call
http://localhost:8080/yourapp/index.html

if you create a directory test
http://localhost:8080/yourapp/test/
it will call
http://localhost:8080/yourapp/test/index.html

so, while your mapping of webresources/myresource
could theoretically work on
http://localhost:8080/yourapp/
it would fail on
http://localhost:8080/yourapp/test/

I think the way specified in your mail is really misusing the feature and
if it works, its a bug in my opinion.

What you are trying to achieve looks like a case for a url-rewriting filter like
http://ocpsoft.com/prettyfaces/ or http://tuckey.org/urlrewrite

kr,
dominik

--
[url=http://www.dominikdorn.com]Dominik Dorn[/url]

Tausche Deine [url=http://www.studyguru.eu] Lernunterlagen auf
http://www.studyguru.eu[/url]!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Paul Sandoz

Hi Dominik,

I agree with your assessment. Perhaps GF should fail to deploy in such
circumstances?

Alex, i am not sure what your servlet url pattern is but if it is
something like "/*" you could do something like:

@Path("/")
public Root extends OtherResource {
}

where OtherRootResource is the one root resource you want to point to
for the "root" URL.

If such a URL pattern causes issues because JSPs and static resources
are not accessible use ServletContainer as a filter instead.

Paul.

On Apr 15, 2010, at 8:42 PM, Dominik Dorn wrote:

> hmm... as far as I understand, welcome-files are things that get
> resolved if just
> a directory is specified, like index.html, index.php, etc. and they
> are FILES!
>
> so if you have
> http://localhost:8080/yourapp/
> it will call
> http://localhost:8080/yourapp/index.html
>
> if you create a directory test
> http://localhost:8080/yourapp/test/
> it will call
> http://localhost:8080/yourapp/test/index.html
>
> so, while your mapping of webresources/myresource
> could theoretically work on
> http://localhost:8080/yourapp/
> it would fail on
> http://localhost:8080/yourapp/test/
>
> I think the way specified in your mail is really misusing the
> feature and
> if it works, its a bug in my opinion.
>
> What you are trying to achieve looks like a case for a url-rewriting
> filter like
> http://ocpsoft.com/prettyfaces/ or http://tuckey.org/urlrewrite
>
> kr,
> dominik
>
>
> --
> [url=http://www.dominikdorn.com]Dominik Dorn[/url]
>
> Tausche Deine [url=http://www.studyguru.eu] Lernunterlagen auf
> http://www.studyguru.eu[/url]!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net