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