001
014
015 package com.liferay.util.servlet;
016
017 import com.liferay.portal.kernel.util.ServerDetector;
018
019 import java.util.Map;
020
021 import javax.servlet.http.HttpServletRequest;
022 import javax.servlet.http.HttpServletRequestWrapper;
023 import javax.servlet.http.HttpSession;
024
025
029 public class SharedSessionServletRequest extends HttpServletRequestWrapper {
030
031 public SharedSessionServletRequest(
032 HttpServletRequest request, Map<String, Object> sharedSessionAttributes,
033 boolean shared) {
034
035 super(request);
036
037 _sharedSessionAttributes = sharedSessionAttributes;
038
039 _session = getSharedSessionWrapper(request.getSession());
040 _shared = shared;
041 }
042
043 public HttpSession getSession() {
044 if (_shared) {
045 return _session;
046 }
047 else {
048 return getSharedSessionWrapper(super.getSession());
049 }
050 }
051
052 public HttpSession getSession(boolean create) {
053 if (_shared) {
054 return _session;
055 }
056 else {
057 return getSharedSessionWrapper(super.getSession(create));
058 }
059 }
060
061 public HttpSession getSharedSession() {
062 return _session;
063 }
064
065 protected HttpSession getSharedSessionWrapper(HttpSession session) {
066 if (ServerDetector.isJetty()) {
067 return new JettySharedSessionWrapper(
068 session, _sharedSessionAttributes);
069 }
070 else {
071 return new SharedSessionWrapper(session, _sharedSessionAttributes);
072 }
073 }
074
075 private HttpSession _session;
076 private Map<String, Object> _sharedSessionAttributes;
077 private boolean _shared;
078
079 }