001
014
015 package com.liferay.portal.servlet;
016
017 import com.liferay.portal.events.EventsProcessorUtil;
018 import com.liferay.portal.kernel.events.ActionException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.servlet.PortalSessionContext;
022 import com.liferay.portal.kernel.util.BasePortalLifecycle;
023 import com.liferay.portal.kernel.util.PropsKeys;
024 import com.liferay.portal.util.PropsValues;
025
026 import javax.servlet.http.HttpSession;
027 import javax.servlet.http.HttpSessionEvent;
028
029
032 public class PortalSessionCreator extends BasePortalLifecycle {
033
034 public PortalSessionCreator(HttpSessionEvent httpSessionEvent) {
035 _httpSessionEvent = httpSessionEvent;
036
037 registerPortalLifecycle(METHOD_INIT);
038 }
039
040 @Override
041 protected void doPortalDestroy() {
042 }
043
044 @Override
045 protected void doPortalInit() {
046 if (PropsValues.SESSION_DISABLED) {
047 return;
048 }
049
050 HttpSession session = _httpSessionEvent.getSession();
051
052 try {
053 PortalSessionContext.put(session.getId(), session);
054 }
055 catch (IllegalStateException ise) {
056 if (_log.isWarnEnabled()) {
057 _log.warn(ise, ise);
058 }
059 }
060
061
062
063 try {
064 EventsProcessorUtil.process(
065 PropsKeys.SERVLET_SESSION_CREATE_EVENTS,
066 PropsValues.SERVLET_SESSION_CREATE_EVENTS, session);
067 }
068 catch (ActionException ae) {
069 _log.error(ae, ae);
070 }
071 }
072
073 private static Log _log = LogFactoryUtil.getLog(PortalSessionCreator.class);
074
075 private HttpSessionEvent _httpSessionEvent;
076
077 }