[
https://issues.apache.org/jira/browse/WW-4741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16345126#comment-16345126
]
Yogesh Patel commented on WW-4741:
----------------------------------
[~lukaszlenart]
After upgrading to struts 2.5.13 version, it still creates HTTP Sessions for
all requests using I18Interceptor.
In I18Interceptor, Storage is *SESSION* bydefault for all requests.So it calls
*SessionLocaleHandler* to store values. below code snippet creates session for
all requests.
{code:java}
protected class SessionLocaleHandler extends RequestOnlyLocaleHandler {{code}
{code:java}
@Override
public Locale store(ActionInvocation invocation, Locale locale) {
//save it in session
Map<String, Object> session =
invocation.getInvocationContext().getSession();
if (session != null) {
String sessionId =
ServletActionContext.getRequest().getSession().getId();
synchronized (sessionId.intern()) {
session.put(attributeName, locale);
}
}
return locale;
}
{code}
If we compare older version of struts 2.3.24.1 then it was not creating
sessions if it does not exists.
{code:java}
Struts 2.3.24.1 Code Snippet as Belows:{code}
{code:java}
protected Locale storeLocale(ActionInvocation invocation, Locale locale,
String storage) {
//save it in session
Map<String, Object> session =
invocation.getInvocationContext().getSession();
if (session != null) {
synchronized (session) {
if (locale == null) {
storage = Storage.NONE.toString();
locale = readStoredLocale(invocation, session);
}
if (Storage.SESSION.toString().equals(storage)) {
session.put(attributeName, locale);
removeCache();
}
}
}
return locale;
}
{code}
Can you please confirm that is this issue in I18Interceptor ?
> Http Sessions forcefully created for all requests using I18nInterceptor with
> default Storage value.
> ---------------------------------------------------------------------------------------------------
>
> Key: WW-4741
> URL: https://issues.apache.org/jira/browse/WW-4741
> Project: Struts 2
> Issue Type: Bug
> Affects Versions: 2.5.10
> Reporter: Adam Greenfield
> Priority: Major
> Fix For: 2.5.12
>
>
> Changes made in WW-4730 for store and read functions cause an httpSession to
> be created for every request that uses I18nInterceptor when storage =
> Storage.SESSION.
> Current code checks for
> {noformat}Map<String, Object> session =
> invocation.getInvocationContext().getSession(){noformat}
> to be null and then calls
> {noformat}ServletActionContext.getRequest().getSession(){noformat}
> (notice how the second one references the HttpServletRequest. The
> HttpServletRequest Session and and the InvocationContext session are
> different. The request's session can be null, even if the
> InvocationContext's session is not).
> Calling .getSession() in this manner forcefully creates a session.
> An appropriate check here might be
> {noformat}HttpSession httpSession =
> ServletActionContext.getRequest().getSession(false);
> if(httpSession != null) {
> ... // get sessionId and synchronize on it
> }
> {noformat}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)