Browse Source
Conflicts: src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/InviteResponseProcessor.javapull/1/head

49 changed files with 461 additions and 343 deletions
@ -0,0 +1,21 @@ |
|||||
|
MIT License |
||||
|
|
||||
|
Copyright (c) 2020 swwhaha |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE. |
@ -1,250 +1,262 @@ |
|||||
package com.genersoft.iot.vmp.gb28181; |
package com.genersoft.iot.vmp.gb28181; |
||||
|
|
||||
import java.util.Properties; |
import java.text.ParseException; |
||||
|
import java.util.Properties; |
||||
import javax.annotation.PostConstruct; |
|
||||
import javax.sip.DialogTerminatedEvent; |
import javax.annotation.PostConstruct; |
||||
import javax.sip.IOExceptionEvent; |
import javax.sip.DialogTerminatedEvent; |
||||
import javax.sip.ListeningPoint; |
import javax.sip.IOExceptionEvent; |
||||
import javax.sip.RequestEvent; |
import javax.sip.ListeningPoint; |
||||
import javax.sip.ResponseEvent; |
import javax.sip.RequestEvent; |
||||
import javax.sip.ServerTransaction; |
import javax.sip.ResponseEvent; |
||||
import javax.sip.SipFactory; |
import javax.sip.ServerTransaction; |
||||
import javax.sip.SipListener; |
import javax.sip.SipFactory; |
||||
import javax.sip.SipProvider; |
import javax.sip.SipListener; |
||||
import javax.sip.SipStack; |
import javax.sip.SipProvider; |
||||
import javax.sip.TimeoutEvent; |
import javax.sip.SipStack; |
||||
import javax.sip.TransactionAlreadyExistsException; |
import javax.sip.TimeoutEvent; |
||||
import javax.sip.TransactionTerminatedEvent; |
import javax.sip.TransactionAlreadyExistsException; |
||||
import javax.sip.TransactionUnavailableException; |
import javax.sip.TransactionTerminatedEvent; |
||||
import javax.sip.address.AddressFactory; |
import javax.sip.TransactionUnavailableException; |
||||
import javax.sip.header.HeaderFactory; |
import javax.sip.address.AddressFactory; |
||||
import javax.sip.header.ViaHeader; |
import javax.sip.header.HeaderFactory; |
||||
import javax.sip.message.MessageFactory; |
import javax.sip.header.ViaHeader; |
||||
import javax.sip.message.Request; |
import javax.sip.message.MessageFactory; |
||||
import javax.sip.message.Response; |
import javax.sip.message.Request; |
||||
|
import javax.sip.message.Response; |
||||
import org.slf4j.Logger; |
|
||||
import org.slf4j.LoggerFactory; |
import org.slf4j.Logger; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
import com.genersoft.iot.vmp.conf.SipConfig; |
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory; |
import com.genersoft.iot.vmp.conf.SipConfig; |
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor; |
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory; |
||||
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor; |
||||
|
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
||||
import gov.nist.javax.sip.SipStackImpl; |
|
||||
|
import gov.nist.javax.sip.SipStackImpl; |
||||
@Component |
|
||||
public class SipLayer implements SipListener, Runnable { |
@Component |
||||
|
public class SipLayer implements SipListener, Runnable { |
||||
private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); |
|
||||
|
private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); |
||||
@Autowired |
|
||||
private SipConfig sipConfig; |
@Autowired |
||||
|
private SipConfig sipConfig; |
||||
private SipProvider tcpSipProvider; |
|
||||
|
private SipProvider tcpSipProvider; |
||||
private SipProvider udpSipProvider; |
|
||||
|
private SipProvider udpSipProvider; |
||||
@Autowired |
|
||||
private SIPProcessorFactory processorFactory; |
@Autowired |
||||
|
private SIPProcessorFactory processorFactory; |
||||
private SipStack sipStack; |
|
||||
|
private SipStack sipStack; |
||||
private AddressFactory addressFactory; |
|
||||
private HeaderFactory headerFactory; |
private AddressFactory addressFactory; |
||||
private MessageFactory messageFactory; |
private HeaderFactory headerFactory; |
||||
|
private MessageFactory messageFactory; |
||||
@PostConstruct |
|
||||
private void initSipServer() { |
@PostConstruct |
||||
Thread thread=new Thread(this); |
private void initSipServer() { |
||||
thread.setDaemon(true); |
Thread thread = new Thread(this); |
||||
thread.setName("sip server thread start"); |
thread.setDaemon(true); |
||||
thread.start(); |
thread.setName("sip server thread start"); |
||||
} |
thread.start(); |
||||
|
} |
||||
@Override |
|
||||
public void run() { |
@Override |
||||
SipFactory sipFactory = SipFactory.getInstance(); |
public void run() { |
||||
sipFactory.setPathName("gov.nist"); |
SipFactory sipFactory = SipFactory.getInstance(); |
||||
try { |
sipFactory.setPathName("gov.nist"); |
||||
headerFactory = sipFactory.createHeaderFactory(); |
try { |
||||
|
headerFactory = sipFactory.createHeaderFactory(); |
||||
addressFactory = sipFactory.createAddressFactory(); |
|
||||
messageFactory = sipFactory.createMessageFactory(); |
addressFactory = sipFactory.createAddressFactory(); |
||||
|
messageFactory = sipFactory.createMessageFactory(); |
||||
Properties properties = new Properties(); |
|
||||
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); |
Properties properties = new Properties(); |
||||
properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getSipIp()); |
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); |
||||
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false"); |
properties.setProperty("javax.sip.IP_ADDRESS", sipConfig.getSipIp()); |
||||
/** |
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false"); |
||||
* sip_server_log.log 和 sip_debug_log.log public static final int TRACE_NONE = |
/** |
||||
* 0; public static final int TRACE_MESSAGES = 16; public static final int |
* sip_server_log.log 和 sip_debug_log.log public static final int TRACE_NONE = |
||||
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32; |
* 0; public static final int TRACE_MESSAGES = 16; public static final int |
||||
*/ |
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32; |
||||
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.TRACE_LEVEL", "32"); |
||||
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log"); |
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log"); |
||||
sipStack = (SipStackImpl) sipFactory.createSipStack(properties); |
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log"); |
||||
|
sipStack = (SipStackImpl) sipFactory.createSipStack(properties); |
||||
startTcpListener(); |
|
||||
startUdpListener(); |
startTcpListener(); |
||||
} catch (Exception e) { |
startUdpListener(); |
||||
logger.error("Sip Server 启动失败! port {" + sipConfig.getSipPort() + "}"); |
} catch (Exception e) { |
||||
e.printStackTrace(); |
logger.error("Sip Server 启动失败! port {" + sipConfig.getSipPort() + "}"); |
||||
} |
e.printStackTrace(); |
||||
logger.info("Sip Server 启动成功 port {" + sipConfig.getSipPort() + "}"); |
} |
||||
} |
logger.info("Sip Server 启动成功 port {" + sipConfig.getSipPort() + "}"); |
||||
|
} |
||||
private void startTcpListener() throws Exception { |
|
||||
ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), "TCP"); |
private void startTcpListener() throws Exception { |
||||
tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint); |
ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), |
||||
tcpSipProvider.addSipListener(this); |
"TCP"); |
||||
} |
tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint); |
||||
|
tcpSipProvider.addSipListener(this); |
||||
private void startUdpListener() throws Exception { |
} |
||||
ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), "UDP"); |
|
||||
udpSipProvider = sipStack.createSipProvider(udpListeningPoint); |
private void startUdpListener() throws Exception { |
||||
udpSipProvider.addSipListener(this); |
ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), |
||||
} |
"UDP"); |
||||
|
udpSipProvider = sipStack.createSipProvider(udpListeningPoint); |
||||
/** |
udpSipProvider.addSipListener(this); |
||||
* SIP服务端接收消息的方法 Content 里面是GBK编码 This method is called by the SIP stack when a |
} |
||||
* new request arrives. |
|
||||
*/ |
/** |
||||
@Override |
* SIP服务端接收消息的方法 Content 里面是GBK编码 This method is called by the SIP stack when a |
||||
public void processRequest(RequestEvent evt) { |
* new request arrives. |
||||
ISIPRequestProcessor processor = processorFactory.createRequestProcessor(evt); |
*/ |
||||
processor.process(evt, this); |
@Override |
||||
} |
public void processRequest(RequestEvent evt) { |
||||
|
ISIPRequestProcessor processor = processorFactory.createRequestProcessor(evt); |
||||
@Override |
processor.process(evt, this); |
||||
public void processResponse(ResponseEvent evt) { |
} |
||||
Response response = evt.getResponse(); |
|
||||
int status = response.getStatusCode(); |
@Override |
||||
if ((status >= 200) && (status < 300)) { // Success!
|
public void processResponse(ResponseEvent evt) { |
||||
ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); |
Response response = evt.getResponse(); |
||||
processor.process(evt, this, sipConfig); |
int status = response.getStatusCode(); |
||||
} else { |
if ((status >= 200) && (status < 300)) { // Success!
|
||||
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getContent().toString()); |
ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); |
||||
} |
try { |
||||
// trying不会回复
|
processor.process(evt, this, sipConfig); |
||||
if (status == Response.TRYING) { |
} catch (ParseException e) { |
||||
|
// TODO Auto-generated catch block
|
||||
} |
e.printStackTrace(); |
||||
} |
} |
||||
|
// } else if (status == Response.TRYING) {
|
||||
/** |
// trying不会回复
|
||||
* <p> |
} else if ((status >= 100) && (status < 200)) { |
||||
* Title: processTimeout |
// 增加其它无需回复的响应,如101、180等
|
||||
* </p> |
} else { |
||||
* <p> |
logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/); |
||||
* Description: |
} |
||||
* </p> |
// trying不会回复
|
||||
* |
// if (status == Response.TRYING) {
|
||||
* @param timeoutEvent |
|
||||
*/ |
// }
|
||||
@Override |
} |
||||
public void processTimeout(TimeoutEvent timeoutEvent) { |
|
||||
// TODO Auto-generated method stub
|
/** |
||||
|
* <p> |
||||
} |
* Title: processTimeout |
||||
|
* </p> |
||||
/** |
* <p> |
||||
* <p> |
* Description: |
||||
* Title: processIOException |
* </p> |
||||
* </p> |
* |
||||
* <p> |
* @param timeoutEvent |
||||
* Description: |
*/ |
||||
* </p> |
@Override |
||||
* |
public void processTimeout(TimeoutEvent timeoutEvent) { |
||||
* @param exceptionEvent |
// TODO Auto-generated method stub
|
||||
*/ |
|
||||
@Override |
} |
||||
public void processIOException(IOExceptionEvent exceptionEvent) { |
|
||||
// TODO Auto-generated method stub
|
/** |
||||
|
* <p> |
||||
} |
* Title: processIOException |
||||
|
* </p> |
||||
/** |
* <p> |
||||
* <p> |
* Description: |
||||
* Title: processTransactionTerminated |
* </p> |
||||
* </p> |
* |
||||
* <p> |
* @param exceptionEvent |
||||
* Description: |
*/ |
||||
* </p> |
@Override |
||||
* |
public void processIOException(IOExceptionEvent exceptionEvent) { |
||||
* @param transactionTerminatedEvent |
// TODO Auto-generated method stub
|
||||
*/ |
|
||||
@Override |
} |
||||
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { |
|
||||
// TODO Auto-generated method stub
|
/** |
||||
|
* <p> |
||||
} |
* Title: processTransactionTerminated |
||||
|
* </p> |
||||
/** |
* <p> |
||||
* <p> |
* Description: |
||||
* Title: processDialogTerminated |
* </p> |
||||
* </p> |
* |
||||
* <p> |
* @param transactionTerminatedEvent |
||||
* Description: |
*/ |
||||
* </p> |
@Override |
||||
* |
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { |
||||
* @param dialogTerminatedEvent |
// TODO Auto-generated method stub
|
||||
*/ |
|
||||
@Override |
} |
||||
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { |
|
||||
// TODO Auto-generated method stub
|
/** |
||||
|
* <p> |
||||
} |
* Title: processDialogTerminated |
||||
|
* </p> |
||||
public ServerTransaction getServerTransaction(RequestEvent evt) { |
* <p> |
||||
Request request = evt.getRequest(); |
* Description: |
||||
ServerTransaction serverTransaction = evt.getServerTransaction(); |
* </p> |
||||
// 判断TCP还是UDP
|
* |
||||
boolean isTcp = false; |
* @param dialogTerminatedEvent |
||||
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); |
*/ |
||||
String transport = reqViaHeader.getTransport(); |
@Override |
||||
if (transport.equals("TCP")) { |
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { |
||||
isTcp = true; |
// TODO Auto-generated method stub
|
||||
} |
|
||||
|
} |
||||
if (serverTransaction == null) { |
|
||||
try { |
public ServerTransaction getServerTransaction(RequestEvent evt) { |
||||
if (isTcp) { |
Request request = evt.getRequest(); |
||||
serverTransaction = tcpSipProvider.getNewServerTransaction(request); |
ServerTransaction serverTransaction = evt.getServerTransaction(); |
||||
} else { |
// 判断TCP还是UDP
|
||||
serverTransaction = udpSipProvider.getNewServerTransaction(request); |
boolean isTcp = false; |
||||
} |
ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); |
||||
} catch (TransactionAlreadyExistsException e) { |
String transport = reqViaHeader.getTransport(); |
||||
e.printStackTrace(); |
if (transport.equals("TCP")) { |
||||
} catch (TransactionUnavailableException e) { |
isTcp = true; |
||||
e.printStackTrace(); |
} |
||||
} |
|
||||
} |
if (serverTransaction == null) { |
||||
return serverTransaction; |
try { |
||||
} |
if (isTcp) { |
||||
|
serverTransaction = tcpSipProvider.getNewServerTransaction(request); |
||||
public AddressFactory getAddressFactory() { |
} else { |
||||
return addressFactory; |
serverTransaction = udpSipProvider.getNewServerTransaction(request); |
||||
} |
} |
||||
|
} catch (TransactionAlreadyExistsException e) { |
||||
public HeaderFactory getHeaderFactory() { |
e.printStackTrace(); |
||||
return headerFactory; |
} catch (TransactionUnavailableException e) { |
||||
} |
e.printStackTrace(); |
||||
|
} |
||||
public MessageFactory getMessageFactory() { |
} |
||||
return messageFactory; |
return serverTransaction; |
||||
} |
} |
||||
|
|
||||
public SipProvider getTcpSipProvider() { |
public AddressFactory getAddressFactory() { |
||||
return tcpSipProvider; |
return addressFactory; |
||||
} |
} |
||||
|
|
||||
public SipProvider getUdpSipProvider() { |
public HeaderFactory getHeaderFactory() { |
||||
return udpSipProvider; |
return headerFactory; |
||||
} |
} |
||||
|
|
||||
} |
public MessageFactory getMessageFactory() { |
||||
|
return messageFactory; |
||||
|
} |
||||
|
|
||||
|
public SipProvider getTcpSipProvider() { |
||||
|
return tcpSipProvider; |
||||
|
} |
||||
|
|
||||
|
public SipProvider getUdpSipProvider() { |
||||
|
return udpSipProvider; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 169 KiB |
Loading…
Reference in new issue