KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > transport > http > AxisHTTPSessionListener


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  */

16 package org.apache.axis.transport.http;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.axis.components.logger.LogFactory;
20
21 import javax.servlet.http.HttpSessionListener JavaDoc;
22 import javax.servlet.http.HttpSessionEvent JavaDoc;
23 import javax.servlet.http.HttpSession JavaDoc;
24 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 /**
28  * A simple listener for Servlet 2.3 session lifecycle events.
29  * @web.listener
30  * @author Glen Daniels (gdaniels@apache.org)
31  */

32 public class AxisHTTPSessionListener implements HttpSessionListener JavaDoc {
33     protected static Log log =
34             LogFactory.getLog(AxisHTTPSessionListener.class.getName());
35     
36     /**
37      * Static method to destroy all ServiceLifecycle objects within an
38      * Axis session.
39      */

40     static void destroySession(HttpSession JavaDoc session)
41     {
42         // Check for our marker so as not to do unneeded work
43
if (session.getAttribute(AxisHttpSession.AXIS_SESSION_MARKER) == null)
44             return;
45         
46         if (log.isDebugEnabled()) {
47             log.debug("Got destroySession event : " + session);
48         }
49         
50         Enumeration JavaDoc e = session.getAttributeNames();
51         while (e.hasMoreElements()) {
52             Object JavaDoc next = e.nextElement();
53             if (next instanceof ServiceLifecycle JavaDoc) {
54                 ((ServiceLifecycle JavaDoc)next).destroy();
55             }
56         }
57     }
58     
59     /** No-op for now */
60     public void sessionCreated(HttpSessionEvent JavaDoc event) {
61     }
62
63     /**
64      * Called when a session is destroyed by the servlet engine. We use
65      * the relevant HttpSession to look up an AxisHttpSession, and destroy
66      * all the appropriate objects stored therein.
67      *
68      * @param event the event descriptor passed in by the servlet engine
69      */

70     public void sessionDestroyed(HttpSessionEvent JavaDoc event) {
71         HttpSession JavaDoc session = event.getSession();
72         destroySession(session);
73     }
74 }
75
Popular Tags