| | |
| | | private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); |
| | | |
| | | @Autowired |
| | | private SipConfig config; |
| | | private SipConfig sipConfig; |
| | | |
| | | private SipProvider tcpSipProvider; |
| | | |
| | |
| | | |
| | | @PostConstruct |
| | | private void initSipServer() { |
| | | Thread thread=new Thread(this); |
| | | thread.setDaemon(true); |
| | | thread.setName("sip server thread start"); |
| | | thread.start(); |
| | | Thread thread = new Thread(this); |
| | | thread.setDaemon(true); |
| | | thread.setName("sip server thread start"); |
| | | thread.start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | Properties properties = new Properties(); |
| | | properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP"); |
| | | properties.setProperty("javax.sip.IP_ADDRESS", config.getSipIp()); |
| | | 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 |
| | | * 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.TRACE_LEVEL", "32"); |
| | | properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log"); |
| | | properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log"); |
| | | sipStack = (SipStackImpl) sipFactory.createSipStack(properties); |
| | |
| | | startTcpListener(); |
| | | startUdpListener(); |
| | | } catch (Exception e) { |
| | | logger.error("Sip Server 启动失败! port {" + config.getSipPort() + "}"); |
| | | logger.error("Sip Server 启动失败! port {" + sipConfig.getSipPort() + "}"); |
| | | e.printStackTrace(); |
| | | } |
| | | logger.info("Sip Server 启动成功 port {" + config.getSipPort() + "}"); |
| | | logger.info("Sip Server 启动成功 port {" + sipConfig.getSipPort() + "}"); |
| | | } |
| | | |
| | | private void startTcpListener() throws Exception { |
| | | ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "TCP"); |
| | | ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), |
| | | "TCP"); |
| | | tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint); |
| | | tcpSipProvider.addSipListener(this); |
| | | } |
| | | |
| | | private void startUdpListener() throws Exception { |
| | | ListeningPoint udpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "UDP"); |
| | | ListeningPoint udpListeningPoint = sipStack.createListeningPoint(sipConfig.getSipIp(), sipConfig.getSipPort(), |
| | | "UDP"); |
| | | udpSipProvider = sipStack.createSipProvider(udpListeningPoint); |
| | | udpSipProvider.addSipListener(this); |
| | | } |
| | |
| | | @Override |
| | | public void processRequest(RequestEvent evt) { |
| | | ISIPRequestProcessor processor = processorFactory.createRequestProcessor(evt); |
| | | processor.process(evt, this, getServerTransaction(evt)); |
| | | processor.process(evt, this); |
| | | } |
| | | |
| | | @Override |
| | |
| | | int status = response.getStatusCode(); |
| | | if ((status >= 200) && (status < 300)) { // Success! |
| | | ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); |
| | | processor.process(evt, this, config); |
| | | processor.process(evt, this, sipConfig); |
| | | } else if (status == Response.TRYING) { |
| | | // trying不会回复 |
| | | } else { |
| | | logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getContent().toString()); |
| | | } |
| | | // trying不会回复 |
| | | if (status == Response.TRYING) { |
| | | // if (status == Response.TRYING) { |
| | | |
| | | } |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | |
| | | private ServerTransaction getServerTransaction(RequestEvent evt) { |
| | | public ServerTransaction getServerTransaction(RequestEvent evt) { |
| | | Request request = evt.getRequest(); |
| | | ServerTransaction serverTransaction = evt.getServerTransaction(); |
| | | // 判断TCP还是UDP |