Johanan Liebermann Johanan Liebermann - 4 years ago 172
Java Question

PeerUnavailableException using JAIN SIP API and the NIST implementation

I'm trying to build a simple SIP application using JAIN SIP 1.2 and the NIST implementation. I'm using JavaSE1.7 with Eclipse as my IDE.
The problem: I am getting javax.sip.PeerUnavailableException when trying to construct a SipStack object.

My main class:

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) {

My problematic class (the one from which I construct the SIP Stack object):

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.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();

// 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();
// test
// myProperties.setProperty("javax.sip.IP_ADDRESS","");

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);


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

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

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

MaxForwardsHeader myMaxForwardsHeader =

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);

// print the message


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


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


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


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


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


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


The console output:

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(
at javax.sip.SipFactory.createSipStack(
at net.bezeqint.sip.enp.ExampleListener.(
at net.bezeqint.sip.enp.ListenerMain.main(
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(
... 3 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Priority
at gov.nist.javax.sip.SipStackImpl.(
... 8 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
at$ Source)
at$ Source)
at Method)
at 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 have double checked the path name used by
and made sure it is properly imported to my build path.

What's the problem with the javax.sip.PeerUnavailableException?

Answer Source

Solved! I had to import the org.apache.log4j package and this did the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download