01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.http.core;
16:
17: import java.util.HashMap;
18: import javax.servlet.http.HttpSessionEvent;
19: import javax.servlet.http.HttpSessionListener;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22: import org.araneaframework.core.RelocatableDecorator;
23: import org.araneaframework.core.StandardEnvironment;
24: import org.araneaframework.http.router.StandardHttpSessionRouterService;
25:
26: /**
27: * A session listener which takes care of destroying the session service in the session.
28: *
29: * @author "Toomas Römer" <toomas@webmedia.ee>
30: */
31: public class StandardSessionListener implements HttpSessionListener {
32: public static final Log log = LogFactory
33: .getLog(StandardSessionListener.class);
34:
35: public void sessionCreated(HttpSessionEvent sessEvent) {
36: log.debug("Session '" + sessEvent.getSession().getId()
37: + "' created");
38: }
39:
40: public void sessionDestroyed(HttpSessionEvent sessEvent) {
41: if (sessEvent.getSession().getAttribute(
42: StandardHttpSessionRouterService.SESSION_SERVICE_KEY) != null) {
43: RelocatableDecorator service = (RelocatableDecorator) sessEvent
44: .getSession()
45: .getAttribute(
46: StandardHttpSessionRouterService.SESSION_SERVICE_KEY);
47:
48: if (service != null)
49: try {
50: if (service._getRelocatable()
51: .getCurrentEnvironment() == null)
52: service._getRelocatable().overrideEnvironment(
53: new StandardEnvironment(null,
54: new HashMap()));
55: service._getComponent().destroy();
56: } catch (Exception e) {
57: log
58: .error(
59: "Exception while destroying service in an expired session",
60: e);
61: }
62: }
63: log.debug("Session " + sessEvent.getSession().getId()
64: + " destroyed");
65: }
66: }
|