Discussion:
Should servletPath contain the welcome file?
Florent Guillaume
2018-10-01 11:54:52 UTC
Permalink
Hi,

I'm observing a behavior (Tomcat 9.0.10) with respect to getServletPath()
that I don't understand when reading the servlet spec.

For a request http://localhost:8080/nuxeo/ui/ I get the following:

httpRequest.getRequestURL()
http://localhost:8080/nuxeo/ui/
httpRequest.getRequestURI()
/nuxeo/ui/
httpRequest.getContextPath()
/nuxeo
httpRequest.getServletPath()
/ui/index.jsp
httpRequest.getPathInfo()
null
httpRequest.getQueryString()
null

But my understanding from the Servlet spec is that we should always have
(Servlet 4.0 spec, §3.5):
requestURI = contextPath + servletPath + pathInfo
which you can see is not the case here. I don't think getServletPath()
should return the index.jsp part, which is a welcome file.

FYI the mapping that matches the above is:
httpRequest.getHttpServletMapping().getServletName()
(java.lang.String) jsp
httpRequest.getHttpServletMapping().getMappingMatch()
(javax.servlet.http.MappingMatch) EXTENSION
httpRequest.getHttpServletMapping().getPattern()
(java.lang.String) *.jsp
httpRequest.getHttpServletMapping().getMatchValue()
(java.lang.String) ui/index

Is this a bug in Tomcat or did I miss something from the spec?

Thanks,
Florent
--
[image: Nuxeo Logo] <https://www.nuxeo.com/>

Florent Guillaume Head of R&D [image: LinkedIn]
<https://www.linkedin.com/in/fguillaume/> [image: Twitter]
<https://twitter.com/efge> [image: Github] <https://github.com/efge>

Nuxeo Content Services Platform. Stay ahead.
Mark Thomas
2018-10-01 16:41:39 UTC
Permalink
Post by Florent Guillaume
Hi,
I'm observing a behavior (Tomcat 9.0.10) with respect to getServletPath()
that I don't understand when reading the servlet spec.
httpRequest.getRequestURL()
http://localhost:8080/nuxeo/ui/
httpRequest.getRequestURI()
/nuxeo/ui/
httpRequest.getContextPath()
/nuxeo
httpRequest.getServletPath()
/ui/index.jsp
httpRequest.getPathInfo()
null
httpRequest.getQueryString()
null
But my understanding from the Servlet spec is that we should always have
requestURI = contextPath + servletPath + pathInfo
which you can see is not the case here. I don't think getServletPath()
should return the index.jsp part, which is a welcome file.
httpRequest.getHttpServletMapping().getServletName()
(java.lang.String) jsp
httpRequest.getHttpServletMapping().getMappingMatch()
(javax.servlet.http.MappingMatch) EXTENSION
httpRequest.getHttpServletMapping().getPattern()
(java.lang.String) *.jsp
httpRequest.getHttpServletMapping().getMatchValue()
(java.lang.String) ui/index
Is this a bug in Tomcat or did I miss something from the spec?
It is one of the many grey areas in the spec around those methods. This
is currently being tracked as:
https://github.com/eclipse-ee4j/servlet-api/issues/18

Once Eclipse has figured out how the spec update process is going to
work, I'm expecting work to start on that issue. As an aside,

requestURI = contextPath + servletPath + pathInfo

is a good general rule but it does not work for all edge cases (which
are generally the areas issue 18 seeks to address).

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Florent Guillaume
2018-10-01 16:55:56 UTC
Permalink
Ok thanks. I added a workaround in my code for the welcome file case.

And indeed I had already observed other situations where requestURI =
contextPath + servletPath + pathInfo is not true if there's normalization
going on, for instance the fact that we can have:

requestURI = /nuxeo/login.jsp/../foo/bar.xhtml;jsessionid=123
contextPath = /nuxeo
servletPath = /foo
pathInfo = /bar.xhtml

Thanks,
Florent
Post by Mark Thomas
Post by Florent Guillaume
Hi,
I'm observing a behavior (Tomcat 9.0.10) with respect to getServletPath()
that I don't understand when reading the servlet spec.
httpRequest.getRequestURL()
http://localhost:8080/nuxeo/ui/
httpRequest.getRequestURI()
/nuxeo/ui/
httpRequest.getContextPath()
/nuxeo
httpRequest.getServletPath()
/ui/index.jsp
httpRequest.getPathInfo()
null
httpRequest.getQueryString()
null
But my understanding from the Servlet spec is that we should always have
requestURI = contextPath + servletPath + pathInfo
which you can see is not the case here. I don't think getServletPath()
should return the index.jsp part, which is a welcome file.
httpRequest.getHttpServletMapping().getServletName()
(java.lang.String) jsp
httpRequest.getHttpServletMapping().getMappingMatch()
(javax.servlet.http.MappingMatch) EXTENSION
httpRequest.getHttpServletMapping().getPattern()
(java.lang.String) *.jsp
httpRequest.getHttpServletMapping().getMatchValue()
(java.lang.String) ui/index
Is this a bug in Tomcat or did I miss something from the spec?
It is one of the many grey areas in the spec around those methods. This
https://github.com/eclipse-ee4j/servlet-api/issues/18
Once Eclipse has figured out how the spec update process is going to
work, I'm expecting work to start on that issue. As an aside,
requestURI = contextPath + servletPath + pathInfo
is a good general rule but it does not work for all edge cases (which
are generally the areas issue 18 seeks to address).
Mark
---------------------------------------------------------------------
--
[image: Nuxeo Logo] <https://www.nuxeo.com/>

Florent Guillaume Head of R&D [image: LinkedIn]
<https://www.linkedin.com/in/fguillaume/> [image: Twitter]
<https://twitter.com/efge> [image: Github] <https://github.com/efge>

Nuxeo Content Services Platform. Stay ahead.
Loading...