我需要使用SIP servlet实现下一个流程:
1)我的SIP Servlet应该捕获INVITE消息2)查看SIP TO header,如果它通过某种模式匹配,我需要comeback REFER消息。
我在谷歌上搜索了一下,找到了这本手册(基本传输):www.dialogic.com/webhelp/IMG1010/10.5.1/WebHelp/sip_rfr_calltrans.htm
据我正确理解,此流程如下: 1) userA向SIP应用发送INVITE消息2) SIP应用应发送200OK返回3) UserA发送确认消息4) SIP应用向UserA发送REFER消息5) UserA应发送回202接受并通知
我的环境:
1) mss-2.0.0.FINAL-jboss- as -7.1.2最终作为SIP代理服务器127.0.0.1:5080
2) user3@127.0.0.1:5060 - MicroSIP (http://www.microsip.org/)
3) user2@127.0.0.1:5090 - Zoiper_Free_2.41
DAR文件:
INVITE:("org.call.forwarding.CallForward","DAR:From","ORIGINATING","","NO_ROUTE","0")
寄存器:(“org.call.forwarding.CallForward”,"DAR:From","ORIGINATING","","NO_ROUTE","0")
SUBSCRIBE:("org.call.forwarding.CallForward","DAR:From","ORIGINATING","","NO_ROUTE","0")
选项:(“org.call.forwarding.CallForward”,"DAR:From","ORIGINATING","","NO_ROUTE","0")
NOTIFY:("org.call.forwarding.CallForward","DAR:From","ORIGINATING","","NO_ROUTE","0")
REFER:("org.call.forwarding.CallForward","DAR:From","ORIGINATING","","NO_ROUTE","0")
从user3@127.0.0.1我调用到refuser@127.0.0.1
所以我的源码如下: 1)捕获INVITE包并做出200OK响应:
@Override
protected void doInvite(SipServletRequest request) throws Exception {
// Pattern match logic ommited
SipServletResponse response = request.createResponse(SipServletResponse.SC_OK);
String str = response.toString();
response.send()
}
INVITE sip:refuser@127.0.0.1:5080 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport=5060;branch=z9hG4bKPjb1570e34df4c442093af6fb2fa238667;received=127.0.0.1
Max-Forwards: 70
From: "user3" <sip:user3@127.0.0.1>;tag=87be8901c4e242fbb5c696d90d0ec068
To: <sip:refuser@127.0.0.1>
Contact: "user3" <sip:user3@127.0.0.1:5060;ob>
Call-ID: 983d9572c4a541d49566699b3edec1e0
CSeq: 22256 INVITE
Allow: PRACK,INVITE,ACK,BYE,CANCEL,UPDATE,INFO,SUBSCRIBE,NOTIFY,REFER,MESSAGE,OPTIONS
Supported: replaces,100rel,timer,norefersub
Session-Expires: 1800
Min-SE: 90
User-Agent: MicroSIP/3.3.21
Content-Type: application/sdp
Content-Length: 673我的回答是:200OK回复,如下所示:
SIP/2.0 200 OK
To: <sip:refuser@127.0.0.1>;tag=25395207_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
Via: SIP/2.0/UDP 192.168.0.17:5060;rport=5060;branch=z9hG4bKPjb1570e34df4c442093af6fb2fa238667;received=127.0.0.1
CSeq: 22256 INVITE
Call-ID: 983d9572c4a541d49566699b3edec1e0
From: "user3" <sip:user3@127.0.0.1>;tag=87be8901c4e242fbb5c696d90d0ec068
Contact: <sip:127.0.0.1:5080>
Content-Length: 0然后我尝试处理ACK包并生成REFER包:
@Override
protected void doAck(SipServletRequest request) throws ServletException, IOException {
String ack = request.toString();
logger.info("Got ASK!!!: " + request.toString());
SipFactory sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY);
SipApplicationSession appSession = request.getApplicationSession();
SipServletRequest refer = sipFactory.createRequest(appSession, "REFER",
sipFactory.createURI("sip:user@127.0.0.1:5080"), // from sipFactory.createURI("sip:user2@127.0.0.1:5090")); // to
refer.addHeader("Refer-To", "sip:user3@127.0.0.1:5080");
refer.addHeader("Referred-By", "sip:user@127.0.0.1:5080");
logger.info("!!!!!!!!!!!THIS IS REFER: \n" + refer.toString());
String strRefer = refer.toString();
refer.send();
}
ACK sip:127.0.0.1:5080 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport=5060;branch=z9hG4bKPje03842cfb4104d379db989f2d77a871a;received=127.0.0.1
Max-Forwards: 70
From: "user3" <sip:user3@127.0.0.1>;tag=87be8901c4e242fbb5c696d90d0ec068
To: <sip:refuser@127.0.0.1>;tag=25395207_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
Call-ID: 983d9572c4a541d49566699b3edec1e0
CSeq: 22256 ACK
Content-Length: 0和我的REFER包:
REFER sip:user2@127.0.0.1:5090 SIP/2.0
Call-ID: ca002d9261fe165c0a4eaedc99ead2c7@127.0.0.1
CSeq: 1 REFER
From: <sip:user@127.0.0.1:5080>;tag=14387494_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
To: <sip:user2@127.0.0.1:5090>
Max-Forwards: 70
Contact: <sip:user@127.0.0.1:5080>
Refer-To: <sip:user3@127.0.0.1:5080>
Referred-By: <sip:user@127.0.0.1:5080>
Content-Length: 0然后我在日志文件中看到一条尝试消息:
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 127.0.0.1:5080;branch=z9hG4bK8479416b-da5c-4dca-baef- f9b7db279b9e_da1be872_1872624593941
To: <sip:user2@127.0.0.1:5090>
From: <sip:user@127.0.0.1:5080>;tag=14387494_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
Call-ID: ca002d9261fe165c0a4eaedc99ead2c7@127.0.0.1
CSeq: 1 REFER
Content-Length: 0大约30秒后,我看到Microsip显示“不可接受”消息:
SIP/2.0 408 Request timeout
To: <sip:user2@127.0.0.1:5090>;tag=37903989_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
Via: SIP/2.0/UDP 127.0.0.1:5080;branch=z9hG4bK8479416b-da5c-4dca-baef-f9b7db279b9e_da1be872_1872624593941
CSeq: 1 REFER
Call-ID: ca002d9261fe165c0a4eaedc99ead2c7@127.0.0.1
From: <sip:user@127.0.0.1:5080>;tag=14387494_da1be872_8479416b-da5c-4dca-baef-f9b7db279b9e
Contact: <sip:127.0.0.1:5080>
Content-Length: 0任何人都可以解释:这家伙怎么了?还有另一个让我头疼的地方:在某些情况下,在发送200OK消息(当我处理INVITE时)之后,我会在ACK之前立即收到BYE消息……为什么会发生这种情况?
发布于 2013-10-31 10:38:07
在您的REFER头中,您的联系人和CallID看起来没有链接到您的原始确认和200OK消息。这就是为什么你最终会得到100分,因为没有任何未处理的消息等待任何类型的响应。
https://stackoverflow.com/questions/19591124
复制相似问题