Java SIP Mobicents-如何在现有对话框中创建新请求?(相同的呼叫ID)
我目前正在使用sip开发一个通信系统,使用mobicents(tomcat上的SIPServlet实现)作为基础。我试着实现一个通知服务,UAs可以通过Notify随时订阅获取状态信息。正如我在RFC3265-“特定事件通知”中所读到的,订阅的通知消息必须具有相同的调用ID,因为它们属于订阅对话框 问题:现在我在创建具有相同调用ID的NOTIFY时遇到问题,因为我不知道如何告诉servlet容器新请求属于当前对话框。 这就是我尝试测试的内容:Java SIP Mobicents-如何在现有对话框中创建新请求?(相同的呼叫ID),java,sip,Java,Sip,我目前正在使用sip开发一个通信系统,使用mobicents(tomcat上的SIPServlet实现)作为基础。我试着实现一个通知服务,UAs可以通过Notify随时订阅获取状态信息。正如我在RFC3265-“特定事件通知”中所读到的,订阅的通知消息必须具有相同的调用ID,因为它们属于订阅对话框 问题:现在我在创建具有相同调用ID的NOTIFY时遇到问题,因为我不知道如何告诉servlet容器新请求属于当前对话框。 这就是我尝试测试的内容: public void doSubscribe(Si
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();
}
}
我原以为添加相同的会话就可以了,但事实并非如此。有人知道怎么做吗?花了相当长的时间,但我自己解决了。似乎我误解了通过SipFactory结合SipApplicationSession创建新请求 我目前的观点(希望这次是正确的): SipFactory用于创建完整新对话框的初始请求,并且仅用于新对话框。而SipApplicationSession只是一个为每个新会话存储会话对象的容器。 这意味着,上面的代码在SipApplicationSession容器中创建了第二个SipSession,它独立于由incomming SUBSCRIBE请求创建的SipSession! 要在现有对话框中创建请求,必须使用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();
}
}
最终解决方案很简单。但是很少有例子或文档能帮助你理解这样的东西。因此,我希望这能帮助每个人面对和我一样的问题。这花了不少时间,但我自己解决了。似乎我误解了通过SipFactory结合SipApplicationSession创建新请求 我目前的观点(希望这次是正确的): SipFactory用于创建完整新对话框的初始请求,并且仅用于新对话框。而SipApplicationSession只是一个为每个新会话存储会话对象的容器。 这意味着,上面的代码在SipApplicationSession容器中创建了第二个SipSession,它独立于由incomming SUBSCRIBE请求创建的SipSession! 要在现有对话框中创建请求,必须使用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();
}
}
最终解决方案很简单。但是很少有例子或文档能帮助你理解这样的东西。因此,我希望这能帮助每个人面对和我一样的问题