jain sip processResponse()没有被调用

时间:2014-04-01 18:46:38

标签: java sip jain-sip

我尝试使用JAIN SIP API发送SIP注册请求。我已经在类中实现了javax.sip.SipListener,我的程序成功发送了请求,甚至我从sip服务器获得了401未经授权的响应。我已经使用wireshark验证了这一点。但 processResponse()没有被调用。我在processResponse()中使用了System.out.Println(“响应响应”)来验证它是否被调用而不是。任何人都可以帮我解释为什么会这样。我已经烧了很多头,但却无法理解。 我在下面粘贴了我的代码。

公共类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) {

}

}

1 个答案:

答案 0 :(得分:1)

你有这样的地方的addSipListener()吗?

sipProvider.addSipListener(listener);

这是回调起作用的原因。在这种情况下,侦听器是CoreEngine实例,因为它实现了回调接口。