我正在尝试使用JAIN SIP API发送SIP注册请求。我在类中实现了javax.sip.SipListener,我的程序成功地发送了请求,甚至我从sip服务器得到了一个401未经授权的响应。我已经用wireshark验证了这一点。但是
未调用processResponse()。我在processResponse()中使用System.out.Println(“response received”)来验证它是否被调用。有人能帮我弄清楚为什么会发生这种事吗。我的头被烧了很多次,都想不出来。
我已将代码粘贴到下面。
公共类CoreEngine实现javax.sip.SipListener{
//public localip=Inet4Address.getLocalHost().getHostAddress();
SipFactory sipFactory = null;
SipStack sipStack = null;
Properties properties;
HeaderFactory headerFactory;
AddressFactory addressFactory;
MessageFactory messageFactory;
SipProvider sipProvider ;
ListeningPoint lp;
ContactHeader contactHeader;
ClientTransaction inviteTid;
public void init() throws Exception {
sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist");
properties = new Properties();
properties.setProperty("javax.sip.STACK_NAME", "Sip_Test");
// Create SipStack object
sipStack = sipFactory.createSipStack(properties);
headerFactory = sipFactory.createHeaderFactory();
addressFactory = sipFactory.createAddressFactory();
messageFactory = sipFactory.createMessageFactory();
lp = sipStack.createListeningPoint("192.168.0.205",
5060, ListeningPoint.UDP);
sipProvider = sipStack.createSipProvider(lp);
}
public void register() throws Exception {
String fromName = "223344";
String fromSipAddress = "173.194.117.84";
String toSipAddress = "173.194.117.84";
String toUser = "223344";
SipURI fromAddress = addressFactory.createSipURI(fromName,
fromSipAddress);
System.out.println("sipuri fromaddress"+fromAddress);
Address fromNameAddress = addressFactory.createAddress(fromAddress);
FromHeader fromHeader = headerFactory.createFromHeader(
fromNameAddress, null);
SipURI toAddress = addressFactory
.createSipURI(toUser, toSipAddress);
Address toNameAddress = addressFactory.createAddress(toAddress);
ToHeader toHeader = headerFactory.createToHeader(toNameAddress,
null);
URI requestURI = addressFactory.createURI(
"sip:" + "173.194.117.84");
List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
String ipAddress = lp.getIPAddress();
ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress,
lp.getPort(),
lp.getTransport(), null);
viaHeaders.add(viaHeader);
CallIdHeader callIdHeader = sipProvider.getNewCallId();
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L,
Request.REGISTER);
MaxForwardsHeader maxForwards = headerFactory
.createMaxForwardsHeader(70);
Request request = messageFactory.createRequest(requestURI,
Request.REGISTER, callIdHeader, cSeqHeader, fromHeader,
toHeader, viaHeaders, maxForwards);
SipURI contactURI = addressFactory.createSipURI(fromName, "173.194.117.84");
contactURI.setPort(sipProvider.getListeningPoint(lp.getTransport())
.getPort());
Address contactAddress = addressFactory.createAddress(contactURI);
contactHeader = headerFactory.createContactHeader(contactAddress);
request.addHeader(contactHeader);
Header extensionHeader = headerFactory.createHeader("Expires",
"120");
request.addHeader(extensionHeader);
System.out.println("request is"+ request);
inviteTid = sipProvider.getNewClientTransaction(request);
inviteTid.sendRequest();
}
public void processRequest(RequestEvent requestEvent) {
}
public void processResponse(ResponseEvent responseEvent) {
System.out.println("Response received");
System.out.println("response event"+ responseEvent.getResponse().getStatusCode());
}
public void processTimeout(TimeoutEvent timeoutEvent) {
}
public void processIOException(IOExceptionEvent exceptionEvent) {
}
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
}
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
}
}