Author: tmjee
Date: Sat Jun 24 09:36:59 2006
New Revision: 416935

URL: http://svn.apache.org/viewvc?rev=416935&view=rev
Log:
WW-1351
  - added a SessionListener for Chat showcase example to do clean up
    when session expires


Added:
    
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java
   (with props)
Modified:
    struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml

Added: 
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java?rev=416935&view=auto
==============================================================================
--- 
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java
 (added)
+++ 
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java
 Sat Jun 24 09:36:59 2006
@@ -0,0 +1,31 @@
+package org.apache.struts.action2.showcase.chat;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class ChatSessionListener implements HttpSessionListener {
+
+       private static final Log _log = 
LogFactory.getLog(ChatSessionListener.class);
+       
+       public void sessionCreated(HttpSessionEvent event) {
+       }
+
+       public void sessionDestroyed(HttpSessionEvent event) {
+               HttpSession session = event.getSession();
+               WebApplicationContext context = 
WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
+               if (context != null) {
+                       User user = (User) 
session.getAttribute(ChatInterceptor.CHAT_USER_SESSION_KEY);
+                       ChatService service = (ChatService) 
context.getBean("chatService");
+                       service.logout(user.getName());
+                       
+                       _log.info("session expired, logged user 
["+user.getName()+"] out");
+               }
+       }
+
+}

Propchange: 
struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/chat/ChatSessionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml?rev=416935&r1=416934&r2=416935&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml 
(original)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml Sat Jun 
24 09:36:59 2006
@@ -2,7 +2,7 @@
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
 <web-app>
 
-    <display-name>WebWork Showcase Application</display-name>
+    <display-name>SAF2 Showcase Application</display-name>
 
        
     <filter>
@@ -46,6 +46,13 @@
         <listener-class>
           org.apache.myfaces.webapp.StartupServletContextListener
         </listener-class>
+    </listener>
+    
+    <!-- Chat Example in Showcase -->
+    <listener>
+       <listener-class>
+         org.apache.struts.action2.showcase.chat.ChatSessionListener
+       </listener-class>
     </listener>
        
     <!-- SNIPPET START: dwr -->


Reply via email to