View Javadoc

1   /*
2    * $Id: CreateSessionInterceptor.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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 &lt;@s.token&gt; 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   * &lt;action name="someAction" class="com.examples.SomeAction"&gt;
66   *     &lt;interceptor-ref name="create-session"/&gt;
67   *     &lt;interceptor-ref name="defaultStack"/&gt;
68   *     &lt;result name="input"&gt;input_with_token_tag.ftl&lt;/result&gt;
69   * &lt;/action&gt;
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      /* (non-Javadoc)
84       * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
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  }