为了使用servlet定时器,我必须使用TimerListener接口。当我部署我的应用程序时,我收到此错误:
java.lang.IllegalStateException: No TimerListener is configured.
我已在Sip部署描述符(sip.xml)的侦听器元素中声明了我的实现类:
<?xml version="1.0" encoding="UTF-8"?>
<sip-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jcp.org/xml/ns/sipservlet http://www.jcp.org/xml/ns/sipservlet/sip-app_1_1.xsd"
version="1.1">
<listener>
<listener-class>net.sip.psngn.NaerumPoliceSipServlet</listener-class>
</listener>
</sip-app>
错误发生在我创建servlet计时器时。有谁知道如何解决这个问题?提前致谢。
package net.sip.psngn;
import javax.servlet.sip.*;
import javax.servlet.ServletContext;
import java.sql.Time;
import javax.annotation.Resource;
import javax.persistence.*;
import javax.transaction.UserTransaction;
import javax.servlet.sip.annotation.SipListener;
@javax.servlet.sip.annotation.SipServlet
@SipListener
public class NaerumPoliceSipServlet extends SipServlet implements TimerListener {
private static final long serialVersionUID = 3978425801979081269L;
public String CSeq;
@PersistenceUnit
private EntityManagerFactory emf;
@Resource
private UserTransaction utx;
@Resource
TimerService timerservice;
/*
* Demonstrates extension with a new "REPUBLISH" method
*/
@Override
protected void doRequest(SipServletRequest reqfromclient) throws javax.servlet.ServletException, java.io.IOException {
if( reqfromclient.getMethod().equals("MESSAGE") ) {
String MsgContent = reqfromclient.getContent().toString();
System.out.println("The arrived message is " + MsgContent);
// Assign the callee URI
String URICallee = reqfromclient.getTo().getURI().toString();
String reqDomain = ((SipURI)reqfromclient.getTo().getURI()).getHost();
//Assign the caller URI
String URICaller = reqfromclient.getFrom().getURI().toString();
//Get the sequence of arriving MESSAGE
CSeq = reqfromclient.getHeader("CSeq");
System.out.println("Sequence number of the message "+CSeq);
// Get the application session of the message
SipApplicationSession sas = reqfromclient.getApplicationSession();
System.out.println("The app session is: " + sas);
// Create the timer with a timeout after 20 seconds
ServletTimer servlettimer = timerservice.createTimer(sas, 20000, false, "enough");
System.out.println("The Servlet Timer is created and delay is set to 20 seconds");
//Store the ID of the timer as an attribute of the SipApplicationSession
sas.setAttribute("TimerID", servlettimer.getId());
System.out.println("TimerID: " + servlettimer.getId());
// Access the stopwatch from the other class
StopwatchClass stwclass = new StopwatchClass();
//Get the message arrival time
Time time = new Time(System.currentTimeMillis());
}
}
public void timeout(ServletTimer servlettimer) {
if ("enough".equals(servlettimer.getInfo())) {
System.out.println(servlettimer.getApplicationSession());
}
}
}