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/05/17 06:58:59 UTC

[struts] branch struts-2-5-x updated: Partial backport of L. Lenart's PR#414 to 2.5.x: - Improve Dispatcher getLocale() handling if running in AppEngine. - Implemented the same improvement to the defaultLocale logic path within getLocale().

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

lukaszlenart pushed a commit to branch struts-2-5-x
in repository https://gitbox.apache.org/repos/asf/struts.git


The following commit(s) were added to refs/heads/struts-2-5-x by this push:
     new 59a6cbf  Partial backport of L. Lenart's PR#414 to 2.5.x: - Improve Dispatcher getLocale() handling if running in AppEngine. - Implemented the same improvement to the defaultLocale logic path within   getLocale().
     new 3d3512a  Merge pull request #416 from JCgH4164838Gh792C124B5/Partial_Backport_LL_tiny-improvements
59a6cbf is described below

commit 59a6cbf6cafb90427b19b756a46c8b37a5f6990f
Author: JCgH4164838Gh792C124B5 <43...@users.noreply.github.com>
AuthorDate: Sat May 16 18:44:34 2020 -0400

    Partial backport of L. Lenart's PR#414 to 2.5.x:
    - Improve Dispatcher getLocale() handling if running in AppEngine.
    - Implemented the same improvement to the defaultLocale logic path within
      getLocale().
---
 .../org/apache/struts2/dispatcher/Dispatcher.java     | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

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 9222c7b..5311943 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -696,12 +696,23 @@ public class Dispatcher {
             try {
                 locale = LocaleUtils.toLocale(defaultLocale);
             } catch (IllegalArgumentException e) {
-                LOG.warn(new ParameterizedMessage("Cannot convert 'struts.locale' = [{}] to proper locale, defaulting to request locale [{}]",
-                                defaultLocale, request.getLocale()), e);
-                locale = request.getLocale();
+                try {
+                    locale = request.getLocale();
+                    LOG.warn(new ParameterizedMessage("Cannot convert 'struts.locale' = [{}] to proper locale, defaulting to request locale [{}]",
+                                    defaultLocale, locale), e);
+                } catch (RuntimeException rex) {
+                    LOG.warn(new ParameterizedMessage("Cannot convert 'struts.locale' = [{}] to proper locale, and cannot get locale from HTTP Request, falling back to system default locale",
+                                    defaultLocale), rex);
+                    locale = Locale.getDefault();
+                }
             }
         } else {
-            locale = request.getLocale();
+            try {
+                locale = request.getLocale();
+            } catch (RuntimeException rex) {
+                LOG.warn("Cannot get locale from HTTP Request, falling back to system default locale", rex);
+                locale = Locale.getDefault();
+            }
         }
         return locale;
     }