JAIN SIP 1.2とNIST実装を使用して簡単なSIPアプリケーションを構築しようとしています。私は私のIDEとしてEclipseでJavaSE1.7を使用しています。 問題:SipStackオブジェクトを構築しようとすると、javax.sip.PeerUnavailableExceptionが発生します。JAIN SIP APIとNIST実装を使用した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);
}
}
}
マイ問題のクラス(IはSIPスタックオブジェクトを構築れるから1):
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:[email protected]");
Address contactAddress = myAddressFactory.createAddress("sip:[email protected]");
// 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("[email protected]");
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
}
}
コンソール出力:
Creating ExampleListener... Creating SipStack... javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set. at javax.sip.SipFactory.createStack(SipFactory.java:324) at javax.sip.SipFactory.createSipStack(SipFactory.java:152) at net.bezeqint.sip.enp.ExampleListener.(ExampleListener.java:41) at net.bezeqint.sip.enp.ListenerMain.main(ListenerMain.java:9) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at javax.sip.SipFactory.createStack(SipFactory.java:314) ... 3 more Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Priority at gov.nist.javax.sip.SipStackImpl.(SipStackImpl.java:387) ... 8 more Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 9 more
I mySipFactory.createSipStack()
で使用されているパス名をダブルチェックし、ビルドパスに適切にインポートされていることを確認してください。
javax.sip.PeerUnavailableExceptionの問題点は何ですか?
解決済み!私は 'org.apache.log4j'パッケージをインポートしなければなりませんでした。これがトリックでした。 –