简体   繁体   中英

PeerUnavailableException using JAIN SIP API on Android

I'm trying to build SIP application using JAIN SIP 1.2 and the NIST implementation on android.

I have rebuilt jain-sip-api-1.2.jar and jain-sip-ri-1.2.1111.jar from source, and renamed javax -> jain_javax and gov.nist.javax -> jain_gov.nist.jain_javax . I tested the jar files on textclient example on standard java without problem. However, when I run it on Android I still get the error:

"The Peer SIP Stack: jain_gov.nist.jain_javax.sip.SipstackImpl could not be instantiated. Ensure the Path Name has been set".

Did I miss anything here?

It is not sufficient to rename the packages. JAIN-SIP has internal references to some classes by their original package name "gov.nist". You should also double check all your code to rename any "gov.nist" references such as the prefix for the stack classes.

Android has built-in an older version of JAIN-SIP which is taking over some of the existing references to those "gov.nist" classes. It's not an exported API, so not quite obvious. That's why it may behave differently on desktop machines. Post you code and full error messages/debug logs if you need more help.

Sovled. Jain Sip is using log4i-1.2.x.jar which does not work properly on Android. There are lots of discussion on Internet how to make log4j working on Android but none of them works for me. I have removed all log4j related code from Jain Sip source and now the sip stack is working properly on Android.

I am using JAIN-SIP-1-2-164. Here is the app code:

import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.text.ParseException;
import java.util.*;
import android.os.Handler;

import jain_javax.sip.*;
import jain_javax.sip.address.*;
import jain_javax.sip.header.*;
import jain_javax.sip.message.*;

public class SipLayer implements SipListener {

private SipStack sipStack;
private SipFactory sipFactory;
private Properties properties;
private String local_ip;    
int listen_port;            

/** Here we initialize the SIP stack. */
public SipLayer(int listen_port) {
    try {   
    setUsername(username);
    this.local_ip = InetAddress.getLocalHost().getHostAddress();;
    this.listen_port = listen_port;     
    // Create the SIP factory and set the path name.
    this.sipFactory = SipFactory.getInstance();
    this.sipFactory.setPathName("jain_gov.nist");   
    // Create and set the SIP stack properties.
    this.properties = new Properties();
    this.properties.setProperty("jain_javax.sip.STACK_NAME", "stack");
    this.properties.setProperty("jain_javax.sip.IP_ADDRESS", local_ip);
    if(proxy != null) 
        this.properties.setProperty("jain_javax.sip.OUTBOUND_PROXY", proxy + ':' + server_port + '/' + protocol);

    //DEBUGGING: Information will go to files textclient.log and textclientdebug.log
    this.properties.setProperty("jain_gov.nist.javax.sip.TRACE_LEVEL", "32");
    // this.properties.setProperty("jain_gov.nist.javax.sip.SERVER_LOG", "textclient.txt");
    // this.properties.setProperty("jain_gov.nist.javax.sip.DEBUG_LOG", "textclientdebug.log");

    // Create the SIP stack.
    this.sipStack = this.sipFactory.createSipStack(properties);
  }
  catch (Exception e) {       
    msgProc.processError("SipLayer failed: " + e.getMessage() + "\n");
  }
    }
}

Same code runs ok on java on a windows machine, but android emulator I got above mentioned error message.

I found that it failed in following Jain SIP 1.2 routine at "SipStack sipStack = (SipStack) sipStackConstructor.newInstance(conArgs);"

private SipStack createStack(Properties properties)
        throws PeerUnavailableException {
    try {
        // create parameters argument to identify constructor
        Class[] paramTypes = new Class[1];
        paramTypes[0] = Class.forName("java.util.Properties");
        // get constructor of SipStack in order to instantiate
        Constructor sipStackConstructor = Class.forName(
                getPathName() + ".jain_javax.sip.SipStackImpl").getConstructor(
                paramTypes);
        // Wrap properties object in order to pass to constructor of
        // SipSatck
        Object[] conArgs = new Object[1];
        conArgs[0] = properties;
        // Creates a new instance of SipStack Class with the supplied
        // properties.
        SipStack  sipStack = (SipStack) sipStackConstructor.newInstance(conArgs);
        sipStackList.add(sipStack);
        String name = properties.getProperty("jain_javax.sip.STACK_NAME");
        this.sipStackByName.put(name, sipStack);
                    return sipStack;
    } catch (Exception e) {
        String errmsg = "The Peer SIP Stack: "
                + getPathName()
                + ".jain_javax.sip.SipStackImpl"
                + " could not be instantiated. Ensure the Path Name has been set.";
        throw new PeerUnavailableException(errmsg, e);
    }
}

Any suggestion or how to debug further?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM