Author: lukaszlenart
Date: Sat Mar 17 20:08:37 2012
New Revision: 1301989
URL: http://svn.apache.org/viewvc?rev=1301989&view=rev
Log:
WW-3773 recreates HttpSession and SessionMap if HttpSession doesn't exist
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CreateSessionInterceptorTest.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java?rev=1301989&r1=1301988&r2=1301989&view=diff
==
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java
Sat Mar 17 20:08:37 2012
@@ -21,19 +21,21 @@
package org.apache.struts2.interceptor;
-import org.apache.struts2.ServletActionContext;
-
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.SessionMap;
+
+import javax.servlet.http.HttpSession;
/**
*
*
- * This interceptor creates the HttpSession.
+ * This interceptor creates the HttpSession if it doesn't exist, also
SessionMap is recreated and put in ServletActionContext.
*
- * This is particular usefull when using the <@s.token> tag in
freemarker templates.
+ * This is particular useful when using the <@s.token> tag in freemarker
templates.
* The tag do require that a HttpSession is already created since
freemarker commits
* the response to the client immediately.
*
@@ -88,11 +90,14 @@ public class CreateSessionInterceptor ex
* @see
com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
*/
public String intercept(ActionInvocation invocation) throws Exception {
-if (LOG.isDebugEnabled()) {
-LOG.debug("Creating HttpSession");
+HttpSession httpSession =
ServletActionContext.getRequest().getSession(false);
+if (httpSession == null) {
+if (LOG.isDebugEnabled()) {
+LOG.debug("Creating new HttpSession and new SessionMap in
ServletActionContext");
+}
+ServletActionContext.getRequest().getSession(true);
+ServletActionContext.getContext().setSession(new
SessionMap(ServletActionContext.getRequest()));
}
-
-ServletActionContext.getRequest().getSession(true);
return invocation.invoke();
}
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CreateSessionInterceptorTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CreateSessionInterceptorTest.java?rev=1301989&r1=1301988&r2=1301989&view=diff
==
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CreateSessionInterceptorTest.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CreateSessionInterceptorTest.java
Sat Mar 17 20:08:37 2012
@@ -21,15 +21,14 @@
package org.apache.struts2.interceptor;
-import javax.servlet.http.HttpServletRequest;
-
+import com.opensymphony.xwork2.mock.MockActionInvocation;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsTestCase;
import org.jmock.Mock;
import org.jmock.core.constraint.IsEqual;
import org.jmock.core.matcher.InvokeOnceMatcher;
-import com.opensymphony.xwork2.mock.MockActionInvocation;
+import javax.servlet.http.HttpServletRequest;
/**
* Test case for CreateSessionInterceptor.
@@ -39,7 +38,9 @@ public class CreateSessionInterceptorTes
public void testCreateSession() throws Exception {
Mock httpServletRequestMock = new Mock(HttpServletRequest.class);
+httpServletRequestMock.expects(new
InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.FALSE));
httpServletRequestMock.expects(new
InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.TRUE));
+httpServletRequestMock.expects(new
InvokeOnceMatcher()).method("getSession").with(new IsEqual(Boolean.FALSE));
HttpServletRequest request = (HttpServletRequest)
httpServletRequestMock.proxy();
ServletActionContext.setRequest(request);