我目前正在用sip开发一个通信系统,使用mobicents (tomcat上的sip-servlet实现)作为基础。我尝试实现了一个Notification-Service,UAs可以通过Notify时不时地订阅以获取状态信息。
问题:现在我在使用相同的Call-ID创建NOTIFY时遇到了问题,因为我不知道如何告诉servlet容器新请求属于当前对话。这是我尝试测试的内容:
public void doSubscribe(SipServletRequest request){
try{
//Get Session
SipApplicationSession session = request.getApplicationSession();
//Send response
SipServletResponse response = request.createResponse(SipServletResponse.SC_OK);
response.setExpires(600);
response.setHeader("Event", "buddylist");
response.send();
//Send notify (same call-id!!!)
Address serverAddress = this.sipFactory.createAddress("sip:server@test.com");
SipServletRequest newRequest = sipFactory.createRequest(session, "NOTIFY", serverAddress, request.getFrom());
newRequest.setHeader("Subscription-State", "active;expires=600");
newRequest.setHeader("Event", "buddylist");
newRequest.send();
} catch(Exception e){
e.printStackTrace();
}
}我原以为添加相同的会话就能完成这项工作,但事实并非如此。有谁知道怎么做才对吗?
发布于 2013-03-20 00:59:30
它花了相当长的时间,但我自己弄明白了。似乎我误解了通过SipFactory结合SipApplicationSession创建新请求。
我目前的观点(希望这次是正确的):SipFactory用于创建一个完整的新对话框的初始请求,并且仅用于新对话框。而SipApplicationSession只是一个容器,它存储每个新会话的会话对象。这意味着,上面的代码在SipApplicationSession-Container中创建了第二个SipSession,它独立于由传入的SUBSCRIBE-Request创建的SipSession!要在现有的Dialog中创建请求,您必须使用SipSession对象本身:
public void doSubscribe(SipServletRequest request){
try{
//Get !!!SipSession
SipSession sipSession = request.getSession();
//Send response
SipServletResponse response = request.createResponse(SipServletResponse.SC_OK);
response.setExpires(600);
response.setHeader("Event", "buddylist");
response.send();
//Send notify (same call-id!!!)
SipServletRequest newRequest = sipSession.createRequest("NOTIFY");
newRequest.setHeader("Subscription-State", "active;expires=600");
newRequest.setHeader("Event", "buddylist");
newRequest.send();
} catch(Exception e){
e.printStackTrace();
}
}最终,解决方案很简单。但帮助您理解此类内容的示例或文档较少。因此,我希望这能帮助每一个和我一样面临同样问题的人。
https://stackoverflow.com/questions/15454522
复制相似问题