I am developing a project with servletbridge, and am having some issues
with getContextPath() in
org.eclipse.equinox.http.helper.ContextPathServletAdaptor$HttpServletRequestAdaptor
and org.eclipse.equinox.http.servlet.internal.HttpServletRequestAdaptor.
In
org.eclipse.equinox.http.helper.ContextPathServletAdaptor$HttpServletRequestAdaptor
(module: equinox-incubator/org.eclipse.equinox.http.helper),
getContextPath() returns super. getContextPath() with or without the
ContextPathServletAdaptor?s contextPath, depending on whether or not the
javax.servlet.include.request_uri request attribute is set.
So with a web app of ?MyWebApp? and an bundle of ?MyBundle1? I get
returned a context path of ?/MyWebApp? when I?m inside of a .jsp file
included (RequestDispatch.include) from a Struts Action servlet, and
?/MyWebApp/MyBundle1? otherwise. I don?t understand why these are
different, and as we have code in both cases which invokes getContextPath,
these inconsistent return values don?t work well. To get around this I
have commented out the code in
ContextPathServletAdaptor$HttpServletRequestAdaptor.getContextPath() for
the include case. But I?m wondering if this really the way it is supposed
to work, or am I perhaps doing something completely wrong?
The second issue is with getContexPath() in the internal
HttpServletRequestAdaptor (module: org.eclipse.equinox.http.servlet).
Here super.getServletPath() is optionally appended to
super.getContextPath() depending once again on whether the
javax.servlet.include.request_uri request attribute is set. This works
fine for me on Tomcat, but running the same jsf (faces) code on IBM
Websphere 6.1 gives me a messed up context path. In both cases
javax.servlet.include.request_uri is not set, so the method appends the
servlet path which happens to be an empty string in Tomcat, and non-empty
in WebSphere. Upon return from this method we end up back in the above
mentioned ContextPathServletAdaptor$HttpServletRequestAdaptor, which tacks
on the bundle name.
By way of example, when I send a request to
http://mymachine:8080/MyWebApp/MyBundle2/testJsfPath.faces, in Tomcat
request.getContextPath() in the jsp returns "/MyWebApp/MyBundle2" while
Websphere returns "/MyWebApp/MyBundle2/testJsfPath.jsp/MyBundle2". The
difference is the ?/MyBundle2/testJsfPath.jsp? which Websphere returns as
the servlet path above and Tomcat does not. Presumably this is because
the original request object passed in and wrapped is different:
com.ibm.ws.webcontainer.srt.SRTServletRequest for Websphere and
org.apache.catalina.connector.Request for Tomcat (or something like that).
What I don?t understand is why we tack on the servlet path in either
case. Here my workaround is to comment out code in
HttpServletRequestAdaptor.getContextPath() so as not to return the servlet
path.