我正在尝试使用JAIN SIP 1.2和Android上的NIST实现构建SIP应用程序。
我已从源代码重建jain-sip-api-1.2.jar
和jain-sip-ri-1.2.1111.jar
,并重命名为javax -> jain_javax
和gov.nist.javax -> jain_gov.nist.jain_javax
。我在标准java上的textclient示例上测试了jar文件没有问题。但是,当我在Android上运行它时,我仍然会收到错误:
"The Peer SIP Stack: jain_gov.nist.jain_javax.sip.SipstackImpl could not be instantiated. Ensure the Path Name has been set".
我在这里错过了什么吗?
答案 0 :(得分:1)
重命名包是不够的。 JAIN-SIP通过其原始包名“gov.nist”对某些类进行内部引用。您还应该仔细检查所有代码,以重命名任何“gov.nist”引用,例如堆栈类的前缀。
Android内置了旧版本的JAIN-SIP,它正在接管对这些“gov.nist”类的一些现有引用。它不是导出的API,因此不太明显。这就是为什么它在台式机上可能表现不同的原因。如果您需要更多帮助,请发布代码和完整错误消息/调试日志。
答案 1 :(得分:1)
Sovled。 Jain Sip正在使用log4i-1.2.x.jar,它在Android上无法正常运行。关于如何让log4j在Android上工作的互联网上有很多讨论,但它们都不适用于我。我已从Jain Sip源中删除了所有与log4j相关的代码,现在sip堆栈在Android上正常运行。
答案 2 :(得分:0)
我正在使用JAIN-SIP-1-2-164。这是应用代码:
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");
}
}
}
相同的代码在Windows机器上的java上运行正常,但是android模拟器我得到了上面提到的错误消息。
我发现在“SipStack sipStack =(SipStack)sipStackConstructor.newInstance(conArgs);”
中遵循Jain SIP 1.2例程失败了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);
}
}
有任何建议或如何进一步调试?