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.portal.servlet;
16  
17  import com.liferay.portal.events.EventsProcessorUtil;
18  import com.liferay.portal.kernel.events.ActionException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.BasePortalLifecycle;
22  import com.liferay.portal.kernel.util.PropsKeys;
23  import com.liferay.portal.util.PropsValues;
24  
25  import javax.servlet.http.HttpSession;
26  import javax.servlet.http.HttpSessionEvent;
27  
28  /**
29   * <a href="PortalSessionCreator.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Michael Young
32   */
33  public class PortalSessionCreator extends BasePortalLifecycle {
34  
35      public PortalSessionCreator(HttpSessionEvent httpSessionEvent) {
36          _httpSessionEvent = httpSessionEvent;
37  
38          registerPortalLifecycle(METHOD_INIT);
39      }
40  
41      protected void doPortalDestroy() {
42      }
43  
44      protected void doPortalInit() {
45          if (PropsValues.SESSION_DISABLED) {
46              return;
47          }
48  
49          HttpSession session = _httpSessionEvent.getSession();
50  
51          try {
52              PortalSessionContext.put(session.getId(), session);
53          }
54          catch (IllegalStateException ise) {
55              if (_log.isWarnEnabled()) {
56                  _log.warn(ise, ise);
57              }
58          }
59  
60          // Process session created events
61  
62          try {
63              EventsProcessorUtil.process(
64                  PropsKeys.SERVLET_SESSION_CREATE_EVENTS,
65                  PropsValues.SERVLET_SESSION_CREATE_EVENTS, session);
66          }
67          catch (ActionException ae) {
68              _log.error(ae, ae);
69          }
70      }
71  
72      private static Log _log = LogFactoryUtil.getLog(
73          PortalSessionCreator.class);
74  
75      private HttpSessionEvent _httpSessionEvent;
76  
77  }