1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.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  }