001
014
015 package com.liferay.portal.servlet;
016
017 import com.liferay.portal.kernel.util.ServerDetector;
018 import com.liferay.portal.resiliency.spi.agent.SPIAgentRequest;
019
020 import javax.servlet.http.HttpServletRequest;
021 import javax.servlet.http.HttpServletRequestWrapper;
022 import javax.servlet.http.HttpSession;
023
024
028 public class SharedSessionServletRequest extends HttpServletRequestWrapper {
029
030 public SharedSessionServletRequest(
031 HttpServletRequest request, boolean shared) {
032
033 super(request);
034
035 _portalSession = request.getSession();
036 _shared = shared;
037 }
038
039 @Override
040 public HttpSession getSession() {
041 return getSession(true);
042 }
043
044 @Override
045 public HttpSession getSession(boolean create) {
046 if (create) {
047 checkPortalSession();
048 }
049
050 if (_shared) {
051 return _portalSession;
052 }
053
054 HttpSession portletSession = super.getSession(create);
055
056 if ((portletSession != null) && (portletSession != _portalSession)) {
057 SPIAgentRequest.populatePortletSessionAttributes(
058 this, portletSession);
059
060 return getSharedSessionWrapper(_portalSession, portletSession);
061 }
062
063 return portletSession;
064 }
065
066 public HttpSession getSharedSession() {
067 return _portalSession;
068 }
069
070 protected void checkPortalSession() {
071 try {
072 _portalSession.isNew();
073 }
074 catch (IllegalStateException ise) {
075 _portalSession = super.getSession(true);
076 }
077 }
078
079 protected HttpSession getSharedSessionWrapper(
080 HttpSession portalSession, HttpSession portletSession) {
081
082 if (ServerDetector.isJetty()) {
083 return new JettySharedSessionWrapper(portalSession, portletSession);
084 }
085 else {
086 return new SharedSessionWrapper(portalSession, portletSession);
087 }
088 }
089
090 private HttpSession _portalSession;
091 private boolean _shared;
092
093 }