Type: Technical Task
Affects Version/s: None
PortletRequestDispatcherImpl sets what should be servletPath to pathInfo. This causes 80 failures in Portlet TCK 3.0 tests.
According to Portlet Specification 25.1.2, 25.5.1 and 25.6.1, when dispatching a request to a servlet/jsp, the HttpServletRequest methods getPathInfo(), getPathTranslated(), getQueryString(), getRequestURI() and getServletPath() (invoked in the target servlet) must return the path and query string information used to obtain the PortletRequestDispatcher object; several request attributes, like javax.servlet.include.path_info, must be set to the request and must be equal to the return values of the HttpServletRequest methods, like getPathInfo().
There are a lot of TCK test cases testing this requirement for include/forward towards servlet/jsp. 80 test cases failed due to the mismatch of expected values or attribute values against method return values.
Take a servlet mapping of the servlet used in a tck test case as example:
The path used to obtain the PortletRequestDispatcher in the test case is
According to the Servlet Spec (here we used Servlet Spec 3.1), chapter 12,
- A string beginning with a ‘ / ’ character and ending with a ‘ /* ’ suffix is used for path mapping.
- A string beginning with a ‘ *. ’ prefix is used as an extension mapping.
- The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port/<context-root>/. In this case the path info is ’ / ’ and the servlet path and context path is empty string (““).
- A string containing only the ’ / ’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
- All other strings are used for exact matches only.
For the servlet above, it’s a exact match, so the servlet path should be /DispatcherTests_SPEC2_19_IncludeServletAction_servlet and the path info should be null.
However, in PortletRequestDispatcherImpl, when parsing the path elements (PortletRequestDispatcherImpl.java#L165), we only set the servlet path when the url-pattern in the mapping ends with “/*”, and for other cases we set the dispatch target path as path_info. As a result, the path_info is set as /DispatcherTests_SPEC2_19_IncludeServletAction_servlet and servlet_path is null, which is wrong.
For example, according to Servlet Spec chapter 3.5, for path like “WEB-INF/path/to/view.jsp”, the servlet_path should be this path itself, and path_info should be null. While in our PortletRequestDispatcherImpl, the servlet_path is set to null and path_info is set to this path.