View Javadoc

1   /*
2    * $Id: CreateSessionInterceptor.java 471756 2006-11-06 15:01:43Z husted $
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  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 &lt;@s.token&gt; 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   * &lt;action name="someAction" class="com.examples.SomeAction"&gt;
69   *     &lt;interceptor-ref name="create-session"/&gt;
70   *     &lt;interceptor-ref name="defaultStack"/&gt;
71   *     &lt;result name="input"&gt;input_with_token_tag.ftl&lt;/result&gt;
72   * &lt;/action&gt;
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      /* (non-Javadoc)
87       * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
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  }