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