Witam
Próbuje dodać listener sesji dla mojej usługi sieciowej pod Tomcat'em:
package ws;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
class SessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
try {
log("utworzono sesje: "+se.getSession().getId());
}catch(IOException e) {
}
}
public void sessionDestroyed(HttpSessionEvent se) {
try {
log("zakończono sesje: "+se.getSession().getId());
}catch(IOException e) {
}
}
private void log(String text) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter("c:\\log\\session.log",true));
writer.append(text+"\n");
writer.flush();
writer.close();
}
}
Niestety gdy dodaje listener do web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>XWS Secure Hello</display-name>
<description>Secured Hello</description>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<listener>
<listener-class>ws.SessionListener</listener-class>
</listener>
<servlet>
<servlet-name>XWSHello</servlet-name>
<display-name>>XWS Secure Hello</display-name>
<description>Secured Hello</description>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XWSHello</servlet-name>
<url-pattern>/shello</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
Wyskakuje mi błąd: Error listenerStart.
Sesje obługuje zgodnie z przykładem:
http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html