简体   繁体   English

Java SIP Servlet,如何发送REFER消息

[英]Java SIP Servlets, how to send REFER message

I need to implement next flow using SIP servlets: 我需要使用SIP servlet实现下一个流程:

1) My SIP Servlet should catch INVITE message 2) Look on SIP TO header, and if it match by some pattern I need comeback REFER message. 1)我的SIP Servlet应该捕获INVITE消息2)查看SIP TO标头,如果它与某些模式匹配,我需要复出REFER消息。

I google it, and found this manual (Basic Transfer): www.dialogic.com/webhelp/IMG1010/10.5.1/WebHelp/sip_rfr_calltrans.htm 我在Google上进行了搜索,并找到了本手册(基本传输):www.dialogic.com/webhelp/IMG1010/10.5.1/WebHelp/sip_rfr_calltrans.htm

As I understood correctly, this flow looks like bellow: 1) userA send INVITE message to SIP App 2) SIP App should send 200 OK back 3) UserA sending ACK message 4) SIP App send REFER message to UserA 5) UserA should send back 202Accepted and than NOTIFY 按照我的理解,该流程如下所示:1)userA向SIP应用发送邀请消息2)SIP应用应向发送200 OK回送3)用户A发送ACK消息4)SIP应用向用户A发送参考消息5)用户A应回发送202接受并且比通知

My enviroment: 我的环境:

1) mss-2.0.0.FINAL-jboss-as-7.1.2.Final as SIP PROXY Server 127.0.0.1:5080 1)mss-2.0.0.FINAL-jboss-as-7.1.2.Final作为SIP PROXY Server 127.0.0.1:5080

2) user3@127.0.0.1:5060 --- MicroSIP ( http://www.microsip.org/ ) 2)user3@127.0.0.1:5060 --- MicroSIP( http://www.microsip.org/

3) user2@127.0.0.1:5090 --- Zoiper_Free_2.41 3)user2@127.0.0.1:5090 --- Zoiper_Free_2.41

DAR File: DAR文件:

INVITE:("org.call.forwarding.CallForward","DAR:From","ORIGINATING","","NO_ROUTE", "0") 邀请:(“ org.call.forwarding.CallForward”,“ DAR:From”,“ ORIGINATING”,“”,“ NO_ROUTE”,“ 0”)

REGISTER:("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”)

OPTIONS:("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") 通知:(“ org.call.forwarding.CallForward”,“ DAR:From”,“ ORIGINATING”,“”,“ NO_ROUTE”,“ 0”)

REFER:("org.call.forwarding.CallForward", "DAR:From", "ORIGINATING", "", "NO_ROUTE", "0") 参考:(“ org.call.forwarding.CallForward”,“ DAR:From”,“ ORIGINATING”,“”,“ NO_ROUTE”,“ 0”)

From user3@127.0.0.1 I calling to refuser@127.0.0.1 从user3@127.0.0.1我打电话到拒绝者@ 127.0.0.1

So my source code looks like bellow: 1) Catching INVITE package and make 200 OK response: 因此,我的源代码如下所示:1)捕获INVITE包并做出200 OK响应:

@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

And my response: 200 OK Respnose like bellow: 我的回应是:200 OK像下面这样喘息:

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

Then I trying to process ACK package and generate REFER package: 然后,我尝试处理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

And my REFER package: 和我的参考包:

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

Then I see at log file TRYING message: 然后我在日志文件TRYING消息中看到:

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

And after ~30 secs I see that Microsip show "Not Acceptable" message: 约30秒后,我看到Microsip显示“ Not Acceptable”消息:

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

Can any body explaine: whats wrong with this guy??? 任何人都可以解释:这家伙怎么了??? Also another point that blow my brain: in some cases after sending 200 OK message (when I processed INVITE) I immediatly recive BYE message before ACK... Why its happens? 另一个让我震惊的地方是:在某些情况下,发送200 OK消息后(当我处理INVITE时),我在ACK之前立即收到BYE消息...为什么会发生?

It looks like in your REFER header that your Contact and CallID does not link up with your original ACK and 200OK messages. 在您的REFER标头中,您的Contact和CallID似乎没有与原始ACK和200OK消息链接。 So that's why you are getting a 100 Trying eventually because there is no outstanding message waiting for any sort of response. 这就是为什么您最终获得100次尝试的原因,因为没有等待任何响应的未完成消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM