glassfish
  1. glassfish
  2. GLASSFISH-1411

Special attribute handling in request dispatch wrappers is inefficient

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 9.1pe
    • Fix Version/s: 9.1pe_dev
    • Component/s: web_container
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Sun

    • Issuezilla Id:
      1,411
    • Status Whiteboard:
      Hide

      fixed-pwc12

      Show
      fixed-pwc12

      Description

      The servlet spec defines the following special attribute names, which are set by
      the container (and never by user code) during a request dispatch operation:

      javax.servlet.include.request_uri
      javax.servlet.include.context_path
      javax.servlet.include.path_info
      javax.servlet.include.servlet_path
      javax.servlet.include.query_string
      javax.servlet.forward.request_uri
      javax.servlet.forward.context_path
      javax.servlet.forward.path_info
      javax.servlet.forward.servlet_path
      javax.servlet.forward.query_string

      During a dispatch operation, the request gets wrapped inside an
      org.apache.catalina.core.Application(Http)Request instance, which knows about
      these special attribute names, and gives them special treatment. However, the
      way this special treatment is implemented is inefficient, as indicated by sdo's
      performance data:

      The current impl of Application(Http)Request defines a static String[]
      containing the above strings, and the impl of its setAttribute() and
      removeAttribute() methods checks if the attribute to be set or removed is
      amongst the special ones (to decide whether special treatment is necessary) by
      enumerating the String[] and checking if the given attribute name matches any of
      the names in the String[].

      Storing the special attribute names in a java.util.HashSet would be much more
      efficient.

      An even better improvement would be to initialize an Application(Http)Request
      with its special attributes at construction time (instead of calling
      setAttribute() for each special attribute), which would completely avoid any
      checks for special attributes in setAttribute().

        Activity

        Hide
        jluehe added a comment -

        Incremental fix: Use HashSet instead of String[] for special attribute names

        Checking in ApplicationRequest.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationRequest.java,v
        <-- ApplicationRequest.java
        new revision: 1.4; previous revision: 1.3
        done

        Show
        jluehe added a comment - Incremental fix: Use HashSet instead of String[] for special attribute names Checking in ApplicationRequest.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationRequest.java,v <-- ApplicationRequest.java new revision: 1.4; previous revision: 1.3 done
        Hide
        jluehe added a comment -
        • Added new initSpecialAttributes() method to
          o.a.c.core.ApplicationHttpRequest, which is used to initialize a request
          dispatch wrapper with all its special javax.servlet.include.* or
          javax.servlet.forward.* attributes, respectively, in one shot, rather than
          calling setAttribute() for each
        • Instead of managing a wrapper's special attributes in two arrays (one for
          the attribute names, another for the attribute values), use a HashMap.

        Checking in ApplicationHttpRequest.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v
        <-- ApplicationHttpRequest.java
        new revision: 1.7; previous revision: 1.6
        done
        Checking in ApplicationRequest.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationRequest.java,v
        <-- ApplicationRequest.java
        new revision: 1.5; previous revision: 1.4
        done
        Checking in ApplicationDispatcher.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationDispatcher.java,v
        <-- ApplicationDispatcher.java
        new revision: 1.14; previous revision: 1.13
        done

        Show
        jluehe added a comment - Added new initSpecialAttributes() method to o.a.c.core.ApplicationHttpRequest, which is used to initialize a request dispatch wrapper with all its special javax.servlet.include.* or javax.servlet.forward.* attributes, respectively, in one shot, rather than calling setAttribute() for each Instead of managing a wrapper's special attributes in two arrays (one for the attribute names, another for the attribute values), use a HashMap. Checking in ApplicationHttpRequest.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v <-- ApplicationHttpRequest.java new revision: 1.7; previous revision: 1.6 done Checking in ApplicationRequest.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationRequest.java,v <-- ApplicationRequest.java new revision: 1.5; previous revision: 1.4 done Checking in ApplicationDispatcher.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationDispatcher.java,v <-- ApplicationDispatcher.java new revision: 1.14; previous revision: 1.13 done
        Hide
        jluehe added a comment -

        Fixed minor regression introduced by previous commit: If request dispatch
        forward is followed by a request dispatch include, any of the
        javax.servlet.forward standard attributes must be included in the enumeration of
        request attribute names returned by
        javax.servlet.ServletRequest.getAttributeNames():

        Checking in ApplicationHttpRequest.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v
        <-- ApplicationHttpRequest.java
        new revision: 1.8; previous revision: 1.7
        done

        Show
        jluehe added a comment - Fixed minor regression introduced by previous commit: If request dispatch forward is followed by a request dispatch include, any of the javax.servlet.forward standard attributes must be included in the enumeration of request attribute names returned by javax.servlet.ServletRequest.getAttributeNames(): Checking in ApplicationHttpRequest.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v <-- ApplicationHttpRequest.java new revision: 1.8; previous revision: 1.7 done
        Hide
        kmeduri added a comment -

        Merged the fix to PWC12Dev_Branch:

        Checking in
        appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java;
        /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v
        <-- ApplicationHttpRequest.java
        new revision: 1.6.6.2; previous revision: 1.6.6.1
        done

        Show
        kmeduri added a comment - Merged the fix to PWC12Dev_Branch: Checking in appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java; /cvs/glassfish/appserv-webtier/src/java/org/apache/catalina/core/ApplicationHttpRequest.java,v <-- ApplicationHttpRequest.java new revision: 1.6.6.2; previous revision: 1.6.6.1 done

          People

          • Assignee:
            jluehe
            Reporter:
            jluehe
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: