我使用jain sip库创建了一个sip客户端。我可以注册客户端,这里是来自sip服务器的respose
31-May-2015 19:00:14.257 [CM504001]: Endpoint Extn:401: new contact is registered. Contact(s): [sip:401@192.168.1.3:5080 / 401]
现在,当我点击通话按钮时,我会收到服务器的响应。
31-May-2015 19:05:18.118 [CM504002]: Endpoint Extn:401: a contact is unregistered. Contact(s): []
31-May-2015 19:01:04.867 Leg L:1.1[Unknown:] is terminated: Cause: BYE from PBX
31-May-2015 19:01:04.812 [CM502001]: Source info: From: <sip:401@192.168.1.3:5080>;tag=Tzt0ZEP92; To: <sip:400>
31-May-2015 19:01:04.812 [CM503013]: Call(C:1): Incoming call rejected, caller is unknown; msg=Ivite-IN Recv Req INVITE from 192.168.1.3:5080 tid=-343937-0429701b5f2f8b0122a365a56ac5d974 Call-ID=c0335e9c736e5785826955de9f0b6ae7@192.168.1.3:
INVITE sip:400 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.3:5080;rport=5080;branch=z9hG4bK-343937-0429701b5f2f8b0122a365a56ac5d974
Max-Forwards: 70
Route: <sip:192.168.1.7:5060;transport=udp;lr>
Contact: <sip:401@192.168.1.3:5080>
To: <sip:400>
From: <sip:401@192.168.1.3:5080>;tag=Tzt0ZEP92
Call-ID: c0335e9c736e5785826955de9f0b6ae7@192.168.1.3
CSeq: 2 INVITE
Call-Info: <http://www.antd.nist.gov>
Content-Type: application/sdp
Proxy-Authorization: Digest username="401",realm="3CXPhoneSystem",nonce="414d535c0b7b9a9497:e49c5068970045631f39bac52ed74673",uri="sip:400",response="6e376a0d4dc10ffdc584d3b697aadb0c",algorithm=MD5
Supported: replaces, outbound
Content-Length: 246
31-May-2015 19:01:04.343 [CM500002]: Unidentified incoming call. Review INVITE and adjust source identification:
Invite-UNK Recv Req INVITE from 192.168.1.3:5080 tid=-343937-fc99c27fff992fb02c73b014c7b6a23d Call-ID=c0335e9c736e5785826955de9f0b6ae7@192.168.1.3:
INVITE sip:400 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.3:5080;rport=5080;branch=z9hG4bK-343937-fc99c27fff992fb02c73b014c7b6a23d
Max-Forwards: 70
Route: <sip:192.168.1.7:5060;transport=udp;lr>
Contact: <sip:401@192.168.1.3:5080>
To: <sip:400>
From: <sip:401@192.168.1.3:5080>;tag=Tzt0ZEP92
Call-ID: c0335e9c736e5785826955de9f0b6ae7@192.168.1.3
CSeq: 1 INVITE
Call-Info: <http://www.antd.nist.gov>
Content-Type: application/sdp
Supported: replaces, outbound
Content-Length: 246
负责处理响应的部分代码如下
public void processResponse(ResponseEvent arg0) {
Response response = (Response) arg0.getResponse();
System.out.println(response.getStatusCode());
Dialog responseDialog = null;
ClientTransaction tid = arg0.getClientTransaction();
if (tid != null) {
responseDialog = tid.getDialog();
} else {
responseDialog = arg0.getDialog();
}
CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
if (response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED
|| response.getStatusCode() == Response.UNAUTHORIZED) {
AuthenticationHelper authenticationHelper = ((SipStackExt) sipStack)
.getAuthenticationHelper(
new AccountManagerImpl(sipProfile.getSipUserName(),
sipProfile.getRemoteIp(), sipProfile
.getSipPassword()), headerFactory);
try {
ClientTransaction inviteTid = authenticationHelper
.handleChallenge(response, tid, sipProvider, 5, true);
inviteTid.sendRequest();
} catch (NullPointerException e) {
System.out.println("a: null error");
e.printStackTrace();
} catch (SipException e) {
System.out.println("b: null error");
e.printStackTrace();
}
} else if (response.getStatusCode() == Response.OK) {
if (cseq.getMethod().equals(Request.INVITE)) {
System.out.println("Dialog after 200 OK " + dialog);
System.out.println("c: invite " + dialog);
try {
Request ackRequest = responseDialog.createAck(cseq
.getSeqNumber());
System.out.println("Sending ACK");
responseDialog.sendAck(ackRequest);
byte[] rawContent = response.getRawContent();
String sdpContent = new String(rawContent, "UTF-8");
SDPAnnounceParser parser = new SDPAnnounceParser(sdpContent);
SessionDescriptionImpl sessiondescription = parser.parse();
MediaDescription incomingMediaDescriptor = (MediaDescription) sessiondescription
.getMediaDescriptions(false).get(0);
int rtpPort = incomingMediaDescriptor.getMedia()
.getMediaPort();
dispatchSipEvent(new SipEvent(this,
SipEventType.CALL_CONNECTED, "", "", rtpPort));
} catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (SipException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (SdpException e) {
e.printStackTrace();
}
} else if (cseq.getMethod().equals(Request.CANCEL)) {
if (dialog.getState() == DialogState.CONFIRMED) {
// oops cancel went in too late. Need to hang up the
// dialog.
System.out
.println("Sending BYE -- cancel went in too late !!");
Request byeRequest = null;
try {
byeRequest = dialog.createRequest(Request.BYE);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ClientTransaction ct = null;
try {
ct = sipProvider.getNewClientTransaction(byeRequest);
} catch (TransactionUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
dialog.sendRequest(ct);
} catch (TransactionDoesNotExistException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} else if (response.getStatusCode() == Response.DECLINE) {
System.out.println("CALL DECLINED");
dispatchSipEvent(new SipEvent(this, SipEventType.DECLINED, "", ""));
} else if (response.getStatusCode() == Response.NOT_FOUND) {
System.out.println("NOT FOUND");
} else if (response.getStatusCode() == Response.ACCEPTED) {
System.out.println("ACCEPTED");
} else if (response.getStatusCode() == Response.BUSY_HERE) {
System.out.println("BUSY");
dispatchSipEvent(new SipEvent(this, SipEventType.BUSY_HERE, "", ""));
} else if (response.getStatusCode() == Response.SERVICE_UNAVAILABLE) {
System.out.println("BUSY");
dispatchSipEvent(new SipEvent(this,
SipEventType.SERVICE_UNAVAILABLE, "", ""));
}
}
我一直在努力让这件事工作但仍然没有运气。请帮忙。