001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.util.PortalInitable;
022    import com.liferay.portal.kernel.util.PropsKeys;
023    import com.liferay.portal.util.PropsValues;
024    
025    import javax.servlet.http.HttpSession;
026    import javax.servlet.http.HttpSessionEvent;
027    
028    /**
029     * @author Michael Young
030     */
031    public class PortalSessionCreator implements PortalInitable {
032    
033            public PortalSessionCreator(HttpSessionEvent event) {
034                    _event = event;
035            }
036    
037            public void portalInit() {
038                    if (PropsValues.SESSION_DISABLED) {
039                            return;
040                    }
041    
042                    HttpSession session = _event.getSession();
043    
044                    try {
045                            PortalSessionContext.put(session.getId(), session);
046                    }
047                    catch (IllegalStateException ise) {
048                            if (_log.isWarnEnabled()) {
049                                    _log.warn(ise, ise);
050                            }
051                    }
052    
053                    // Process session created events
054    
055                    try {
056                            EventsProcessorUtil.process(
057                                    PropsKeys.SERVLET_SESSION_CREATE_EVENTS,
058                                    PropsValues.SERVLET_SESSION_CREATE_EVENTS, session);
059                    }
060                    catch (ActionException ae) {
061                            _log.error(ae, ae);
062                    }
063            }
064    
065            private static Log _log = LogFactoryUtil.getLog(
066                    PortalSessionCreator.class);
067    
068            private HttpSessionEvent _event;
069    
070    }