1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.servlet;
16  
17  import com.liferay.portal.kernel.util.ServerDetector;
18  
19  import java.util.Map;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletRequestWrapper;
23  import javax.servlet.http.HttpSession;
24  
25  /**
26   * <a href="SharedSessionServletRequest.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   * @author Brian Myunghun Kim
30   */
31  public class SharedSessionServletRequest extends HttpServletRequestWrapper {
32  
33      public SharedSessionServletRequest(
34          HttpServletRequest request, Map<String, Object> sharedSessionAttributes,
35          boolean shared) {
36  
37          super(request);
38  
39          _sharedSessionAttributes = sharedSessionAttributes;
40  
41          _session = getSharedSessionWrapper(request.getSession());
42          _shared = shared;
43      }
44  
45      public HttpSession getSession() {
46          if (_shared) {
47              return _session;
48          }
49          else {
50              return getSharedSessionWrapper(super.getSession());
51          }
52      }
53  
54      public HttpSession getSession(boolean create) {
55          if (_shared) {
56              return _session;
57          }
58          else {
59              return getSharedSessionWrapper(super.getSession(create));
60          }
61      }
62  
63      public HttpSession getSharedSession() {
64          return _session;
65      }
66  
67      protected HttpSession getSharedSessionWrapper(HttpSession session) {
68          if (!ServerDetector.isJOnAS() && ServerDetector.isJetty()) {
69              return new JettySharedSessionWrapper(
70                  session, _sharedSessionAttributes);
71          }
72          else {
73              return new SharedSessionWrapper(session, _sharedSessionAttributes);
74          }
75      }
76  
77      private HttpSession _session;
78      private Map<String, Object> _sharedSessionAttributes;
79      private boolean _shared;
80  
81  }