2014-04-01 56 views
0

我試圖使用JAIN SIP API發送SIP註冊請求。我已經在類中實現了javax.sip.SipListener,並且我的程序成功發送了請求,甚至我從SIP服務器收到401未經授權的響應。我已經使用wireshark驗證了這一點。但是 processResponse()沒有被調用。我在processResponse()內部使用了一個System.out.Println(「response received」)來驗證它是否被調用,而不是它。任何人都可以幫我解釋爲何發生這種情況。我燒了很多頭,但無法弄清楚。 我在下面粘貼了我的代碼。jain sip processResponse()未被調用

公共類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

你有addSipListener()的地方也是這樣嗎?

sipProvider.addSipListener(listener);

這是什麼使得回調的工作。在你的情況下,偵聽器是CoreEngine實例,因爲它實現了回調接口。