public SipServerLayer(String ip, int port, SipMessageProcessor messageProcessor) throws PeerUnavailableException,
TransportNotSupportedException, InvalidArgumentException, ObjectInUseException, TooManyListenersException {
sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist");
Properties properties = new Properties();
properties.setProperty("javax.sip.STACK_NAME", "srymy-GB28181");
properties.setProperty("javax.sip.IP_ADDRESS", ip);
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log");
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log");
sipStack = sipFactory.createSipStack(properties);
headerFactory = sipFactory.createHeaderFactory();
addressFactory = sipFactory.createAddressFactory();
messageFactory = sipFactory.createMessageFactory();
tcp = sipStack.createListeningPoint(ip, port, "tcp");
udp = sipStack.createListeningPoint(ip, port, "udp");
createListeningPoint(ip,port);
this.messageProcessor = messageProcessor;
}
在创建SipStack时报错javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
经过调试发现
错误发生在源码中的这一行,经过测试,需要在maven.xml中加入日志相关依赖
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.26</version>
</dependency>
根据CHAT-GPT解释:这是一个Maven(或Gradle)依赖项,用于将Log4j API转换为SLF4J API。SLF4J(简单日志门面)是一个简单的日志记录API,允许开发人员使用各种日志记录实现,而无需更改其代码。
在某些情况下,应用程序使用Log4j作为其日志记录框架,而另一些应用程序使用SLF4J。log4j-over-slf4j 是一个依赖项,帮助您在应用程序中使用SLF4J API时保持对现有Log4j实现代码的兼容性。
该依赖项包含对log4j的绑定代码,将Log4j API调用路由到SLF4J API。您可以在您的代码中使用SLF4J API进行日志记录,而无需尝试直接使用Log4j API。
在项目中遇到这个问题,在此记录一下,