jersey
  1. jersey
  2. JERSEY-880

com.sun.jersey.config.property.WebPageContentRegex parameter fails on a Websphere Application Server.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8, 2.0-m02
    • Fix Version/s: 1.13, 2.0
    • Component/s: core
    • Labels:
      None
    • Environment:

      Websphere web Application Server 7.1
      Jersey core + Jersey Server 1.8 and later

      Description

      com.sun.jersey.config.property.WebPageContentRegex parameter fails on a Websphere Application Server.

      WebPageContentRegex is a Filter parameter that takes regex expressions that are used to allow requests to be passed to the underlying servlet to process.
      This feature works fine in Weblogic Application Servers.
      This feature becomes disabled in a Websphere Applications Servers.
      The details of the configuration are as follows.
      MyServletContainer which extends com.sun.jersey.spi.container.servlet.ContainerServlet is declared as a filter. The filter is mapped to "/*" url path.
      A filter parameter value for com.sun.jersey.config.property.WebPageContentRegex is provided as "/(css|schema|images)"

      A request for /warrootcontext/schema/css/test.xsl fails with a 404 not found message.

      A similar request for the same configuration succeeds on weblogic.

      On going through the source code of com.sun.jersey.spi.container.servlet.ContainerServlet, the following issue is seen.
      In the method public void doFilter(HttpServletRequest,HttpServletResponse, FilterChain), static content processing is done on the basis of request.getServletPath().
      Javadocs for HttpServletRequest method states that "Returns the part of this request's URL that calls the servlet." More explicitly, "This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern".
      The reported issue is resolved if the code is modified to to do the static content processing based on the return value of request.getPathInfo().

        Activity

        Hide
        Jakub Podlesak added a comment -

        Could you please double check the regex? In order to match the URI mentioned above,
        you should use the following value for the com.sun.jersey.config.property.WebPageContentRegex parameter:

        "/(css|schema|images)/.*"

        Please double-check and ideally attach a simple web application as a reproducible test case
        (a war file with source code included should be sufficient), that works on WLS and fails on WAS.

        BTW: To generally forward all requests, which would otherwise result to 404 in Jersey,
        you can use the following Jersey parameter:

        <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
        </init-param>

        Show
        Jakub Podlesak added a comment - Could you please double check the regex? In order to match the URI mentioned above, you should use the following value for the com.sun.jersey.config.property.WebPageContentRegex parameter: "/(css|schema|images)/.*" Please double-check and ideally attach a simple web application as a reproducible test case (a war file with source code included should be sufficient), that works on WLS and fails on WAS. BTW: To generally forward all requests, which would otherwise result to 404 in Jersey, you can use the following Jersey parameter: <init-param> <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name> <param-value>true</param-value> </init-param>
        Hide
        Jakub Podlesak added a comment -

        I am resolving as invalid. Please comment on the report if you just did a typo in the original post
        or you insist the test case works as you originally suggested. I am ready to re-open as needed.

        Show
        Jakub Podlesak added a comment - I am resolving as invalid. Please comment on the report if you just did a typo in the original post or you insist the test case works as you originally suggested. I am ready to re-open as needed.
        Hide
        nsreehari_oam added a comment -

        The regex used is "/(css|schema|images)/.*".
        While this works on weblogic servers, it fails on WAS servers. As described in the issue, the servlet API seems to indicate that the WAS servers are right.

        Show
        nsreehari_oam added a comment - The regex used is "/(css|schema|images)/.*". While this works on weblogic servers, it fails on WAS servers. As described in the issue, the servlet API seems to indicate that the WAS servers are right.
        Hide
        nsreehari_oam added a comment -

        I am not able to reopen this issue. Please re-open.
        Thanks.

        Show
        nsreehari_oam added a comment - I am not able to reopen this issue. Please re-open. Thanks.
        Hide
        Jakub Podlesak added a comment -

        Re-opening the bug, still need to reproduce on WAS.

        Show
        Jakub Podlesak added a comment - Re-opening the bug, still need to reproduce on WAS.
        Hide
        Jakub Podlesak added a comment -

        Assigning to Michal.

        Suggested test case is the Jersey Bookstore example, with the com.sun.jersey.config.feature.FilterForwardOn404
        feature (in src/main/webapp/WEB-INF/web.xml) switched to false.

        After deployment, http://localhost:8080/bookstore/jsp/help.jsp (adjust the port number as needed)
        should return 200 and a valid content.

        Show
        Jakub Podlesak added a comment - Assigning to Michal. Suggested test case is the Jersey Bookstore example, with the com.sun.jersey.config.feature.FilterForwardOn404 feature (in src/main/webapp/WEB-INF/web.xml) switched to false. After deployment, http://localhost:8080/bookstore/jsp/help.jsp (adjust the port number as needed) should return 200 and a valid content.
        Hide
        Michal Gajdos added a comment -

        Tried on the Jersey Bookstore example (also webapp/css copied to webapp/jsp):

        web.xml
        <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                 version="2.4">
        
           <filter>
               <filter-name>Jersey Filter</filter-name>
               <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
               <init-param>
                   <param-name>com.sun.jersey.config.feature.Redirect</param-name>
                   <param-value>true</param-value>
               </init-param>
               <init-param>
                   <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name>
                   <param-value>true</param-value>
               </init-param>
               <init-param>
                   <param-name>com.sun.jersey.config.property.packages</param-name>
                   <param-value>com.sun.jersey.samples.bookstore.resources</param-value>
               </init-param>
               <!-- pass to next filter if Jersey/App returns 404 -->
               <init-param>
                   <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
                   <param-value>false</param-value>
               </init-param>
               <!-- match regex to determine if Jersey/App is invoked or pass to next filter -->
               
               <init-param>
                   <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
                   <param-value>/(images|css|jsp)/.*</param-value>
               </init-param>
               
           </filter>
           <filter-mapping>
               <filter-name>Jersey Filter</filter-name>
               <url-pattern>/*</url-pattern>
           </filter-mapping>
        </web-app>
        

        Results:

        Show
        Michal Gajdos added a comment - Tried on the Jersey Bookstore example (also webapp/css copied to webapp/jsp ): web.xml <web-app xmlns= "http: //java.sun.com/xml/ns/j2ee" xmlns:xsi= "http: //www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http: //java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version= "2.4" > <filter> <filter-name>Jersey Filter</filter-name> <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class> <init-param> <param-name>com.sun.jersey.config.feature.Redirect</param-name> <param-value> true </param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.feature.ImplicitViewables</param-name> <param-value> true </param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.sun.jersey.samples.bookstore.resources</param-value> </init-param> <!-- pass to next filter if Jersey/App returns 404 --> <init-param> <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name> <param-value> false </param-value> </init-param> <!-- match regex to determine if Jersey/App is invoked or pass to next filter --> <init-param> <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> <param-value>/(images|css|jsp)/.*</param-value> </init-param> </filter> <filter-mapping> <filter-name>Jersey Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> Results: http://localhost:9080/bookstore/jsp/help.jsp Help web page http://localhost:9080/bookstore/jsp/css/style.css Error 404: Not Found
        Hide
        Michal Gajdos added a comment - - edited

        WAS interprets HttpServletRequest#getServletPath() and HttpServletRequest#getPathInfo() differently when accessing a static resource.

        Jetty, GF:

        WAS:

        Show
        Michal Gajdos added a comment - - edited WAS interprets HttpServletRequest#getServletPath() and HttpServletRequest#getPathInfo() differently when accessing a static resource. Jetty, GF: http://localhost:8080/bookstore/jsp/help.jsp ServletPath: /jsp/help.jsp PathInfo: null http://localhost:8080/bookstore/jsp/css/style.css ServletPath: /jsp/css/style.css PathInfo: null WAS: http://localhost:9080/bookstore/jsp/help.jsp ServletPath: /jsp/help.jsp PathInfo: null http://localhost:9080/bookstore/jsp/css/style.css ServletPath: PathInfo: /jsp/css/style.css
        Hide
        Michal Gajdos added a comment -

        Fixed for Jersey1 (trunk - 1.13-SNAPSHOT) and Jersey2. Tested on Jetty, GF, WAS8.

        Show
        Michal Gajdos added a comment - Fixed for Jersey1 (trunk - 1.13-SNAPSHOT) and Jersey2. Tested on Jetty, GF, WAS8.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            nsreehari_oam
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: