View Javadoc

1   /*
2    * $Id: ClearSessionInterceptor.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * &lt;action name="exampleAction" class="com.examples.ExampleAction"&gt;
68   *     &lt;interceptor-ref name="clearSession"/&gt;
69   *     &lt;interceptor-ref name="defaultStack"/&gt;
70   *     &lt;result name="success"&gt;example.jsp&lt;/result&gt;
71   * &lt;/action&gt;
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      /* (non-Javadoc)
83       * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
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  }