Struts 2
  1. Struts 2
  2. WW-3796

Error at setting character encoding if the parameters have been already read

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.3.1.2
    • Fix Version/s: 2.3.3
    • Component/s: Dispatch Filter
    • Labels:
    • Environment:

      Glassfish

    • Flags:
      Patch

      Description

      In my application I have an access log filter that logs all incoming requests and the parameters of the request.
      The struts2 filter calls request.setCharacterEncoding(encoding), which results in an error, because the request encoding cannot be set after the parameters have been read. This pollutes the log with errors for every request.
      I cannot put the access log filter after the struts2 filter, because it does not invoke chain.doFilter() for the actions.
      I have a custom filter before the access log filter that sets the request encoding in advance. Struts2 tries to set the encoding again later, but too late in my case.
      The proposed patch is very simple and straightforward, and would solve my problem with the polluted log. If the encoding is already set to the same value, do not try to set it again. It is useless and will cause an error. In all other cases, set it as now.

      1. WW-3796.diff
        0.9 kB
        Pelladi Gabor

        Activity

        Pelladi Gabor created issue -
        Hide
        Pelladi Gabor added a comment -

        Patch attached

        Show
        Pelladi Gabor added a comment - Patch attached
        Pelladi Gabor made changes -
        Field Original Value New Value
        Attachment WW-3796.diff [ 12522253 ]
        Hide
        Lukasz Lenart added a comment -

        Solved, thanks for the patch and reporting!

        Show
        Lukasz Lenart added a comment - Solved, thanks for the patch and reporting!
        Lukasz Lenart made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Lukasz Lenart [ lukaszlenart ]
        Fix Version/s 2.3.3 [ 12320642 ]
        Resolution Fixed [ 1 ]
        Hide
        Hudson added a comment -

        Integrated in Struts2 #454 (See https://builds.apache.org/job/Struts2/454/)
        WW-3796 Changes logic to set encoding on HttpServletRequest if differs from configured (Revision 1324888)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
        • /struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
        Show
        Hudson added a comment - Integrated in Struts2 #454 (See https://builds.apache.org/job/Struts2/454/ ) WW-3796 Changes logic to set encoding on HttpServletRequest if differs from configured (Revision 1324888) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java /struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
        Hide
        Pelladi Gabor added a comment -

        Just for the record, I forgot to mention that different containers behave differently. This issue did not come up on tomcat, but on glassfish it produced this for every request:
        PWC4011: Unable to set request character encoding to UTF-8 from context /myproject, because request parameters have already been read, or ServletRequest.getReader() has already been called

        Show
        Pelladi Gabor added a comment - Just for the record, I forgot to mention that different containers behave differently. This issue did not come up on tomcat, but on glassfish it produced this for every request: PWC4011: Unable to set request character encoding to UTF-8 from context /myproject, because request parameters have already been read, or ServletRequest.getReader() has already been called
        Lukasz Lenart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        3h 7m 1 Lukasz Lenart 11/Apr/12 18:41
        Resolved Resolved Closed Closed
        2d 13h 33m 1 Lukasz Lenart 14/Apr/12 08:15

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Pelladi Gabor
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development