01: /*
02: * $Id: CreateSessionInterceptor.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 <@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 10:01:43 -0500 (Mon, 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
84: .getLog(CreateSessionInterceptor.class);
85:
86: /* (non-Javadoc)
87: * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
88: */
89: public String intercept(ActionInvocation invocation)
90: throws Exception {
91: _log.debug("Creating HttpSession");
92: ServletActionContext.getRequest().getSession(true);
93: return invocation.invoke();
94: }
95:
96: }
|