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 java.util.Map;
25
26 import com.opensymphony.xwork2.ActionContext;
27 import com.opensymphony.xwork2.ActionInvocation;
28 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
29 import com.opensymphony.xwork2.util.logging.Logger;
30 import com.opensymphony.xwork2.util.logging.LoggerFactory;
31
32 /***
33 * <!-- START SNIPPET: description -->
34 *
35 * This interceptor clears the HttpSession.
36 * <p/>
37 *
38 * <!-- END SNIPPET: description -->
39 *
40 * <p/> <u>Interceptor parameters:</u>
41 *
42 *
43 * <!-- START SNIPPET: extending -->
44 *
45 * <ul>
46 * <li>none</li>
47 * </ul>
48 *
49 * <!-- END SNIPPET: extending -->
50 *
51 *
52 * <!-- START SNIPPET: parameters -->
53 *
54 * <ul>
55 *
56 * <li>None</li>
57 *
58 * </ul>
59 *
60 * <!-- END SNIPPET: parameters -->
61 *
62 * <b>Example:</b>
63 *
64 * <pre>
65 * <!-- START SNIPPET: example -->
66 *
67 * <action name="exampleAction" class="com.examples.ExampleAction">
68 * <interceptor-ref name="clearSession"/>
69 * <interceptor-ref name="defaultStack"/>
70 * <result name="success">example.jsp</result>
71 * </action>
72 *
73 * <!-- END SNIPPET: example -->
74 * </pre>
75 */
76 public class ClearSessionInterceptor extends AbstractInterceptor {
77
78 private static final long serialVersionUID = -2102199238428329238L;
79
80 private static final Logger LOG = LoggerFactory.getLogger(ClearSessionInterceptor.class);
81
82
83
84
85 public String intercept(ActionInvocation invocation) throws Exception {
86 LOG.debug("Clearing HttpSession");
87 ActionContext ac = invocation.getInvocationContext();
88 Map session = ac.getSession();
89
90 if (null != session) {
91 session.clear();
92 }
93 return invocation.invoke();
94 }
95 }