users@jersey.java.net

Pointing web app welcome-file to Jersey Application causes StringIndexOutOfBoundsException

From: Alex Treppass <alextreppass_at_googlemail.com>
Date: Thu, 15 Apr 2010 11:54:57 +0100

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:
* <welcome-file-list>*
* <welcome-file>ws/bar/collections/list</welcome-file>*
* </welcome-file-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,