You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2020/12/11 08:12:23 UTC

[struts] branch WW-5100-character-encoding-on-response created (now 73dbe5b)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5100-character-encoding-on-response
in repository https://gitbox.apache.org/repos/asf/struts.git.


      at 73dbe5b  WW-5100 Applies encoding to response as well

This branch includes the following new commits:

     new 73dbe5b  WW-5100 Applies encoding to response as well

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[struts] 01/01: WW-5100 Applies encoding to response as well

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5100-character-encoding-on-response
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 73dbe5b5954c58c23b752ac28787c06f094d873a
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Fri Dec 11 09:12:11 2020 +0100

    WW-5100 Applies encoding to response as well
---
 .../main/java/org/apache/struts2/dispatcher/Dispatcher.java | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
index 8d7b5fb..7b9a8e1 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -835,6 +835,7 @@ public class Dispatcher {
 
         if (encoding != null) {
             applyEncoding(request, encoding);
+            applyEncoding(response, encoding);
         }
 
         if (locale != null) {
@@ -854,7 +855,17 @@ public class Dispatcher {
                 request.setCharacterEncoding(encoding);
             }
         } catch (Exception e) {
-            LOG.error("Error setting character encoding to '{}' - ignoring.", encoding, e);
+            LOG.error(new ParameterizedMessage("Error setting character encoding to '{}' on request - ignoring.", encoding), e);
+        }
+    }
+
+    private void applyEncoding(HttpServletResponse response, String encoding) {
+        try {
+            if (!encoding.equals(response.getCharacterEncoding())) {
+                response.setCharacterEncoding(encoding);
+            }
+        } catch (Exception e) {
+            LOG.error(new ParameterizedMessage("Error setting character encoding to '{}' on response - ignoring.", encoding), e);
         }
     }