3

我正在尝试使用 JAIN SIP 1.2 和 NIST 实现来构建一个简单的 SIP 应用程序。我使用 JavaSE1.7 和 Eclipse 作为我的 IDE。问题:尝试构造 SipStack 对象时出现 javax.sip.PeerUnavailableException。

我的主要课程:

package net.bezeqint.sip.enp;

public class ListenerMain {

    public static void main(String[] args) {

        try {
            System.out.println("Creating ExampleListener...");
            ExampleListener listener = new ExampleListener();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

我有问题的类(我从中构造 SIP Stack 对象的类):

package net.bezeqint.sip.enp;

import javax.sip.*;
import javax.sip.message.*;
import javax.sip.header.*;
import javax.sip.address.*;
import javax.sip.address.URI;

import java.net.*;
import java.util.*;

public class ExampleListener implements SipListener {

    private SipFactory mySipFactory;
    private SipStack mySipStack;
    private ListeningPoint myListeningPoint;
    private SipProvider mySipProvider;
    private MessageFactory myMessageFacory;
    private HeaderFactory myHeaderFactory;
    private AddressFactory myAddressFactory;
    private Properties myProperties;
    private String myIP;
    private int myPort = 5060;

    public ExampleListener() throws Exception {

        mySipFactory = SipFactory.getInstance();
        mySipFactory.setPathName("gov.nist");

        // create factories
        myMessageFacory = mySipFactory.createMessageFactory();
        myHeaderFactory = mySipFactory.createHeaderFactory();
        myAddressFactory = mySipFactory.createAddressFactory();
        // create a Properties object to pass as an argument to the createSipStack() method
        myProperties = new Properties();
        myProperties.setProperty("javax.sip.STACK_NAME","myStack");
        // test
        // myProperties.setProperty("javax.sip.IP_ADDRESS","192.168.1.1");

        System.out.println("Creating SipStack...");
        mySipStack = mySipFactory.createSipStack(myProperties);
        System.out.println("SipStack created!");

        // get our IP address to be used when creating the ListeningPoint
        myIP = InetAddress.getLocalHost().getHostAddress();

        myListeningPoint = mySipStack.createListeningPoint(myIP, myPort, "udp");

        mySipProvider = mySipStack.createSipProvider(myListeningPoint);

        mySipProvider.addSipListener(this);


        // begin building a request
        Address destAddress = myAddressFactory.createAddress("sip:registrar.ocean.com");
        Address addressOfRecord = myAddressFactory.createAddress("sip:peter@ocean.com");
        Address contactAddress = myAddressFactory.createAddress("sip:peter@169.254.153.60");

        // convert address to URI object
        URI myRequestURI = destAddress.getURI();

        // create headers
        ArrayList viaHeaders = new ArrayList();
        ViaHeader myViaHeader = myHeaderFactory.createViaHeader("Peterpc.ocean.com"
                , 5060, "udp", "z9hG4bKnashds7");
        viaHeaders.add(myViaHeader);

        MaxForwardsHeader myMaxForwardsHeader =
                myHeaderFactory.createMaxForwardsHeader(70);

        ToHeader myToHeader = myHeaderFactory.createToHeader(addressOfRecord, null);

        FromHeader myFromHeader = myHeaderFactory.createFromHeader(addressOfRecord, "456248");

        CallIdHeader myCallIDHeader = myHeaderFactory.createCallIdHeader("843817637684230@998sdasdh09");

        CSeqHeader myCseqHeader = myHeaderFactory.createCSeqHeader(1826, "REGISTER");

        // create message
        Request myRequest = myMessageFacory.createRequest(myRequestURI, "REGISTER", myCallIDHeader, myCseqHeader, myFromHeader, myToHeader, viaHeaders, myMaxForwardsHeader);

        // add missing headers
        ContactHeader myContactHeader = myHeaderFactory.createContactHeader(contactAddress);
        myRequest.addHeader(myContactHeader);

        // print the message
        System.out.println(myRequest);

    }

    @Override
    public void processDialogTerminated(DialogTerminatedEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processIOException(IOExceptionEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processRequest(RequestEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processResponse(ResponseEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processTimeout(TimeoutEvent arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processTransactionTerminated(TransactionTerminatedEvent arg0) {
        // TODO Auto-generated method stub

    }
}

控制台输出:

创建 ExampleListener... 创建 SipStack... javax.sip.PeerUnavailableException:对等 SIP 堆栈:gov.nist.javax.sip.SipStackImpl 无法实例化。确保已设置路径名称。在 javax.sip.SipFactory.createStack(SipFactory.java:324) 在 javax.sip.SipFactory.createSipStack(SipFactory.java:152) 在 net.bezeqint.sip.enp.ExampleListener.(ExampleListener.java:41) 在 net .bezeqint.sip.enp.ListenerMain.main(ListenerMain.java:9) 引起:java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source ) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 在 java.lang.reflect.Constructor。

我已经仔细检查了使用的路径名,mySipFactory.createSipStack()并确保它已正确导入到我的构建路径中。

javax.sip.PeerUnavailableException 有什么问题?

4

2 回答 2

7

解决了!我不得不导入org.apache.log4j包,这成功了。

于 2012-04-16T12:46:54.753 回答
2

当您使用 Maven 构建项目时,请确保您依赖于 jain-sip-api 和 jain-sip-ri。

于 2013-09-12T06:35:20.090 回答