Skip to content

Commit 26fa06b

Browse files
author
cnenning
committed
WW-4741 Merges #119 which avoids session creation on locale read operation
2 parents 38409e0 + 78db281 commit 26fa06b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
import javax.servlet.http.Cookie;
3636
import javax.servlet.http.HttpServletResponse;
37+
import javax.servlet.http.HttpSession;
38+
3739
import java.util.Locale;
3840
import java.util.Map;
3941

@@ -296,12 +298,16 @@ public Locale read(ActionInvocation invocation) {
296298
Map<String, Object> session = invocation.getInvocationContext().getSession();
297299

298300
if (session != null) {
299-
String sessionId = ServletActionContext.getRequest().getSession().getId();
300-
synchronized (sessionId.intern()) {
301-
Object sessionLocale = session.get(attributeName);
302-
if (sessionLocale != null && sessionLocale instanceof Locale) {
303-
locale = (Locale) sessionLocale;
304-
LOG.debug("Applied session locale: {}", locale);
301+
//[WW-4741] Do not force session creation while this is a read operation
302+
HttpSession httpSession = ServletActionContext.getRequest().getSession(false);
303+
if(null != httpSession) {
304+
String sessionId = httpSession.getId();
305+
synchronized (sessionId.intern()) {
306+
Object sessionLocale = session.get(attributeName);
307+
if (sessionLocale != null && sessionLocale instanceof Locale) {
308+
locale = (Locale) sessionLocale;
309+
LOG.debug("Applied session locale: {}", locale);
310+
}
305311
}
306312
}
307313
}

0 commit comments

Comments
 (0)