1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.interceptor;
23
24 import org.apache.struts2.ServletActionContext;
25
26 import com.opensymphony.xwork2.ActionInvocation;
27 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
28 import com.opensymphony.xwork2.util.logging.Logger;
29 import com.opensymphony.xwork2.util.logging.LoggerFactory;
30
31 /***
32 * <!-- START SNIPPET: description -->
33 *
34 * This interceptor creates the HttpSession.
35 * <p/>
36 * This is particular usefull when using the <@s.token> tag in freemarker templates.
37 * The tag <b>do</b> require that a HttpSession is already created since freemarker commits
38 * the response to the client immediately.
39 *
40 * <!-- END SNIPPET: description -->
41 *
42 * <p/> <u>Interceptor parameters:</u>
43 *
44 *
45 * <!-- START SNIPPET: extending -->
46 *
47 * <ul>
48 * <li>none</li>
49 * </ul>
50 *
51 * <!-- END SNIPPET: extending -->
52 *
53 *
54 * <!-- START SNIPPET: parameters -->
55 *
56 * <ul>
57 *
58 * <li>None</li>
59 *
60 * </ul>
61 *
62 * <!-- END SNIPPET: parameters -->
63 *
64 * <b>Example:</b>
65 *
66 * <pre>
67 * <!-- START SNIPPET: example -->
68 *
69 * <action name="someAction" class="com.examples.SomeAction">
70 * <interceptor-ref name="createSession"/>
71 * <interceptor-ref name="defaultStack"/>
72 * <result name="input">input_with_token_tag.ftl</result>
73 * </action>
74 *
75 * <!-- END SNIPPET: example -->
76 * </pre>
77 *
78 * @version $Date: 2008-04-27 09:41:38 -0400 (Sun, 27 Apr 2008) $ $Id: CreateSessionInterceptor.java 651946 2008-04-27 13:41:38Z apetrelli $
79 */
80 public class CreateSessionInterceptor extends AbstractInterceptor {
81
82 private static final long serialVersionUID = -4590322556118858869L;
83
84 private static final Logger LOG = LoggerFactory.getLogger(CreateSessionInterceptor.class);
85
86
87
88
89
90 public String intercept(ActionInvocation invocation) throws Exception {
91 LOG.debug("Creating HttpSession");
92 ServletActionContext.getRequest().getSession(true);
93 return invocation.invoke();
94 }
95
96 }