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.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.PortalInitable;
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 implements PortalInitable {
34  
35      public PortalSessionCreator(HttpSessionEvent event) {
36          _event = event;
37      }
38  
39      public void portalInit() {
40          if (PropsValues.SESSION_DISABLED) {
41              return;
42          }
43  
44          HttpSession session = _event.getSession();
45  
46          try {
47              PortalSessionContext.put(session.getId(), session);
48          }
49          catch (IllegalStateException ise) {
50              if (_log.isWarnEnabled()) {
51                  _log.warn(ise, ise);
52              }
53          }
54  
55          // Process session created events
56  
57          try {
58              EventsProcessorUtil.process(
59                  PropsKeys.SERVLET_SESSION_CREATE_EVENTS,
60                  PropsValues.SERVLET_SESSION_CREATE_EVENTS, session);
61          }
62          catch (ActionException ae) {
63              _log.error(ae, ae);
64          }
65      }
66  
67      private static Log _log = LogFactoryUtil.getLog(
68          PortalSessionCreator.class);
69  
70      private HttpSessionEvent _event;
71  
72  }