Repository: struts
Updated Branches:
  refs/heads/master 38409e0e0 -> 26fa06b11


[WW-4741] Do not force session creation on locale read operation

Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/78db281c
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/78db281c
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/78db281c

Branch: refs/heads/master
Commit: 78db281cd6f66d50b3a5f48e2b1dee596d0a2232
Parents: 9fcf2df
Author: Yasser Zamani <yasser.zam...@live.com>
Authored: Fri Feb 24 18:18:53 2017 +0330
Committer: Yasser Zamani <yasser.zam...@live.com>
Committed: Fri Feb 24 18:18:53 2017 +0330

----------------------------------------------------------------------
 .../struts2/interceptor/I18nInterceptor.java      | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/78db281c/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java 
b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
index f86c5f8..9060d69 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
@@ -34,6 +34,8 @@ import org.apache.struts2.dispatcher.Parameter;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
 import java.util.Locale;
 import java.util.Map;
 
@@ -296,12 +298,16 @@ public class I18nInterceptor extends AbstractInterceptor {
             Map<String, Object> session = 
invocation.getInvocationContext().getSession();
 
             if (session != null) {
-                String sessionId = 
ServletActionContext.getRequest().getSession().getId();
-                synchronized (sessionId.intern()) {
-                    Object sessionLocale = session.get(attributeName);
-                    if (sessionLocale != null && sessionLocale instanceof 
Locale) {
-                        locale = (Locale) sessionLocale;
-                        LOG.debug("Applied session locale: {}", locale);
+                //[WW-4741] Do not force session creation while this is a read 
operation
+                HttpSession httpSession = 
ServletActionContext.getRequest().getSession(false);
+                if(null != httpSession) {
+                    String sessionId = httpSession.getId();
+                    synchronized (sessionId.intern()) {
+                        Object sessionLocale = session.get(attributeName);
+                        if (sessionLocale != null && sessionLocale instanceof 
Locale) {
+                            locale = (Locale) sessionLocale;
+                            LOG.debug("Applied session locale: {}", locale);
+                        }
                     }
                 }
             }

Reply via email to