Commit 3745c80567cfdbd02cb60b2351d048f63eb6c1a2
1 parent
7997e40e
重构28181信令的message结构
Showing
40 changed files
with
2200 additions
and
204 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
| ... | ... | @@ -77,7 +77,7 @@ public class SipLayer{ |
| 77 | 77 | return sipStack; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - @Bean("tcpSipProvider") | |
| 80 | + @Bean(name = "tcpSipProvider") | |
| 81 | 81 | @DependsOn("sipStack") |
| 82 | 82 | private SipProviderImpl startTcpListener() { |
| 83 | 83 | ListeningPoint tcpListeningPoint = null; |
| ... | ... | @@ -100,7 +100,7 @@ public class SipLayer{ |
| 100 | 100 | return tcpSipProvider; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - @Bean("udpSipProvider") | |
| 103 | + @Bean(name = "udpSipProvider") | |
| 104 | 104 | @DependsOn("sipStack") |
| 105 | 105 | private SipProviderImpl startUdpListener() { |
| 106 | 106 | ListeningPoint udpListeningPoint = null; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
| ... | ... | @@ -16,8 +16,8 @@ import java.text.SimpleDateFormat; |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @description: 在线事件监听器,监听到离线后,修改设备离在线状态。 设备在线有两个来源: |
| 19 | - * 1、设备主动注销,发送注销指令,{@link com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.RegisterRequestProcessor} | |
| 20 | - * 2、设备未知原因离线,心跳超时,{@link com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.MessageRequestProcessor} | |
| 19 | + * 1、设备主动注销,发送注销指令 | |
| 20 | + * 2、设备未知原因离线,心跳超时 | |
| 21 | 21 | * @author: swwheihei |
| 22 | 22 | * @date: 2020年5月6日 下午1:51:23 |
| 23 | 23 | */ | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; | |
| 3 | 4 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; |
| 4 | 5 | import com.genersoft.iot.vmp.gb28181.transmit.event.response.ISIPResponseProcessor; |
| 5 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.event.timeout.ITimeoutProcessor; |
| 6 | 7 | import org.slf4j.Logger; |
| 7 | 8 | import org.slf4j.LoggerFactory; |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | 10 | import org.springframework.stereotype.Component; |
| 9 | 11 | |
| 10 | 12 | import javax.sip.*; |
| 11 | 13 | import javax.sip.header.CSeqHeader; |
| 14 | +import javax.sip.header.CallIdHeader; | |
| 15 | +import javax.sip.message.Response; | |
| 12 | 16 | import java.util.Map; |
| 13 | 17 | import java.util.concurrent.ConcurrentHashMap; |
| 14 | 18 | |
| ... | ... | @@ -26,6 +30,9 @@ public class SIPProcessorObserver implements SipListener { |
| 26 | 30 | private static Map<String, ISIPResponseProcessor> responseProcessorMap = new ConcurrentHashMap<>(); |
| 27 | 31 | private static ITimeoutProcessor timeoutProcessor; |
| 28 | 32 | |
| 33 | + @Autowired | |
| 34 | + private SipSubscribe sipSubscribe; | |
| 35 | + | |
| 29 | 36 | /** |
| 30 | 37 | * 添加 request订阅 |
| 31 | 38 | * @param method 方法名 |
| ... | ... | @@ -73,14 +80,54 @@ public class SIPProcessorObserver implements SipListener { |
| 73 | 80 | */ |
| 74 | 81 | @Override |
| 75 | 82 | public void processResponse(ResponseEvent responseEvent) { |
| 76 | - CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME); | |
| 77 | - String method = cseqHeader.getMethod(); | |
| 78 | - ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method); | |
| 79 | - if (sipRequestProcessor == null) { | |
| 80 | - logger.warn("不支持方法{}的response", method); | |
| 81 | - return; | |
| 83 | + logger.debug(responseEvent.getResponse().toString()); | |
| 84 | +// CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME); | |
| 85 | +// String method = cseqHeader.getMethod(); | |
| 86 | +// ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method); | |
| 87 | +// if (sipRequestProcessor == null) { | |
| 88 | +// logger.warn("不支持方法{}的response", method); | |
| 89 | +// return; | |
| 90 | +// } | |
| 91 | +// sipRequestProcessor.process(responseEvent); | |
| 92 | + | |
| 93 | + | |
| 94 | + Response response = responseEvent.getResponse(); | |
| 95 | + logger.debug(responseEvent.getResponse().toString()); | |
| 96 | + int status = response.getStatusCode(); | |
| 97 | + if (((status >= 200) && (status < 300)) || status == 401) { // Success! | |
| 98 | +// ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); | |
| 99 | + CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME); | |
| 100 | + String method = cseqHeader.getMethod(); | |
| 101 | + ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method); | |
| 102 | + if (sipRequestProcessor != null) { | |
| 103 | + sipRequestProcessor.process(responseEvent); | |
| 104 | + } | |
| 105 | + if (responseEvent.getResponse() != null && sipSubscribe.getOkSubscribesSize() > 0 ) { | |
| 106 | + CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME); | |
| 107 | + if (callIdHeader != null) { | |
| 108 | + SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId()); | |
| 109 | + if (subscribe != null) { | |
| 110 | + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent); | |
| 111 | + subscribe.response(eventResult); | |
| 112 | + } | |
| 113 | + } | |
| 114 | + } | |
| 115 | + } else if ((status >= 100) && (status < 200)) { | |
| 116 | + // 增加其它无需回复的响应,如101、180等 | |
| 117 | + } else { | |
| 118 | + logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/); | |
| 119 | + if (responseEvent.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) { | |
| 120 | + CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME); | |
| 121 | + if (callIdHeader != null) { | |
| 122 | + SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); | |
| 123 | + if (subscribe != null) { | |
| 124 | + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent); | |
| 125 | + subscribe.response(eventResult); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 82 | 129 | } |
| 83 | - sipRequestProcessor.process(responseEvent); | |
| 130 | + | |
| 84 | 131 | } |
| 85 | 132 | |
| 86 | 133 | /** | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/CheckForAllRecordsThread.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.callback; |
| 2 | 2 | |
| 3 | -import java.util.ArrayList; | |
| 4 | -import java.util.Comparator; | |
| 5 | -import java.util.List; | |
| 6 | -import java.util.concurrent.TimeUnit; | |
| 7 | - | |
| 8 | 3 | import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; |
| 9 | 4 | import com.genersoft.iot.vmp.gb28181.bean.RecordItem; |
| 10 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.MessageRequestProcessor; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.RecordInfoMessageHandler; | |
| 11 | 6 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 12 | - | |
| 13 | 7 | import org.slf4j.Logger; |
| 14 | 8 | |
| 9 | +import java.util.ArrayList; | |
| 10 | +import java.util.Comparator; | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.concurrent.TimeUnit; | |
| 13 | + | |
| 15 | 14 | @SuppressWarnings("unchecked") |
| 16 | 15 | public class CheckForAllRecordsThread extends Thread { |
| 17 | 16 | |
| ... | ... | @@ -58,7 +57,7 @@ public class CheckForAllRecordsThread extends Thread { |
| 58 | 57 | msg.setData(recordInfo); |
| 59 | 58 | deferredResultHolder.invokeAllResult(msg); |
| 60 | 59 | logger.info("处理完成,返回结果"); |
| 61 | - MessageRequestProcessor.threadNameList.remove(cacheKey); | |
| 60 | + RecordInfoMessageHandler.threadNameList.remove(cacheKey); | |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | public void setRedis(RedisUtil redis) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorAbstract.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request; |
| 2 | 2 | |
| 3 | 3 | import gov.nist.javax.sip.SipProviderImpl; |
| 4 | -import gov.nist.javax.sip.SipStackImpl; | |
| 5 | -import gov.nist.javax.sip.message.SIPRequest; | |
| 6 | -import gov.nist.javax.sip.stack.SIPServerTransaction; | |
| 7 | -import org.dom4j.Document; | |
| 8 | -import org.dom4j.DocumentException; | |
| 9 | -import org.dom4j.Element; | |
| 10 | -import org.dom4j.io.SAXReader; | |
| 11 | -import org.slf4j.Logger; | |
| 12 | -import org.slf4j.LoggerFactory; | |
| 13 | -import org.springframework.beans.factory.InitializingBean; | |
| 14 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 15 | 5 | import org.springframework.beans.factory.annotation.Qualifier; |
| 16 | 6 | |
| 17 | -import javax.sip.*; | |
| 18 | -import javax.sip.address.Address; | |
| 19 | -import javax.sip.address.AddressFactory; | |
| 20 | -import javax.sip.address.SipURI; | |
| 21 | -import javax.sip.header.ContentTypeHeader; | |
| 22 | -import javax.sip.header.HeaderFactory; | |
| 23 | -import javax.sip.header.ViaHeader; | |
| 24 | -import javax.sip.message.MessageFactory; | |
| 25 | -import javax.sip.message.Request; | |
| 26 | -import javax.sip.message.Response; | |
| 27 | -import java.io.ByteArrayInputStream; | |
| 28 | -import java.text.ParseException; | |
| 29 | - | |
| 30 | 7 | /** |
| 31 | 8 | * @description:处理接收IPCamera发来的SIP协议请求消息 |
| 32 | 9 | * @author: songww |
| 33 | 10 | * @date: 2020年5月3日 下午4:42:22 |
| 34 | 11 | */ |
| 35 | -public abstract class SIPRequestProcessorAbstract implements InitializingBean, ISIPRequestProcessor { | |
| 12 | +public abstract class SIPRequestProcessorAbstract { | |
| 36 | 13 | |
| 37 | - private final static Logger logger = LoggerFactory.getLogger(SIPRequestProcessorAbstract.class); | |
| 38 | 14 | |
| 39 | 15 | @Autowired |
| 40 | 16 | @Qualifier(value="tcpSipProvider") |
| ... | ... | @@ -44,136 +20,4 @@ public abstract class SIPRequestProcessorAbstract implements InitializingBean, I |
| 44 | 20 | @Qualifier(value="udpSipProvider") |
| 45 | 21 | private SipProviderImpl udpSipProvider; |
| 46 | 22 | |
| 47 | - /** | |
| 48 | - * 根据 RequestEvent 获取 ServerTransaction | |
| 49 | - * @param evt | |
| 50 | - * @return | |
| 51 | - */ | |
| 52 | - public ServerTransaction getServerTransaction(RequestEvent evt) { | |
| 53 | - Request request = evt.getRequest(); | |
| 54 | - ServerTransaction serverTransaction = evt.getServerTransaction(); | |
| 55 | - // 判断TCP还是UDP | |
| 56 | - boolean isTcp = false; | |
| 57 | - ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); | |
| 58 | - String transport = reqViaHeader.getTransport(); | |
| 59 | - if (transport.equals("TCP")) { | |
| 60 | - isTcp = true; | |
| 61 | - } | |
| 62 | - | |
| 63 | - if (serverTransaction == null) { | |
| 64 | - try { | |
| 65 | - if (isTcp) { | |
| 66 | - SipStackImpl stack = (SipStackImpl)tcpSipProvider.getSipStack(); | |
| 67 | - serverTransaction = (SIPServerTransaction) stack.findTransaction((SIPRequest)request, true); | |
| 68 | - if (serverTransaction == null) { | |
| 69 | - serverTransaction = tcpSipProvider.getNewServerTransaction(request); | |
| 70 | - } | |
| 71 | - } else { | |
| 72 | - SipStackImpl stack = (SipStackImpl)udpSipProvider.getSipStack(); | |
| 73 | - serverTransaction = (SIPServerTransaction) stack.findTransaction((SIPRequest)request, true); | |
| 74 | - if (serverTransaction == null) { | |
| 75 | - serverTransaction = udpSipProvider.getNewServerTransaction(request); | |
| 76 | - } | |
| 77 | - } | |
| 78 | - } catch (TransactionAlreadyExistsException e) { | |
| 79 | - logger.error(e.getMessage()); | |
| 80 | - } catch (TransactionUnavailableException e) { | |
| 81 | - logger.error(e.getMessage()); | |
| 82 | - } | |
| 83 | - } | |
| 84 | - return serverTransaction; | |
| 85 | - } | |
| 86 | - | |
| 87 | - public AddressFactory getAddressFactory() { | |
| 88 | - try { | |
| 89 | - return SipFactory.getInstance().createAddressFactory(); | |
| 90 | - } catch (PeerUnavailableException e) { | |
| 91 | - e.printStackTrace(); | |
| 92 | - } | |
| 93 | - return null; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public HeaderFactory getHeaderFactory() { | |
| 97 | - try { | |
| 98 | - return SipFactory.getInstance().createHeaderFactory(); | |
| 99 | - } catch (PeerUnavailableException e) { | |
| 100 | - e.printStackTrace(); | |
| 101 | - } | |
| 102 | - return null; | |
| 103 | - } | |
| 104 | - | |
| 105 | - public MessageFactory getMessageFactory() { | |
| 106 | - try { | |
| 107 | - return SipFactory.getInstance().createMessageFactory(); | |
| 108 | - } catch (PeerUnavailableException e) { | |
| 109 | - e.printStackTrace(); | |
| 110 | - } | |
| 111 | - return null; | |
| 112 | - } | |
| 113 | - | |
| 114 | - /*** | |
| 115 | - * 回复状态码 | |
| 116 | - * 100 trying | |
| 117 | - * 200 OK | |
| 118 | - * 400 | |
| 119 | - * 404 | |
| 120 | - * @param evt | |
| 121 | - * @throws SipException | |
| 122 | - * @throws InvalidArgumentException | |
| 123 | - * @throws ParseException | |
| 124 | - */ | |
| 125 | - public void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException { | |
| 126 | - Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); | |
| 127 | - ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 128 | - serverTransaction.sendResponse(response); | |
| 129 | - if (statusCode >= 200) { | |
| 130 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 131 | - } | |
| 132 | - } | |
| 133 | - | |
| 134 | - public void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { | |
| 135 | - Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); | |
| 136 | - response.setReasonPhrase(msg); | |
| 137 | - ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 138 | - serverTransaction.sendResponse(response); | |
| 139 | - if (statusCode >= 200) { | |
| 140 | - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 141 | - } | |
| 142 | - } | |
| 143 | - | |
| 144 | - /** | |
| 145 | - * 回复带sdp的200 | |
| 146 | - * @param evt | |
| 147 | - * @param sdp | |
| 148 | - * @throws SipException | |
| 149 | - * @throws InvalidArgumentException | |
| 150 | - * @throws ParseException | |
| 151 | - */ | |
| 152 | - public void responseAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException { | |
| 153 | - Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); | |
| 154 | - SipFactory sipFactory = SipFactory.getInstance(); | |
| 155 | - ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); | |
| 156 | - response.setContent(sdp, contentTypeHeader); | |
| 157 | - | |
| 158 | - SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); | |
| 159 | - | |
| 160 | - Address concatAddress = sipFactory.createAddressFactory().createAddress( | |
| 161 | - sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() | |
| 162 | - )); | |
| 163 | - response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); | |
| 164 | - getServerTransaction(evt).sendResponse(response); | |
| 165 | - } | |
| 166 | - | |
| 167 | - public Element getRootElement(RequestEvent evt) throws DocumentException { | |
| 168 | - return getRootElement(evt, "gb2312"); | |
| 169 | - } | |
| 170 | - public Element getRootElement(RequestEvent evt, String charset) throws DocumentException { | |
| 171 | - if (charset == null) charset = "gb2312"; | |
| 172 | - Request request = evt.getRequest(); | |
| 173 | - SAXReader reader = new SAXReader(); | |
| 174 | - reader.setEncoding(charset); | |
| 175 | - Document xml = reader.read(new ByteArrayInputStream(request.getRawContent())); | |
| 176 | - return xml.getRootElement(); | |
| 177 | - } | |
| 178 | - | |
| 179 | 23 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request; | |
| 2 | + | |
| 3 | +import gov.nist.javax.sip.SipProviderImpl; | |
| 4 | +import gov.nist.javax.sip.SipStackImpl; | |
| 5 | +import gov.nist.javax.sip.message.SIPRequest; | |
| 6 | +import gov.nist.javax.sip.stack.SIPServerTransaction; | |
| 7 | +import org.dom4j.Document; | |
| 8 | +import org.dom4j.DocumentException; | |
| 9 | +import org.dom4j.Element; | |
| 10 | +import org.dom4j.io.SAXReader; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 15 | + | |
| 16 | +import javax.sip.*; | |
| 17 | +import javax.sip.address.Address; | |
| 18 | +import javax.sip.address.AddressFactory; | |
| 19 | +import javax.sip.address.SipURI; | |
| 20 | +import javax.sip.header.ContentTypeHeader; | |
| 21 | +import javax.sip.header.HeaderFactory; | |
| 22 | +import javax.sip.header.ViaHeader; | |
| 23 | +import javax.sip.message.MessageFactory; | |
| 24 | +import javax.sip.message.Request; | |
| 25 | +import javax.sip.message.Response; | |
| 26 | +import java.io.ByteArrayInputStream; | |
| 27 | +import java.text.ParseException; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * @description:处理接收IPCamera发来的SIP协议请求消息 | |
| 31 | + * @author: songww | |
| 32 | + * @date: 2020年5月3日 下午4:42:22 | |
| 33 | + */ | |
| 34 | +public abstract class SIPRequestProcessorParent { | |
| 35 | + | |
| 36 | + private final static Logger logger = LoggerFactory.getLogger(SIPRequestProcessorParent.class); | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + @Qualifier(value="tcpSipProvider") | |
| 40 | + private SipProviderImpl tcpSipProvider; | |
| 41 | + | |
| 42 | + @Autowired | |
| 43 | + @Qualifier(value="udpSipProvider") | |
| 44 | + private SipProviderImpl udpSipProvider; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 根据 RequestEvent 获取 ServerTransaction | |
| 48 | + * @param evt | |
| 49 | + * @return | |
| 50 | + */ | |
| 51 | + public ServerTransaction getServerTransaction(RequestEvent evt) { | |
| 52 | + Request request = evt.getRequest(); | |
| 53 | + ServerTransaction serverTransaction = evt.getServerTransaction(); | |
| 54 | + // 判断TCP还是UDP | |
| 55 | + boolean isTcp = false; | |
| 56 | + ViaHeader reqViaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME); | |
| 57 | + String transport = reqViaHeader.getTransport(); | |
| 58 | + if (transport.equals("TCP")) { | |
| 59 | + isTcp = true; | |
| 60 | + } | |
| 61 | + | |
| 62 | + if (serverTransaction == null) { | |
| 63 | + try { | |
| 64 | + if (isTcp) { | |
| 65 | + SipStackImpl stack = (SipStackImpl)tcpSipProvider.getSipStack(); | |
| 66 | + serverTransaction = (SIPServerTransaction) stack.findTransaction((SIPRequest)request, true); | |
| 67 | + if (serverTransaction == null) { | |
| 68 | + serverTransaction = tcpSipProvider.getNewServerTransaction(request); | |
| 69 | + } | |
| 70 | + } else { | |
| 71 | + SipStackImpl stack = (SipStackImpl)udpSipProvider.getSipStack(); | |
| 72 | + serverTransaction = (SIPServerTransaction) stack.findTransaction((SIPRequest)request, true); | |
| 73 | + if (serverTransaction == null) { | |
| 74 | + serverTransaction = udpSipProvider.getNewServerTransaction(request); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } catch (TransactionAlreadyExistsException e) { | |
| 78 | + logger.error(e.getMessage()); | |
| 79 | + } catch (TransactionUnavailableException e) { | |
| 80 | + logger.error(e.getMessage()); | |
| 81 | + } | |
| 82 | + } | |
| 83 | + return serverTransaction; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public AddressFactory getAddressFactory() { | |
| 87 | + try { | |
| 88 | + return SipFactory.getInstance().createAddressFactory(); | |
| 89 | + } catch (PeerUnavailableException e) { | |
| 90 | + e.printStackTrace(); | |
| 91 | + } | |
| 92 | + return null; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public HeaderFactory getHeaderFactory() { | |
| 96 | + try { | |
| 97 | + return SipFactory.getInstance().createHeaderFactory(); | |
| 98 | + } catch (PeerUnavailableException e) { | |
| 99 | + e.printStackTrace(); | |
| 100 | + } | |
| 101 | + return null; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public MessageFactory getMessageFactory() { | |
| 105 | + try { | |
| 106 | + return SipFactory.getInstance().createMessageFactory(); | |
| 107 | + } catch (PeerUnavailableException e) { | |
| 108 | + e.printStackTrace(); | |
| 109 | + } | |
| 110 | + return null; | |
| 111 | + } | |
| 112 | + | |
| 113 | + /*** | |
| 114 | + * 回复状态码 | |
| 115 | + * 100 trying | |
| 116 | + * 200 OK | |
| 117 | + * 400 | |
| 118 | + * 404 | |
| 119 | + * @param evt | |
| 120 | + * @throws SipException | |
| 121 | + * @throws InvalidArgumentException | |
| 122 | + * @throws ParseException | |
| 123 | + */ | |
| 124 | + public void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException { | |
| 125 | + Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); | |
| 126 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 127 | + serverTransaction.sendResponse(response); | |
| 128 | + if (statusCode >= 200) { | |
| 129 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + public void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException { | |
| 134 | + Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); | |
| 135 | + response.setReasonPhrase(msg); | |
| 136 | + ServerTransaction serverTransaction = getServerTransaction(evt); | |
| 137 | + serverTransaction.sendResponse(response); | |
| 138 | + if (statusCode >= 200) { | |
| 139 | + if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | |
| 140 | + } | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * 回复带sdp的200 | |
| 145 | + * @param evt | |
| 146 | + * @param sdp | |
| 147 | + * @throws SipException | |
| 148 | + * @throws InvalidArgumentException | |
| 149 | + * @throws ParseException | |
| 150 | + */ | |
| 151 | + public void responseAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException { | |
| 152 | + Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); | |
| 153 | + SipFactory sipFactory = SipFactory.getInstance(); | |
| 154 | + ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP"); | |
| 155 | + response.setContent(sdp, contentTypeHeader); | |
| 156 | + | |
| 157 | + SipURI sipURI = (SipURI)evt.getRequest().getRequestURI(); | |
| 158 | + | |
| 159 | + Address concatAddress = sipFactory.createAddressFactory().createAddress( | |
| 160 | + sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort() | |
| 161 | + )); | |
| 162 | + response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress)); | |
| 163 | + getServerTransaction(evt).sendResponse(response); | |
| 164 | + } | |
| 165 | + | |
| 166 | + public Element getRootElement(RequestEvent evt) throws DocumentException { | |
| 167 | + return getRootElement(evt, "gb2312"); | |
| 168 | + } | |
| 169 | + public Element getRootElement(RequestEvent evt, String charset) throws DocumentException { | |
| 170 | + if (charset == null) charset = "gb2312"; | |
| 171 | + Request request = evt.getRequest(); | |
| 172 | + SAXReader reader = new SAXReader(); | |
| 173 | + reader.setEncoding(charset); | |
| 174 | + Document xml = reader.read(new ByteArrayInputStream(request.getRawContent())); | |
| 175 | + return xml.getRootElement(); | |
| 176 | + } | |
| 177 | + | |
| 178 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
| ... | ... | @@ -3,13 +3,15 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| 3 | 3 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 6 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 7 | 8 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 8 | 9 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 9 | 10 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 10 | 11 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 11 | 12 | import org.slf4j.Logger; |
| 12 | 13 | import org.slf4j.LoggerFactory; |
| 14 | +import org.springframework.beans.factory.InitializingBean; | |
| 13 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | 16 | import org.springframework.stereotype.Component; |
| 15 | 17 | |
| ... | ... | @@ -29,7 +31,7 @@ import java.util.Map; |
| 29 | 31 | * @date: 2020年5月3日 下午5:31:45 |
| 30 | 32 | */ |
| 31 | 33 | @Component |
| 32 | -public class AckRequestProcessor extends SIPRequestProcessorAbstract { | |
| 34 | +public class AckRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 33 | 35 | |
| 34 | 36 | private Logger logger = LoggerFactory.getLogger(AckRequestProcessor.class); |
| 35 | 37 | private String method = "ACK"; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
| ... | ... | @@ -5,7 +5,8 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| 8 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 10 | 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 11 | 12 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| ... | ... | @@ -13,6 +14,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 13 | 14 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 14 | 15 | import org.slf4j.Logger; |
| 15 | 16 | import org.slf4j.LoggerFactory; |
| 17 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | 19 | import org.springframework.stereotype.Component; |
| 18 | 20 | |
| ... | ... | @@ -32,7 +34,7 @@ import java.util.Map; |
| 32 | 34 | * @date: 2021年3月9日 |
| 33 | 35 | */ |
| 34 | 36 | @Component |
| 35 | -public class ByeRequestProcessor extends SIPRequestProcessorAbstract { | |
| 37 | +public class ByeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 36 | 38 | |
| 37 | 39 | private Logger logger = LoggerFactory.getLogger(ByeRequestProcessor.class); |
| 38 | 40 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/CancelRequestProcessor.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 4 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 6 | +import org.springframework.beans.factory.InitializingBean; | |
| 5 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | 8 | import org.springframework.stereotype.Component; |
| 7 | 9 | |
| ... | ... | @@ -13,7 +15,7 @@ import javax.sip.RequestEvent; |
| 13 | 15 | * @date: 2020年5月3日 下午5:32:23 |
| 14 | 16 | */ |
| 15 | 17 | @Component |
| 16 | -public class CancelRequestProcessor extends SIPRequestProcessorAbstract { | |
| 18 | +public class CancelRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 17 | 19 | |
| 18 | 20 | private String method = "CANCEL"; |
| 19 | 21 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -4,7 +4,8 @@ import com.genersoft.iot.vmp.gb28181.bean.*; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| 7 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 8 | 9 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 9 | 10 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 10 | 11 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| ... | ... | @@ -16,6 +17,7 @@ import gov.nist.javax.sip.address.AddressImpl; |
| 16 | 17 | import gov.nist.javax.sip.address.SipUri; |
| 17 | 18 | import org.slf4j.Logger; |
| 18 | 19 | import org.slf4j.LoggerFactory; |
| 20 | +import org.springframework.beans.factory.InitializingBean; | |
| 19 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | 22 | import org.springframework.stereotype.Component; |
| 21 | 23 | |
| ... | ... | @@ -38,7 +40,7 @@ import java.util.Vector; |
| 38 | 40 | */ |
| 39 | 41 | @SuppressWarnings("rawtypes") |
| 40 | 42 | @Component |
| 41 | -public class InviteRequestProcessor extends SIPRequestProcessorAbstract { | |
| 43 | +public class InviteRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 42 | 44 | |
| 43 | 45 | private final static Logger logger = LoggerFactory.getLogger(InviteRequestProcessor.class); |
| 44 | 46 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/MessageRequestProcessor.java renamed to src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/MessageRequestProcessor1.java
| ... | ... | @@ -15,7 +15,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 15 | 15 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 16 | 16 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 17 | 17 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| 18 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 18 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 19 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 19 | 20 | import com.genersoft.iot.vmp.gb28181.utils.DateUtil; |
| 20 | 21 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 21 | 22 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| ... | ... | @@ -33,6 +34,7 @@ import org.dom4j.DocumentException; |
| 33 | 34 | import org.dom4j.Element; |
| 34 | 35 | import org.slf4j.Logger; |
| 35 | 36 | import org.slf4j.LoggerFactory; |
| 37 | +import org.springframework.beans.factory.InitializingBean; | |
| 36 | 38 | import org.springframework.beans.factory.annotation.Autowired; |
| 37 | 39 | import org.springframework.stereotype.Component; |
| 38 | 40 | import org.springframework.util.StringUtils; |
| ... | ... | @@ -44,24 +46,24 @@ import javax.sip.header.HeaderAddress; |
| 44 | 46 | import javax.sip.header.ToHeader; |
| 45 | 47 | import javax.sip.message.Response; |
| 46 | 48 | import java.text.ParseException; |
| 47 | -import java.util.ArrayList; | |
| 48 | -import java.util.Iterator; | |
| 49 | -import java.util.List; | |
| 50 | -import java.util.UUID; | |
| 49 | +import java.util.*; | |
| 50 | +import java.util.concurrent.ConcurrentHashMap; | |
| 51 | 51 | |
| 52 | 52 | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | - * @description:MESSAGE请求处理器 | |
| 56 | - * @author: swwheihei | |
| 57 | - * @date: 2020年5月3日 下午5:32:41 | |
| 55 | + * @description: MESSAGE请求分发处理器, | |
| 56 | + * @author: panlinlin | |
| 57 | + * @date: 2021年11月8日 10:28 | |
| 58 | 58 | */ |
| 59 | 59 | @SuppressWarnings(value={"unchecked", "rawtypes"}) |
| 60 | 60 | @Component |
| 61 | -public class MessageRequestProcessor extends SIPRequestProcessorAbstract { | |
| 61 | +public class MessageRequestProcessor1 extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 62 | 62 | |
| 63 | 63 | public static volatile List<String> threadNameList = new ArrayList(); |
| 64 | - private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class); | |
| 64 | + private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor1.class); | |
| 65 | + private static Map<String, ISIPRequestProcessor> messageHandlerMap = new ConcurrentHashMap<>(); | |
| 66 | + | |
| 65 | 67 | |
| 66 | 68 | private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_"; |
| 67 | 69 | private static final String MESSAGE_KEEP_ALIVE = "Keepalive"; |
| ... | ... | @@ -77,7 +79,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorAbstract { |
| 77 | 79 | private static final String MESSAGE_DEVICE_CONFIG = "DeviceConfig"; |
| 78 | 80 | private static final String MESSAGE_MOBILE_POSITION = "MobilePosition"; |
| 79 | 81 | private static final String MESSAGE_PRESET_QUERY = "PresetQuery"; |
| 80 | - private String method = "MESSAGE"; | |
| 82 | + private String method = "MESSAGE1111"; | |
| 81 | 83 | |
| 82 | 84 | @Autowired |
| 83 | 85 | private UserSetup userSetup; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
| ... | ... | @@ -8,7 +8,8 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 9 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 11 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 12 | 13 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 13 | 14 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 14 | 15 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| ... | ... | @@ -20,6 +21,7 @@ import org.dom4j.DocumentException; |
| 20 | 21 | import org.dom4j.Element; |
| 21 | 22 | import org.slf4j.Logger; |
| 22 | 23 | import org.slf4j.LoggerFactory; |
| 24 | +import org.springframework.beans.factory.InitializingBean; | |
| 23 | 25 | import org.springframework.beans.factory.annotation.Autowired; |
| 24 | 26 | import org.springframework.stereotype.Component; |
| 25 | 27 | import org.springframework.util.StringUtils; |
| ... | ... | @@ -38,7 +40,7 @@ import java.util.Iterator; |
| 38 | 40 | * @date: 2021年1月27日 |
| 39 | 41 | */ |
| 40 | 42 | @Component |
| 41 | -public class NotifyRequestProcessor extends SIPRequestProcessorAbstract { | |
| 43 | +public class NotifyRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 42 | 44 | |
| 43 | 45 | |
| 44 | 46 | private final static Logger logger = LoggerFactory.getLogger(NotifyRequestProcessor.class); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
| ... | ... | @@ -8,7 +8,8 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.bean.WvpSipDate; |
| 9 | 9 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 11 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 12 | 13 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 13 | 14 | import gov.nist.javax.sip.RequestEventExt; |
| 14 | 15 | import gov.nist.javax.sip.address.AddressImpl; |
| ... | ... | @@ -17,6 +18,7 @@ import gov.nist.javax.sip.header.Expires; |
| 17 | 18 | import gov.nist.javax.sip.header.SIPDateHeader; |
| 18 | 19 | import org.slf4j.Logger; |
| 19 | 20 | import org.slf4j.LoggerFactory; |
| 21 | +import org.springframework.beans.factory.InitializingBean; | |
| 20 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | 23 | import org.springframework.stereotype.Component; |
| 22 | 24 | import org.springframework.util.StringUtils; |
| ... | ... | @@ -39,7 +41,7 @@ import java.util.Locale; |
| 39 | 41 | * @date: 2020年5月3日 下午4:47:25 |
| 40 | 42 | */ |
| 41 | 43 | @Component |
| 42 | -public class RegisterRequestProcessor extends SIPRequestProcessorAbstract { | |
| 44 | +public class RegisterRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 43 | 45 | |
| 44 | 46 | private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class); |
| 45 | 47 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/SubscribeRequestProcessor.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 4 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 5 | 6 | import org.slf4j.Logger; |
| 6 | 7 | import org.slf4j.LoggerFactory; |
| 8 | +import org.springframework.beans.factory.InitializingBean; | |
| 7 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | 10 | import org.springframework.stereotype.Component; |
| 9 | 11 | |
| ... | ... | @@ -22,7 +24,7 @@ import java.text.ParseException; |
| 22 | 24 | * @date: 2020年5月3日 下午5:31:20 |
| 23 | 25 | */ |
| 24 | 26 | @Component |
| 25 | -public class SubscribeRequestProcessor extends SIPRequestProcessorAbstract { | |
| 27 | +public class SubscribeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 26 | 28 | |
| 27 | 29 | private Logger logger = LoggerFactory.getLogger(SubscribeRequestProcessor.class); |
| 28 | 30 | private String method = "SUBSCRIBE"; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/IMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import org.dom4j.Element; | |
| 6 | + | |
| 7 | +import javax.sip.RequestEvent; | |
| 8 | + | |
| 9 | +public interface IMessageHandler { | |
| 10 | + /** | |
| 11 | + * 处理来自设备的信息 | |
| 12 | + * @param evt | |
| 13 | + * @param device | |
| 14 | + */ | |
| 15 | + void handForDevice(RequestEvent evt, Device device, Element element); | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 处理来自平台的信息 | |
| 19 | + * @param evt | |
| 20 | + * @param parentPlatform | |
| 21 | + */ | |
| 22 | + void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element); | |
| 23 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageHandlerAbstract.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 6 | +import org.dom4j.Element; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | + | |
| 9 | +import javax.sip.RequestEvent; | |
| 10 | +import java.util.Map; | |
| 11 | +import java.util.concurrent.ConcurrentHashMap; | |
| 12 | + | |
| 13 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 14 | + | |
| 15 | +public abstract class MessageHandlerAbstract extends SIPRequestProcessorParent implements IMessageHandler{ | |
| 16 | + | |
| 17 | + public static Map<String, IMessageHandler> messageHandlerMap = new ConcurrentHashMap<>(); | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + public MessageRequestProcessor messageRequestProcessor; | |
| 21 | + | |
| 22 | + public void addHandler(String cmdType, IMessageHandler messageHandler) { | |
| 23 | + messageHandlerMap.put(cmdType, messageHandler); | |
| 24 | + } | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 28 | + String cmd = getText(element, "CmdType"); | |
| 29 | + IMessageHandler messageHandler = messageHandlerMap.get(cmd); | |
| 30 | + if (messageHandler != null) { | |
| 31 | + messageHandler.handForDevice(evt, device, element); | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 37 | + String cmd = getText(element, "CmdType"); | |
| 38 | + IMessageHandler messageHandler = messageHandlerMap.get(cmd); | |
| 39 | + if (messageHandler != null) { | |
| 40 | + messageHandler.handForPlatform(evt, parentPlatform, element); | |
| 41 | + } | |
| 42 | + } | |
| 43 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageRequestProcessor.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.utils.SipUtils; | |
| 9 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 10 | +import org.dom4j.DocumentException; | |
| 11 | +import org.dom4j.Element; | |
| 12 | +import org.slf4j.Logger; | |
| 13 | +import org.slf4j.LoggerFactory; | |
| 14 | +import org.springframework.beans.factory.InitializingBean; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import javax.sip.InvalidArgumentException; | |
| 19 | +import javax.sip.RequestEvent; | |
| 20 | +import javax.sip.SipException; | |
| 21 | +import javax.sip.message.Response; | |
| 22 | +import java.text.ParseException; | |
| 23 | +import java.util.Map; | |
| 24 | +import java.util.concurrent.ConcurrentHashMap; | |
| 25 | + | |
| 26 | +@Component | |
| 27 | +public class MessageRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { | |
| 28 | + | |
| 29 | + private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class); | |
| 30 | + | |
| 31 | + private final String method = "MESSAGE"; | |
| 32 | + | |
| 33 | + private static Map<String, IMessageHandler> messageHandlerMap = new ConcurrentHashMap<>(); | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private SIPProcessorObserver sipProcessorObserver; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private IVideoManagerStorager storage; | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void afterPropertiesSet() throws Exception { | |
| 43 | + // 添加消息处理的订阅 | |
| 44 | + sipProcessorObserver.addRequestProcessor(method, this); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public void addHandler(String name, IMessageHandler handler) { | |
| 48 | + messageHandlerMap.put(name, handler); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public void process(RequestEvent evt) { | |
| 53 | + logger.debug("接收到消息:" + evt.getRequest()); | |
| 54 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | |
| 55 | + // 查询设备是否存在 | |
| 56 | + Device device = storage.queryVideoDevice(deviceId); | |
| 57 | + // 查询上级平台是否存在 | |
| 58 | + ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(deviceId); | |
| 59 | + try { | |
| 60 | + if (device == null && parentPlatform == null) { | |
| 61 | + // 不存在则回复404 | |
| 62 | + responseAck(evt, Response.NOT_FOUND, "device id not found"); | |
| 63 | + }else { | |
| 64 | + Element rootElement = getRootElement(evt); | |
| 65 | + String name = rootElement.getName(); | |
| 66 | + IMessageHandler messageHandler = messageHandlerMap.get(name); | |
| 67 | + if (messageHandler != null) { | |
| 68 | + if (device != null) { | |
| 69 | + messageHandler.handForDevice(evt, device, rootElement); | |
| 70 | + }else { // 由于上面已经判断都为null则直接返回,所以这里device和parentPlatform必有一个不为null | |
| 71 | + messageHandler.handForPlatform(evt, parentPlatform, rootElement); | |
| 72 | + } | |
| 73 | + }else { | |
| 74 | + // 不支持的message | |
| 75 | + // 不存在则回复415 | |
| 76 | + responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE, "Unsupported message type, must Control/Notify/Query/Response"); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + } catch (SipException e) { | |
| 80 | + logger.warn("SIP 回复错误", e); | |
| 81 | + } catch (InvalidArgumentException e) { | |
| 82 | + logger.warn("参数无效", e); | |
| 83 | + } catch (ParseException e) { | |
| 84 | + logger.warn("SIP回复时解析异常", e); | |
| 85 | + } catch (DocumentException e) { | |
| 86 | + logger.warn("解析XML消息内容异常", e); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + | |
| 91 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/ControlMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.control; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageRequestProcessor; | |
| 5 | +import org.springframework.beans.factory.InitializingBean; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +@Component | |
| 10 | +public class ControlMessageHandler extends MessageHandlerAbstract implements InitializingBean { | |
| 11 | + | |
| 12 | + private final String messageType = "Control"; | |
| 13 | + | |
| 14 | + @Autowired | |
| 15 | + private MessageRequestProcessor messageRequestProcessor; | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + public void afterPropertiesSet() throws Exception { | |
| 19 | + messageRequestProcessor.addHandler(messageType, this); | |
| 20 | + } | |
| 21 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract; | |
| 4 | +import org.springframework.beans.factory.InitializingBean; | |
| 5 | +import org.springframework.stereotype.Component; | |
| 6 | + | |
| 7 | +@Component | |
| 8 | +public class NotifyMessageHandler extends MessageHandlerAbstract implements InitializingBean { | |
| 9 | + | |
| 10 | + private final String messageType = "Notify"; | |
| 11 | + | |
| 12 | + @Override | |
| 13 | + public void afterPropertiesSet() throws Exception { | |
| 14 | + messageRequestProcessor.addHandler(messageType, this); | |
| 15 | + } | |
| 16 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.*; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | |
| 11 | +import com.genersoft.iot.vmp.service.IDeviceAlarmService; | |
| 12 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 13 | +import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 14 | +import org.dom4j.Element; | |
| 15 | +import org.slf4j.Logger; | |
| 16 | +import org.slf4j.LoggerFactory; | |
| 17 | +import org.springframework.beans.factory.InitializingBean; | |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 19 | +import org.springframework.util.StringUtils; | |
| 20 | + | |
| 21 | +import javax.sip.RequestEvent; | |
| 22 | + | |
| 23 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 24 | + | |
| 25 | +public class AlarmMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 26 | + | |
| 27 | + private Logger logger = LoggerFactory.getLogger(AlarmMessageHandler.class); | |
| 28 | + private final String cmdType = "Alarm"; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private NotifyMessageHandler notifyMessageHandler; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + private EventPublisher publisher; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + private UserSetup userSetup; | |
| 38 | + | |
| 39 | + @Autowired | |
| 40 | + private IVideoManagerStorager storager; | |
| 41 | + | |
| 42 | + @Autowired | |
| 43 | + private IDeviceAlarmService deviceAlarmService; | |
| 44 | + | |
| 45 | + @Autowired | |
| 46 | + private DeviceOffLineDetector offLineDetector; | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public void afterPropertiesSet() throws Exception { | |
| 50 | + notifyMessageHandler.addHandler(cmdType, this); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 55 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 56 | + String channelId = deviceIdElement.getText().toString(); | |
| 57 | + DeviceAlarm deviceAlarm = new DeviceAlarm(); | |
| 58 | + deviceAlarm.setDeviceId(device.getDeviceId()); | |
| 59 | + deviceAlarm.setChannelId(channelId); | |
| 60 | + deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority")); | |
| 61 | + deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod")); | |
| 62 | + deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime")); | |
| 63 | + if (getText(rootElement, "AlarmDescription") == null) { | |
| 64 | + deviceAlarm.setAlarmDescription(""); | |
| 65 | + } else { | |
| 66 | + deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription")); | |
| 67 | + } | |
| 68 | + if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) { | |
| 69 | + deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | |
| 70 | + } else { | |
| 71 | + deviceAlarm.setLongitude(0.00); | |
| 72 | + } | |
| 73 | + if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) { | |
| 74 | + deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | |
| 75 | + } else { | |
| 76 | + deviceAlarm.setLatitude(0.00); | |
| 77 | + } | |
| 78 | + | |
| 79 | + if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) { | |
| 80 | + if ( deviceAlarm.getAlarmMethod().equals("4")) { | |
| 81 | + MobilePosition mobilePosition = new MobilePosition(); | |
| 82 | + mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); | |
| 83 | + mobilePosition.setTime(deviceAlarm.getAlarmTime()); | |
| 84 | + mobilePosition.setLongitude(deviceAlarm.getLongitude()); | |
| 85 | + mobilePosition.setLatitude(deviceAlarm.getLatitude()); | |
| 86 | + mobilePosition.setReportSource("GPS Alarm"); | |
| 87 | + BaiduPoint bp = new BaiduPoint(); | |
| 88 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | |
| 89 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | |
| 90 | + mobilePosition.setGeodeticSystem("BD-09"); | |
| 91 | + mobilePosition.setCnLng(bp.getBdLng()); | |
| 92 | + mobilePosition.setCnLat(bp.getBdLat()); | |
| 93 | + if (!userSetup.getSavePositionHistory()) { | |
| 94 | + storager.clearMobilePositionsByDeviceId(device.getDeviceId()); | |
| 95 | + } | |
| 96 | + storager.insertMobilePosition(mobilePosition); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + logger.debug("存储报警信息、报警分类"); | |
| 100 | + // 存储报警信息、报警分类 | |
| 101 | + deviceAlarmService.add(deviceAlarm); | |
| 102 | + | |
| 103 | + if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 104 | + publisher.deviceAlarmEventPublish(deviceAlarm); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Override | |
| 109 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 110 | + | |
| 111 | + } | |
| 112 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; | |
| 10 | +import org.dom4j.Element; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.InitializingBean; | |
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | + | |
| 16 | +import javax.sip.InvalidArgumentException; | |
| 17 | +import javax.sip.RequestEvent; | |
| 18 | +import javax.sip.SipException; | |
| 19 | +import javax.sip.message.Response; | |
| 20 | +import java.text.ParseException; | |
| 21 | + | |
| 22 | +public class KeepaliveMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 23 | + | |
| 24 | + private Logger logger = LoggerFactory.getLogger(KeepaliveMessageHandler.class); | |
| 25 | + private final String cmdType = "Keepalive"; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private NotifyMessageHandler notifyMessageHandler; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private EventPublisher publisher; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void afterPropertiesSet() throws Exception { | |
| 35 | + notifyMessageHandler.addHandler(cmdType, this); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 40 | + // 检查设备是否存在并在线, 不在线则设置为在线 | |
| 41 | + try { | |
| 42 | + if (device != null ) { | |
| 43 | + // 回复200 OK | |
| 44 | + responseAck(evt, Response.OK); | |
| 45 | + publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | |
| 46 | + } | |
| 47 | + } catch (SipException e) { | |
| 48 | + e.printStackTrace(); | |
| 49 | + } catch (InvalidArgumentException e) { | |
| 50 | + e.printStackTrace(); | |
| 51 | + } catch (ParseException e) { | |
| 52 | + e.printStackTrace(); | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 58 | + // 不会收到上级平台的心跳信息 | |
| 59 | + | |
| 60 | + } | |
| 61 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.common.StreamInfo; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | |
| 11 | +import org.dom4j.Element; | |
| 12 | +import org.slf4j.Logger; | |
| 13 | +import org.slf4j.LoggerFactory; | |
| 14 | +import org.springframework.beans.factory.InitializingBean; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | + | |
| 17 | +import javax.sip.InvalidArgumentException; | |
| 18 | +import javax.sip.RequestEvent; | |
| 19 | +import javax.sip.SipException; | |
| 20 | +import javax.sip.message.Response; | |
| 21 | + | |
| 22 | +import java.text.ParseException; | |
| 23 | + | |
| 24 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 25 | + | |
| 26 | +public class MediaStatusMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 27 | + | |
| 28 | + private Logger logger = LoggerFactory.getLogger(MediaStatusMessageHandler.class); | |
| 29 | + private final String cmdType = "MediaStatus"; | |
| 30 | + | |
| 31 | + @Autowired | |
| 32 | + private NotifyMessageHandler notifyMessageHandler; | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + private SIPCommander cmder; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private IRedisCatchStorage redisCatchStorage; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public void afterPropertiesSet() throws Exception { | |
| 42 | + notifyMessageHandler.addHandler(cmdType, this); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 47 | + | |
| 48 | + // 回复200 OK | |
| 49 | + try { | |
| 50 | + responseAck(evt, Response.OK); | |
| 51 | + } catch (SipException e) { | |
| 52 | + e.printStackTrace(); | |
| 53 | + } catch (InvalidArgumentException e) { | |
| 54 | + e.printStackTrace(); | |
| 55 | + } catch (ParseException e) { | |
| 56 | + e.printStackTrace(); | |
| 57 | + } | |
| 58 | + String NotifyType =getText(rootElement, "NotifyType"); | |
| 59 | + if (NotifyType.equals("121")){ | |
| 60 | + logger.info("媒体播放完毕,通知关流"); | |
| 61 | + StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(device.getDeviceId(), "*"); | |
| 62 | + if (streamInfo != null) { | |
| 63 | + redisCatchStorage.stopPlayback(streamInfo); | |
| 64 | + cmder.streamByeCmd(streamInfo.getDeviceID(), streamInfo.getChannelId()); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 71 | + | |
| 72 | + } | |
| 73 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.BaiduPoint; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | |
| 12 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 13 | +import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 14 | +import org.dom4j.DocumentException; | |
| 15 | +import org.dom4j.Element; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.factory.InitializingBean; | |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | +import org.springframework.util.StringUtils; | |
| 21 | + | |
| 22 | +import javax.sip.InvalidArgumentException; | |
| 23 | +import javax.sip.RequestEvent; | |
| 24 | +import javax.sip.SipException; | |
| 25 | +import javax.sip.message.Response; | |
| 26 | +import java.text.ParseException; | |
| 27 | + | |
| 28 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 29 | + | |
| 30 | +public class MobilePositionMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 31 | + | |
| 32 | + private Logger logger = LoggerFactory.getLogger(MobilePositionMessageHandler.class); | |
| 33 | + private final String cmdType = "MobilePosition"; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private NotifyMessageHandler notifyMessageHandler; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private UserSetup userSetup; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + private IVideoManagerStorager storager; | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void afterPropertiesSet() throws Exception { | |
| 46 | + notifyMessageHandler.addHandler(cmdType, this); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 51 | + | |
| 52 | + try { | |
| 53 | + rootElement = getRootElement(evt, device.getCharset()); | |
| 54 | + | |
| 55 | + MobilePosition mobilePosition = new MobilePosition(); | |
| 56 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 57 | + mobilePosition.setDeviceName(device.getName()); | |
| 58 | + } | |
| 59 | + mobilePosition.setDeviceId(device.getDeviceId()); | |
| 60 | + mobilePosition.setChannelId(getText(rootElement, "DeviceID")); | |
| 61 | + mobilePosition.setTime(getText(rootElement, "Time")); | |
| 62 | + mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | |
| 63 | + mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | |
| 64 | + if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { | |
| 65 | + mobilePosition.setSpeed(Double.parseDouble(getText(rootElement, "Speed"))); | |
| 66 | + } else { | |
| 67 | + mobilePosition.setSpeed(0.0); | |
| 68 | + } | |
| 69 | + if (NumericUtil.isDouble(getText(rootElement, "Direction"))) { | |
| 70 | + mobilePosition.setDirection(Double.parseDouble(getText(rootElement, "Direction"))); | |
| 71 | + } else { | |
| 72 | + mobilePosition.setDirection(0.0); | |
| 73 | + } | |
| 74 | + if (NumericUtil.isDouble(getText(rootElement, "Altitude"))) { | |
| 75 | + mobilePosition.setAltitude(Double.parseDouble(getText(rootElement, "Altitude"))); | |
| 76 | + } else { | |
| 77 | + mobilePosition.setAltitude(0.0); | |
| 78 | + } | |
| 79 | + mobilePosition.setReportSource("Mobile Position"); | |
| 80 | + BaiduPoint bp = new BaiduPoint(); | |
| 81 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | |
| 82 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | |
| 83 | + mobilePosition.setGeodeticSystem("BD-09"); | |
| 84 | + mobilePosition.setCnLng(bp.getBdLng()); | |
| 85 | + mobilePosition.setCnLat(bp.getBdLat()); | |
| 86 | + if (!userSetup.getSavePositionHistory()) { | |
| 87 | + storager.clearMobilePositionsByDeviceId(device.getDeviceId()); | |
| 88 | + } | |
| 89 | + storager.insertMobilePosition(mobilePosition); | |
| 90 | + //回复 200 OK | |
| 91 | + responseAck(evt, Response.OK); | |
| 92 | + } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | |
| 93 | + e.printStackTrace(); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Override | |
| 98 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 99 | + | |
| 100 | + } | |
| 101 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/QueryMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageRequestProcessor; | |
| 5 | +import org.springframework.beans.factory.InitializingBean; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +@Component | |
| 10 | +public class QueryMessageHandler extends MessageHandlerAbstract implements InitializingBean { | |
| 11 | + | |
| 12 | + private final String messageType = "Query"; | |
| 13 | + | |
| 14 | + @Autowired | |
| 15 | + private MessageRequestProcessor messageRequestProcessor; | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + public void afterPropertiesSet() throws Exception { | |
| 19 | + messageRequestProcessor.addHandler(messageType, this); | |
| 20 | + } | |
| 21 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.GbStream; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler; | |
| 14 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 15 | +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | |
| 16 | +import org.dom4j.Element; | |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 19 | +import org.springframework.beans.factory.InitializingBean; | |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | + | |
| 22 | +import javax.sip.InvalidArgumentException; | |
| 23 | +import javax.sip.RequestEvent; | |
| 24 | +import javax.sip.SipException; | |
| 25 | +import javax.sip.header.FromHeader; | |
| 26 | +import javax.sip.message.Response; | |
| 27 | +import java.text.ParseException; | |
| 28 | +import java.util.List; | |
| 29 | + | |
| 30 | +public class CatalogMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 31 | + | |
| 32 | + private Logger logger = LoggerFactory.getLogger(CatalogMessageHandler.class); | |
| 33 | + private final String cmdType = "Catalog"; | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private QueryMessageHandler queryMessageHandler; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private IVideoManagerStorager storager; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + private SIPCommanderFroPlatform cmderFroPlatform; | |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + private SipConfig config; | |
| 46 | + | |
| 47 | + @Autowired | |
| 48 | + private EventPublisher publisher; | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void afterPropertiesSet() throws Exception { | |
| 52 | + queryMessageHandler.addHandler(cmdType, this); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 57 | + | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 62 | + | |
| 63 | + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + parentPlatform.getServerGBId(); | |
| 64 | + FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | |
| 65 | + try { | |
| 66 | + // 回复200 OK | |
| 67 | + responseAck(evt, Response.OK); | |
| 68 | + Element snElement = rootElement.element("SN"); | |
| 69 | + String sn = snElement.getText(); | |
| 70 | + // 准备回复通道信息 | |
| 71 | + List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); | |
| 72 | + // 查询关联的直播通道 | |
| 73 | + List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); | |
| 74 | + int size = channelReduces.size() + gbStreams.size(); | |
| 75 | + // 回复级联的通道 | |
| 76 | + if (channelReduces.size() > 0) { | |
| 77 | + for (ChannelReduce channelReduce : channelReduces) { | |
| 78 | + DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); | |
| 79 | + cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + // 回复直播的通道 | |
| 83 | + if (gbStreams.size() > 0) { | |
| 84 | + for (GbStream gbStream : gbStreams) { | |
| 85 | + DeviceChannel deviceChannel = new DeviceChannel(); | |
| 86 | + deviceChannel.setChannelId(gbStream.getGbId()); | |
| 87 | + deviceChannel.setName(gbStream.getName()); | |
| 88 | + deviceChannel.setLongitude(gbStream.getLongitude()); | |
| 89 | + deviceChannel.setLatitude(gbStream.getLatitude()); | |
| 90 | + deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); | |
| 91 | + deviceChannel.setManufacture("wvp-pro"); | |
| 92 | + deviceChannel.setStatus(gbStream.isStatus()?1:0); | |
| 93 | + // deviceChannel.setParentId(parentPlatform.getDeviceGBId()); | |
| 94 | + deviceChannel.setRegisterWay(1); | |
| 95 | + deviceChannel.setCivilCode(config.getDomain()); | |
| 96 | + deviceChannel.setModel("live"); | |
| 97 | + deviceChannel.setOwner("wvp-pro"); | |
| 98 | + deviceChannel.setParental(0); | |
| 99 | + deviceChannel.setSecrecy("0"); | |
| 100 | + deviceChannel.setSecrecy("0"); | |
| 101 | + | |
| 102 | + cmderFroPlatform.catalogQuery(deviceChannel, parentPlatform, sn, fromHeader.getTag(), size); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + if (size == 0) { | |
| 106 | + // 回复无通道 | |
| 107 | + cmderFroPlatform.catalogQuery(null, parentPlatform, sn, fromHeader.getTag(), size); | |
| 108 | + } | |
| 109 | + } catch (SipException e) { | |
| 110 | + e.printStackTrace(); | |
| 111 | + } catch (InvalidArgumentException e) { | |
| 112 | + e.printStackTrace(); | |
| 113 | + } catch (ParseException e) { | |
| 114 | + e.printStackTrace(); | |
| 115 | + } | |
| 116 | + | |
| 117 | + } | |
| 118 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceControlMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.VManageBootstrap; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 12 | +import com.genersoft.iot.vmp.utils.SpringBeanFactory; | |
| 13 | +import gov.nist.javax.sip.SipStackImpl; | |
| 14 | +import org.dom4j.Element; | |
| 15 | +import org.slf4j.Logger; | |
| 16 | +import org.slf4j.LoggerFactory; | |
| 17 | +import org.springframework.beans.factory.InitializingBean; | |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 19 | +import org.springframework.util.StringUtils; | |
| 20 | + | |
| 21 | +import javax.sip.ListeningPoint; | |
| 22 | +import javax.sip.ObjectInUseException; | |
| 23 | +import javax.sip.RequestEvent; | |
| 24 | +import javax.sip.SipProvider; | |
| 25 | +import javax.sip.address.SipURI; | |
| 26 | +import javax.sip.header.HeaderAddress; | |
| 27 | +import javax.sip.header.ToHeader; | |
| 28 | +import java.util.Iterator; | |
| 29 | + | |
| 30 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 31 | + | |
| 32 | +public class DeviceControlMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 33 | + | |
| 34 | + private Logger logger = LoggerFactory.getLogger(DeviceControlMessageHandler.class); | |
| 35 | + private final String cmdType = "DeviceControl"; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private QueryMessageHandler queryMessageHandler; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private IVideoManagerStorager storager; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private SIPCommander cmder; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private SIPCommanderFroPlatform cmderFroPlatform; | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void afterPropertiesSet() throws Exception { | |
| 51 | + queryMessageHandler.addHandler(cmdType, this); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 56 | + | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 61 | + | |
| 62 | + // 此处是上级发出的DeviceControl指令 | |
| 63 | + String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser(); | |
| 64 | + String channelId = getText(rootElement, "DeviceID"); | |
| 65 | + // 远程启动功能 | |
| 66 | + if (!StringUtils.isEmpty(getText(rootElement, "TeleBoot"))) { | |
| 67 | + if (parentPlatform.getServerGBId().equals(targetGBId)) { | |
| 68 | + // 远程启动本平台:需要在重新启动程序后先对SipStack解绑 | |
| 69 | + logger.info("执行远程启动本平台命令"); | |
| 70 | + cmderFroPlatform.unregister(parentPlatform, null, null); | |
| 71 | + | |
| 72 | + Thread restartThread = new Thread(new Runnable() { | |
| 73 | + @Override | |
| 74 | + public void run() { | |
| 75 | + try { | |
| 76 | + Thread.sleep(3000); | |
| 77 | + SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider"); | |
| 78 | + SipStackImpl stack = (SipStackImpl)up.getSipStack(); | |
| 79 | + stack.stop(); | |
| 80 | + Iterator listener = stack.getListeningPoints(); | |
| 81 | + while (listener.hasNext()) { | |
| 82 | + stack.deleteListeningPoint((ListeningPoint) listener.next()); | |
| 83 | + } | |
| 84 | + Iterator providers = stack.getSipProviders(); | |
| 85 | + while (providers.hasNext()) { | |
| 86 | + stack.deleteSipProvider((SipProvider) providers.next()); | |
| 87 | + } | |
| 88 | + VManageBootstrap.restart(); | |
| 89 | + } catch (InterruptedException ignored) { | |
| 90 | + } catch (ObjectInUseException e) { | |
| 91 | + e.printStackTrace(); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + }); | |
| 95 | + | |
| 96 | + restartThread.setDaemon(false); | |
| 97 | + restartThread.start(); | |
| 98 | + } else { | |
| 99 | + // 远程启动指定设备 | |
| 100 | + } | |
| 101 | + } | |
| 102 | + // 云台/前端控制命令 | |
| 103 | + if (!StringUtils.isEmpty(getText(rootElement,"PTZCmd")) && !parentPlatform.getServerGBId().equals(targetGBId)) { | |
| 104 | + String cmdString = getText(rootElement,"PTZCmd"); | |
| 105 | + Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId); | |
| 106 | + cmder.fronEndCmd(deviceForPlatform, channelId, cmdString); | |
| 107 | + } | |
| 108 | + } | |
| 109 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceInfoMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler; | |
| 9 | +import org.dom4j.Element; | |
| 10 | +import org.slf4j.Logger; | |
| 11 | +import org.slf4j.LoggerFactory; | |
| 12 | +import org.springframework.beans.factory.InitializingBean; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | + | |
| 15 | +import javax.sip.InvalidArgumentException; | |
| 16 | +import javax.sip.RequestEvent; | |
| 17 | +import javax.sip.SipException; | |
| 18 | +import javax.sip.header.FromHeader; | |
| 19 | +import javax.sip.message.Response; | |
| 20 | +import java.text.ParseException; | |
| 21 | + | |
| 22 | +public class DeviceInfoMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 23 | + | |
| 24 | + private Logger logger = LoggerFactory.getLogger(DeviceInfoMessageHandler.class); | |
| 25 | + private final String cmdType = "DeviceInfo"; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private QueryMessageHandler queryMessageHandler; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private SIPCommanderFroPlatform cmderFroPlatform; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void afterPropertiesSet() throws Exception { | |
| 35 | + queryMessageHandler.addHandler(cmdType, this); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 40 | + | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 45 | + logger.info("接收到DeviceInfo查询消息"); | |
| 46 | + FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | |
| 47 | + try { | |
| 48 | + // 回复200 OK | |
| 49 | + responseAck(evt, Response.OK); | |
| 50 | + } catch (SipException e) { | |
| 51 | + e.printStackTrace(); | |
| 52 | + } catch (InvalidArgumentException e) { | |
| 53 | + e.printStackTrace(); | |
| 54 | + } catch (ParseException e) { | |
| 55 | + e.printStackTrace(); | |
| 56 | + } | |
| 57 | + String sn = rootElement.element("SN").getText(); | |
| 58 | + cmderFroPlatform.deviceInfoResponse(parentPlatform, sn, fromHeader.getTag()); | |
| 59 | + } | |
| 60 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceStatusMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 12 | +import org.dom4j.Element; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | + | |
| 18 | +import javax.sip.InvalidArgumentException; | |
| 19 | +import javax.sip.RequestEvent; | |
| 20 | +import javax.sip.SipException; | |
| 21 | +import javax.sip.header.FromHeader; | |
| 22 | +import javax.sip.message.Response; | |
| 23 | +import java.text.ParseException; | |
| 24 | + | |
| 25 | +public class DeviceStatusMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 26 | + | |
| 27 | + private Logger logger = LoggerFactory.getLogger(DeviceStatusMessageHandler.class); | |
| 28 | + private final String cmdType = "DeviceStatus"; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private QueryMessageHandler queryMessageHandler; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + private IVideoManagerStorager storager; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + private SIPCommanderFroPlatform cmderFroPlatform; | |
| 38 | + | |
| 39 | + @Autowired | |
| 40 | + private SipConfig config; | |
| 41 | + | |
| 42 | + @Autowired | |
| 43 | + private EventPublisher publisher; | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void afterPropertiesSet() throws Exception { | |
| 47 | + queryMessageHandler.addHandler(cmdType, this); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 52 | + | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 57 | + | |
| 58 | + logger.info("接收到DeviceStatus查询消息"); | |
| 59 | + FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | |
| 60 | + // 回复200 OK | |
| 61 | + try { | |
| 62 | + responseAck(evt, Response.OK); | |
| 63 | + } catch (SipException e) { | |
| 64 | + e.printStackTrace(); | |
| 65 | + } catch (InvalidArgumentException e) { | |
| 66 | + e.printStackTrace(); | |
| 67 | + } catch (ParseException e) { | |
| 68 | + e.printStackTrace(); | |
| 69 | + } | |
| 70 | + String sn = rootElement.element("SN").getText(); | |
| 71 | + cmderFroPlatform.deviceStatusResponse(parentPlatform, sn, fromHeader.getTag()); | |
| 72 | + } | |
| 73 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/ResponseMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageRequestProcessor; | |
| 5 | +import org.springframework.beans.factory.InitializingBean; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +@Component | |
| 10 | +public class ResponseMessageHandler extends MessageHandlerAbstract implements InitializingBean { | |
| 11 | + | |
| 12 | + private final String messageType = "Response"; | |
| 13 | + | |
| 14 | + @Autowired | |
| 15 | + private MessageRequestProcessor messageRequestProcessor; | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + public void afterPropertiesSet() throws Exception { | |
| 19 | + messageRequestProcessor.addHandler(messageType, this); | |
| 20 | + } | |
| 21 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/AlarmMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 12 | +import org.dom4j.Element; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import javax.sip.RequestEvent; | |
| 20 | + | |
| 21 | +@Component | |
| 22 | +public class AlarmMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 23 | + | |
| 24 | + private Logger logger = LoggerFactory.getLogger(AlarmMessageHandler.class); | |
| 25 | + private final String cmdType = "Alarm"; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + private ResponseMessageHandler responseMessageHandler; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private DeferredResultHolder deferredResultHolder; | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public void afterPropertiesSet() throws Exception { | |
| 35 | + responseMessageHandler.addHandler(cmdType, this); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 40 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 41 | + String channelId = deviceIdElement.getText().toString(); | |
| 42 | + String key = DeferredResultHolder.CALLBACK_CMD_ALARM + device.getDeviceId() + channelId; | |
| 43 | + JSONObject json = new JSONObject(); | |
| 44 | + XmlUtil.node2Json(rootElement, json); | |
| 45 | + if (logger.isDebugEnabled()) { | |
| 46 | + logger.debug(json.toJSONString()); | |
| 47 | + } | |
| 48 | + RequestMessage msg = new RequestMessage(); | |
| 49 | + msg.setKey(key); | |
| 50 | + msg.setData(json); | |
| 51 | + deferredResultHolder.invokeAllResult(msg); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 56 | + | |
| 57 | + } | |
| 58 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/BroadcastMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 12 | +import org.dom4j.Element; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import javax.sip.InvalidArgumentException; | |
| 20 | +import javax.sip.RequestEvent; | |
| 21 | +import javax.sip.SipException; | |
| 22 | +import javax.sip.message.Response; | |
| 23 | +import java.text.ParseException; | |
| 24 | + | |
| 25 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 26 | + | |
| 27 | +@Component | |
| 28 | +public class BroadcastMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 29 | + | |
| 30 | + private Logger logger = LoggerFactory.getLogger(BroadcastMessageHandler.class); | |
| 31 | + private final String cmdType = "Broadcast"; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + private ResponseMessageHandler responseMessageHandler; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + private DeferredResultHolder deferredResultHolder; | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public void afterPropertiesSet() throws Exception { | |
| 41 | + responseMessageHandler.addHandler(cmdType, this); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 46 | + try { | |
| 47 | + String channelId = getText(rootElement, "DeviceID"); | |
| 48 | + String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + device.getDeviceId() + channelId; | |
| 49 | + // 回复200 OK | |
| 50 | + responseAck(evt, Response.OK); | |
| 51 | + // 此处是对本平台发出Broadcast指令的应答 | |
| 52 | + JSONObject json = new JSONObject(); | |
| 53 | + XmlUtil.node2Json(rootElement, json); | |
| 54 | + if (logger.isDebugEnabled()) { | |
| 55 | + logger.debug(json.toJSONString()); | |
| 56 | + } | |
| 57 | + RequestMessage msg = new RequestMessage(); | |
| 58 | + msg.setKey(key); | |
| 59 | + msg.setData(json); | |
| 60 | + deferredResultHolder.invokeAllResult(msg); | |
| 61 | + | |
| 62 | + | |
| 63 | + } catch (ParseException | SipException | InvalidArgumentException e) { | |
| 64 | + e.printStackTrace(); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 70 | + | |
| 71 | + } | |
| 72 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 4 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 14 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 15 | +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | |
| 16 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 17 | +import org.dom4j.DocumentException; | |
| 18 | +import org.dom4j.Element; | |
| 19 | +import org.slf4j.Logger; | |
| 20 | +import org.slf4j.LoggerFactory; | |
| 21 | +import org.springframework.beans.factory.InitializingBean; | |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 23 | +import org.springframework.stereotype.Component; | |
| 24 | + | |
| 25 | +import javax.sip.InvalidArgumentException; | |
| 26 | +import javax.sip.RequestEvent; | |
| 27 | +import javax.sip.SipException; | |
| 28 | +import javax.sip.message.Response; | |
| 29 | +import java.text.ParseException; | |
| 30 | +import java.util.Iterator; | |
| 31 | + | |
| 32 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 33 | + | |
| 34 | +@Component | |
| 35 | +public class CatalogMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 36 | + | |
| 37 | + private Logger logger = LoggerFactory.getLogger(CatalogMessageHandler.class); | |
| 38 | + private final String cmdType = "Catalog"; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private ResponseMessageHandler responseMessageHandler; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private IVideoManagerStorager storager; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private DeferredResultHolder deferredResultHolder; | |
| 48 | + | |
| 49 | + @Autowired | |
| 50 | + private DeviceOffLineDetector offLineDetector; | |
| 51 | + | |
| 52 | + @Autowired | |
| 53 | + private SipConfig config; | |
| 54 | + | |
| 55 | + @Autowired | |
| 56 | + private EventPublisher publisher; | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void afterPropertiesSet() throws Exception { | |
| 60 | + responseMessageHandler.addHandler(cmdType, this); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 65 | + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + device.getDeviceId(); | |
| 66 | + Element rootElement = null; | |
| 67 | + try { | |
| 68 | + rootElement = getRootElement(evt, device.getCharset()); | |
| 69 | + Element deviceListElement = rootElement.element("DeviceList"); | |
| 70 | + Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); | |
| 71 | + if (deviceListIterator != null) { | |
| 72 | + | |
| 73 | + // 遍历DeviceList | |
| 74 | + while (deviceListIterator.hasNext()) { | |
| 75 | + Element itemDevice = deviceListIterator.next(); | |
| 76 | + Element channelDeviceElement = itemDevice.element("DeviceID"); | |
| 77 | + if (channelDeviceElement == null) { | |
| 78 | + continue; | |
| 79 | + } | |
| 80 | + String channelDeviceId = channelDeviceElement.getText(); | |
| 81 | + Element channdelNameElement = itemDevice.element("Name"); | |
| 82 | + String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : ""; | |
| 83 | + Element statusElement = itemDevice.element("Status"); | |
| 84 | + String status = statusElement != null ? statusElement.getText().toString() : "ON"; | |
| 85 | + DeviceChannel deviceChannel = new DeviceChannel(); | |
| 86 | + deviceChannel.setName(channelName); | |
| 87 | + deviceChannel.setChannelId(channelDeviceId); | |
| 88 | + // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 | |
| 89 | + if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) { | |
| 90 | + deviceChannel.setStatus(1); | |
| 91 | + } | |
| 92 | + if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { | |
| 93 | + deviceChannel.setStatus(0); | |
| 94 | + } | |
| 95 | + | |
| 96 | + deviceChannel.setManufacture(getText(itemDevice, "Manufacturer")); | |
| 97 | + deviceChannel.setModel(getText(itemDevice, "Model")); | |
| 98 | + deviceChannel.setOwner(getText(itemDevice, "Owner")); | |
| 99 | + deviceChannel.setCivilCode(getText(itemDevice, "CivilCode")); | |
| 100 | + deviceChannel.setBlock(getText(itemDevice, "Block")); | |
| 101 | + deviceChannel.setAddress(getText(itemDevice, "Address")); | |
| 102 | + if (getText(itemDevice, "Parental") == null || getText(itemDevice, "Parental") == "") { | |
| 103 | + deviceChannel.setParental(0); | |
| 104 | + } else { | |
| 105 | + deviceChannel.setParental(Integer.parseInt(getText(itemDevice, "Parental"))); | |
| 106 | + } | |
| 107 | + deviceChannel.setParentId(getText(itemDevice, "ParentID")); | |
| 108 | + if (getText(itemDevice, "SafetyWay") == null || getText(itemDevice, "SafetyWay") == "") { | |
| 109 | + deviceChannel.setSafetyWay(0); | |
| 110 | + } else { | |
| 111 | + deviceChannel.setSafetyWay(Integer.parseInt(getText(itemDevice, "SafetyWay"))); | |
| 112 | + } | |
| 113 | + if (getText(itemDevice, "RegisterWay") == null || getText(itemDevice, "RegisterWay") == "") { | |
| 114 | + deviceChannel.setRegisterWay(1); | |
| 115 | + } else { | |
| 116 | + deviceChannel.setRegisterWay(Integer.parseInt(getText(itemDevice, "RegisterWay"))); | |
| 117 | + } | |
| 118 | + deviceChannel.setCertNum(getText(itemDevice, "CertNum")); | |
| 119 | + if (getText(itemDevice, "Certifiable") == null || getText(itemDevice, "Certifiable") == "") { | |
| 120 | + deviceChannel.setCertifiable(0); | |
| 121 | + } else { | |
| 122 | + deviceChannel.setCertifiable(Integer.parseInt(getText(itemDevice, "Certifiable"))); | |
| 123 | + } | |
| 124 | + if (getText(itemDevice, "ErrCode") == null || getText(itemDevice, "ErrCode") == "") { | |
| 125 | + deviceChannel.setErrCode(0); | |
| 126 | + } else { | |
| 127 | + deviceChannel.setErrCode(Integer.parseInt(getText(itemDevice, "ErrCode"))); | |
| 128 | + } | |
| 129 | + deviceChannel.setEndTime(getText(itemDevice, "EndTime")); | |
| 130 | + deviceChannel.setSecrecy(getText(itemDevice, "Secrecy")); | |
| 131 | + deviceChannel.setIpAddress(getText(itemDevice, "IPAddress")); | |
| 132 | + if (getText(itemDevice, "Port") == null || getText(itemDevice, "Port") == "") { | |
| 133 | + deviceChannel.setPort(0); | |
| 134 | + } else { | |
| 135 | + deviceChannel.setPort(Integer.parseInt(getText(itemDevice, "Port"))); | |
| 136 | + } | |
| 137 | + deviceChannel.setPassword(getText(itemDevice, "Password")); | |
| 138 | + if (NumericUtil.isDouble(getText(itemDevice, "Longitude"))) { | |
| 139 | + deviceChannel.setLongitude(Double.parseDouble(getText(itemDevice, "Longitude"))); | |
| 140 | + } else { | |
| 141 | + deviceChannel.setLongitude(0.00); | |
| 142 | + } | |
| 143 | + if (NumericUtil.isDouble(getText(itemDevice, "Latitude"))) { | |
| 144 | + deviceChannel.setLatitude(Double.parseDouble(getText(itemDevice, "Latitude"))); | |
| 145 | + } else { | |
| 146 | + deviceChannel.setLatitude(0.00); | |
| 147 | + } | |
| 148 | + if (getText(itemDevice, "PTZType") == null || getText(itemDevice, "PTZType") == "") { | |
| 149 | + deviceChannel.setPTZType(0); | |
| 150 | + } else { | |
| 151 | + deviceChannel.setPTZType(Integer.parseInt(getText(itemDevice, "PTZType"))); | |
| 152 | + } | |
| 153 | + deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC | |
| 154 | + storager.updateChannel(device.getDeviceId(), deviceChannel); | |
| 155 | + } | |
| 156 | + | |
| 157 | + RequestMessage msg = new RequestMessage(); | |
| 158 | + msg.setKey(key); | |
| 159 | + msg.setData(device); | |
| 160 | + deferredResultHolder.invokeAllResult(msg); | |
| 161 | + // 回复200 OK | |
| 162 | + responseAck(evt, Response.OK); | |
| 163 | + if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 164 | + publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | |
| 165 | + } | |
| 166 | + } | |
| 167 | + } catch (DocumentException e) { | |
| 168 | + e.printStackTrace(); | |
| 169 | + } catch (InvalidArgumentException e) { | |
| 170 | + e.printStackTrace(); | |
| 171 | + } catch (ParseException e) { | |
| 172 | + e.printStackTrace(); | |
| 173 | + } catch (SipException e) { | |
| 174 | + e.printStackTrace(); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + | |
| 178 | + @Override | |
| 179 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 180 | + | |
| 181 | + } | |
| 182 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/ConfigDownloadMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 13 | +import org.dom4j.Element; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 16 | +import org.springframework.beans.factory.InitializingBean; | |
| 17 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | + | |
| 20 | +import javax.sip.InvalidArgumentException; | |
| 21 | +import javax.sip.RequestEvent; | |
| 22 | +import javax.sip.SipException; | |
| 23 | +import javax.sip.message.Response; | |
| 24 | +import java.text.ParseException; | |
| 25 | + | |
| 26 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 27 | + | |
| 28 | +@Component | |
| 29 | +public class ConfigDownloadMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 30 | + | |
| 31 | + private Logger logger = LoggerFactory.getLogger(ConfigDownloadMessageHandler.class); | |
| 32 | + private final String cmdType = "ConfigDownload"; | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + private ResponseMessageHandler responseMessageHandler; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private EventPublisher publisher; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private DeferredResultHolder deferredResultHolder; | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void afterPropertiesSet() throws Exception { | |
| 45 | + responseMessageHandler.addHandler(cmdType, this); | |
| 46 | + } | |
| 47 | + | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 51 | + String channelId = getText(element, "DeviceID"); | |
| 52 | + String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + device.getDeviceId() + channelId; | |
| 53 | + try { | |
| 54 | + // 回复200 OK | |
| 55 | + responseAck(evt, Response.OK); | |
| 56 | + // 此处是对本平台发出DeviceControl指令的应答 | |
| 57 | + JSONObject json = new JSONObject(); | |
| 58 | + XmlUtil.node2Json(element, json); | |
| 59 | + if (logger.isDebugEnabled()) { | |
| 60 | + logger.debug(json.toJSONString()); | |
| 61 | + } | |
| 62 | + RequestMessage msg = new RequestMessage(); | |
| 63 | + msg.setKey(key); | |
| 64 | + msg.setData(json); | |
| 65 | + deferredResultHolder.invokeAllResult(msg); | |
| 66 | + } catch (SipException e) { | |
| 67 | + e.printStackTrace(); | |
| 68 | + } catch (InvalidArgumentException e) { | |
| 69 | + e.printStackTrace(); | |
| 70 | + } catch (ParseException e) { | |
| 71 | + e.printStackTrace(); | |
| 72 | + } | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 78 | + // 不会收到上级平台的心跳信息 | |
| 79 | + | |
| 80 | + } | |
| 81 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceConfigMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 12 | +import org.dom4j.Element; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import javax.sip.RequestEvent; | |
| 20 | + | |
| 21 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 22 | + | |
| 23 | +@Component | |
| 24 | +public class DeviceConfigMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 25 | + | |
| 26 | + private Logger logger = LoggerFactory.getLogger(DeviceConfigMessageHandler.class); | |
| 27 | + private final String cmdType = "DeviceConfig"; | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + private ResponseMessageHandler responseMessageHandler; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private DeferredResultHolder deferredResultHolder; | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void afterPropertiesSet() throws Exception { | |
| 37 | + responseMessageHandler.addHandler(cmdType, this); | |
| 38 | + } | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 42 | + JSONObject json = new JSONObject(); | |
| 43 | + XmlUtil.node2Json(element, json); | |
| 44 | + String channelId = getText(element, "DeviceID"); | |
| 45 | + if (logger.isDebugEnabled()) { | |
| 46 | + logger.debug(json.toJSONString()); | |
| 47 | + } | |
| 48 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + device.getDeviceId() + channelId; | |
| 49 | + RequestMessage msg = new RequestMessage(); | |
| 50 | + msg.setKey(key); | |
| 51 | + msg.setData(json); | |
| 52 | + deferredResultHolder.invokeAllResult(msg); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Override | |
| 56 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 57 | + } | |
| 58 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 12 | +import org.dom4j.Element; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.stereotype.Component; | |
| 18 | + | |
| 19 | +import javax.sip.RequestEvent; | |
| 20 | + | |
| 21 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 22 | + | |
| 23 | +@Component | |
| 24 | +public class DeviceControlMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 25 | + | |
| 26 | + private Logger logger = LoggerFactory.getLogger(DeviceControlMessageHandler.class); | |
| 27 | + private final String cmdType = "DeviceControl"; | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + private ResponseMessageHandler responseMessageHandler; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private DeferredResultHolder deferredResultHolder; | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void afterPropertiesSet() throws Exception { | |
| 37 | + responseMessageHandler.addHandler(cmdType, this); | |
| 38 | + } | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 42 | + // 此处是对本平台发出DeviceControl指令的应答 | |
| 43 | + JSONObject json = new JSONObject(); | |
| 44 | + String channelId = getText(element, "DeviceID"); | |
| 45 | + XmlUtil.node2Json(element, json); | |
| 46 | + if (logger.isDebugEnabled()) { | |
| 47 | + logger.debug(json.toJSONString()); | |
| 48 | + } | |
| 49 | + RequestMessage msg = new RequestMessage(); | |
| 50 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; | |
| 51 | + msg.setKey(key); | |
| 52 | + msg.setData(json); | |
| 53 | + deferredResultHolder.invokeAllResult(msg); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 58 | + } | |
| 59 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 4 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 14 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 15 | +import org.dom4j.DocumentException; | |
| 16 | +import org.dom4j.Element; | |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 19 | +import org.springframework.beans.factory.InitializingBean; | |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | +import org.springframework.stereotype.Component; | |
| 22 | +import org.springframework.util.StringUtils; | |
| 23 | + | |
| 24 | +import javax.sip.InvalidArgumentException; | |
| 25 | +import javax.sip.RequestEvent; | |
| 26 | +import javax.sip.SipException; | |
| 27 | +import javax.sip.message.Response; | |
| 28 | +import java.text.ParseException; | |
| 29 | + | |
| 30 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 31 | + | |
| 32 | +@Component | |
| 33 | +public class DeviceInfoMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 34 | + | |
| 35 | + private Logger logger = LoggerFactory.getLogger(DeviceInfoMessageHandler.class); | |
| 36 | + private final String cmdType = "DeviceInfo"; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private ResponseMessageHandler responseMessageHandler; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + private IVideoManagerStorager storager; | |
| 43 | + | |
| 44 | + @Autowired | |
| 45 | + private DeferredResultHolder deferredResultHolder; | |
| 46 | + | |
| 47 | + @Autowired | |
| 48 | + private DeviceOffLineDetector offLineDetector; | |
| 49 | + | |
| 50 | + @Autowired | |
| 51 | + private SipConfig config; | |
| 52 | + | |
| 53 | + @Autowired | |
| 54 | + private EventPublisher publisher; | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public void afterPropertiesSet() throws Exception { | |
| 58 | + responseMessageHandler.addHandler(cmdType, this); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Override | |
| 62 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 63 | + logger.debug("接收到DeviceInfo应答消息"); | |
| 64 | + try { | |
| 65 | + rootElement = getRootElement(evt, device.getCharset()); | |
| 66 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 67 | + String channelId = deviceIdElement.getTextTrim(); | |
| 68 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + device.getDeviceId() + channelId; | |
| 69 | + device.setName(getText(rootElement, "DeviceName")); | |
| 70 | + | |
| 71 | + device.setManufacturer(getText(rootElement, "Manufacturer")); | |
| 72 | + device.setModel(getText(rootElement, "Model")); | |
| 73 | + device.setFirmware(getText(rootElement, "Firmware")); | |
| 74 | + if (StringUtils.isEmpty(device.getStreamMode())) { | |
| 75 | + device.setStreamMode("UDP"); | |
| 76 | + } | |
| 77 | + storager.updateDevice(device); | |
| 78 | + | |
| 79 | + RequestMessage msg = new RequestMessage(); | |
| 80 | + msg.setKey(key); | |
| 81 | + msg.setData(device); | |
| 82 | + deferredResultHolder.invokeAllResult(msg); | |
| 83 | + // 回复200 OK | |
| 84 | + responseAck(evt, Response.OK); | |
| 85 | + if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 86 | + publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | |
| 87 | + } | |
| 88 | + } catch (DocumentException e) { | |
| 89 | + e.printStackTrace(); | |
| 90 | + } catch (InvalidArgumentException e) { | |
| 91 | + e.printStackTrace(); | |
| 92 | + } catch (ParseException e) { | |
| 93 | + e.printStackTrace(); | |
| 94 | + } catch (SipException e) { | |
| 95 | + e.printStackTrace(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 101 | + | |
| 102 | + } | |
| 103 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 4 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 14 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 15 | +import org.dom4j.Element; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.factory.InitializingBean; | |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | +import org.springframework.stereotype.Component; | |
| 21 | + | |
| 22 | +import javax.sip.InvalidArgumentException; | |
| 23 | +import javax.sip.RequestEvent; | |
| 24 | +import javax.sip.SipException; | |
| 25 | +import javax.sip.message.Response; | |
| 26 | +import java.text.ParseException; | |
| 27 | + | |
| 28 | +@Component | |
| 29 | +public class DeviceStatusMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 30 | + | |
| 31 | + private Logger logger = LoggerFactory.getLogger(DeviceStatusMessageHandler.class); | |
| 32 | + private final String cmdType = "DeviceStatus"; | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + private ResponseMessageHandler responseMessageHandler; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private DeviceOffLineDetector offLineDetector; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private DeferredResultHolder deferredResultHolder; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private EventPublisher publisher; | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void afterPropertiesSet() throws Exception { | |
| 48 | + responseMessageHandler.addHandler(cmdType, this); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public void handForDevice(RequestEvent evt, Device device, Element element) { | |
| 53 | + logger.info("接收到DeviceStatus应答消息"); | |
| 54 | + // 检查设备是否存在, 不存在则不回复 | |
| 55 | + // 回复200 OK | |
| 56 | + try { | |
| 57 | + responseAck(evt, Response.OK); | |
| 58 | + } catch (SipException e) { | |
| 59 | + e.printStackTrace(); | |
| 60 | + } catch (InvalidArgumentException e) { | |
| 61 | + e.printStackTrace(); | |
| 62 | + } catch (ParseException e) { | |
| 63 | + e.printStackTrace(); | |
| 64 | + } | |
| 65 | + Element deviceIdElement = element.element("DeviceID"); | |
| 66 | + String channelId = deviceIdElement.getText(); | |
| 67 | + JSONObject json = new JSONObject(); | |
| 68 | + XmlUtil.node2Json(element, json); | |
| 69 | + if (logger.isDebugEnabled()) { | |
| 70 | + logger.debug(json.toJSONString()); | |
| 71 | + } | |
| 72 | + RequestMessage msg = new RequestMessage(); | |
| 73 | + msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId() + channelId); | |
| 74 | + msg.setData(json); | |
| 75 | + deferredResultHolder.invokeAllResult(msg); | |
| 76 | + | |
| 77 | + if (offLineDetector.isOnline(device.getDeviceId())) { | |
| 78 | + publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | |
| 79 | + } else { | |
| 80 | + | |
| 81 | + } | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { | |
| 86 | + | |
| 87 | + | |
| 88 | + } | |
| 89 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.UserSetup; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.BaiduPoint; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; | |
| 12 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 13 | +import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 14 | +import org.dom4j.DocumentException; | |
| 15 | +import org.dom4j.Element; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.factory.InitializingBean; | |
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 20 | +import org.springframework.stereotype.Component; | |
| 21 | +import org.springframework.util.StringUtils; | |
| 22 | + | |
| 23 | +import javax.sip.InvalidArgumentException; | |
| 24 | +import javax.sip.RequestEvent; | |
| 25 | +import javax.sip.SipException; | |
| 26 | +import javax.sip.message.Response; | |
| 27 | +import java.text.ParseException; | |
| 28 | + | |
| 29 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 30 | + | |
| 31 | +@Component | |
| 32 | +public class MobilePositionMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 33 | + | |
| 34 | + private Logger logger = LoggerFactory.getLogger(MobilePositionMessageHandler.class); | |
| 35 | + private final String cmdType = "MobilePosition"; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private ResponseMessageHandler responseMessageHandler; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + private UserSetup userSetup; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private IVideoManagerStorager storager; | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void afterPropertiesSet() throws Exception { | |
| 48 | + responseMessageHandler.addHandler(cmdType, this); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Override | |
| 52 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 53 | + | |
| 54 | + try { | |
| 55 | + rootElement = getRootElement(evt, device.getCharset()); | |
| 56 | + | |
| 57 | + MobilePosition mobilePosition = new MobilePosition(); | |
| 58 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 59 | + mobilePosition.setDeviceName(device.getName()); | |
| 60 | + } | |
| 61 | + mobilePosition.setDeviceId(device.getDeviceId()); | |
| 62 | + mobilePosition.setChannelId(getText(rootElement, "DeviceID")); | |
| 63 | + mobilePosition.setTime(getText(rootElement, "Time")); | |
| 64 | + mobilePosition.setLongitude(Double.parseDouble(getText(rootElement, "Longitude"))); | |
| 65 | + mobilePosition.setLatitude(Double.parseDouble(getText(rootElement, "Latitude"))); | |
| 66 | + if (NumericUtil.isDouble(getText(rootElement, "Speed"))) { | |
| 67 | + mobilePosition.setSpeed(Double.parseDouble(getText(rootElement, "Speed"))); | |
| 68 | + } else { | |
| 69 | + mobilePosition.setSpeed(0.0); | |
| 70 | + } | |
| 71 | + if (NumericUtil.isDouble(getText(rootElement, "Direction"))) { | |
| 72 | + mobilePosition.setDirection(Double.parseDouble(getText(rootElement, "Direction"))); | |
| 73 | + } else { | |
| 74 | + mobilePosition.setDirection(0.0); | |
| 75 | + } | |
| 76 | + if (NumericUtil.isDouble(getText(rootElement, "Altitude"))) { | |
| 77 | + mobilePosition.setAltitude(Double.parseDouble(getText(rootElement, "Altitude"))); | |
| 78 | + } else { | |
| 79 | + mobilePosition.setAltitude(0.0); | |
| 80 | + } | |
| 81 | + mobilePosition.setReportSource("Mobile Position"); | |
| 82 | + BaiduPoint bp = new BaiduPoint(); | |
| 83 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | |
| 84 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | |
| 85 | + mobilePosition.setGeodeticSystem("BD-09"); | |
| 86 | + mobilePosition.setCnLng(bp.getBdLng()); | |
| 87 | + mobilePosition.setCnLat(bp.getBdLat()); | |
| 88 | + if (!userSetup.getSavePositionHistory()) { | |
| 89 | + storager.clearMobilePositionsByDeviceId(device.getDeviceId()); | |
| 90 | + } | |
| 91 | + storager.insertMobilePosition(mobilePosition); | |
| 92 | + //回复 200 OK | |
| 93 | + responseAck(evt, Response.OK); | |
| 94 | + } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | |
| 95 | + e.printStackTrace(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 101 | + | |
| 102 | + } | |
| 103 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoMessageHandler.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.RecordItem; | |
| 7 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; | |
| 12 | +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.utils.DateUtil; | |
| 14 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 15 | +import org.dom4j.DocumentException; | |
| 16 | +import org.dom4j.Element; | |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 19 | +import org.springframework.beans.factory.InitializingBean; | |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | +import org.springframework.stereotype.Component; | |
| 22 | + | |
| 23 | +import javax.sip.InvalidArgumentException; | |
| 24 | +import javax.sip.RequestEvent; | |
| 25 | +import javax.sip.SipException; | |
| 26 | +import javax.sip.message.Response; | |
| 27 | +import java.text.ParseException; | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.Iterator; | |
| 30 | +import java.util.List; | |
| 31 | +import java.util.UUID; | |
| 32 | + | |
| 33 | +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; | |
| 34 | + | |
| 35 | +@Component | |
| 36 | +public class RecordInfoMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | |
| 37 | + | |
| 38 | + private Logger logger = LoggerFactory.getLogger(RecordInfoMessageHandler.class); | |
| 39 | + public static volatile List<String> threadNameList = new ArrayList(); | |
| 40 | + private final String cmdType = "RecordInfo"; | |
| 41 | + private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_"; | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private ResponseMessageHandler responseMessageHandler; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private RedisUtil redis; | |
| 48 | + | |
| 49 | + @Autowired | |
| 50 | + private DeferredResultHolder deferredResultHolder; | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public void afterPropertiesSet() throws Exception { | |
| 54 | + responseMessageHandler.addHandler(cmdType, this); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + public void handForDevice(RequestEvent evt, Device device, Element rootElement) { | |
| 59 | + | |
| 60 | + // 回复200 OK | |
| 61 | + try { | |
| 62 | + responseAck(evt, Response.OK); | |
| 63 | + | |
| 64 | + rootElement = getRootElement(evt, device.getCharset()); | |
| 65 | + String uuid = UUID.randomUUID().toString().replace("-", ""); | |
| 66 | + RecordInfo recordInfo = new RecordInfo(); | |
| 67 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 68 | + String channelId = deviceIdElement.getText(); | |
| 69 | + String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + device.getDeviceId() + channelId; | |
| 70 | + recordInfo.setDeviceId(device.getDeviceId()); | |
| 71 | + recordInfo.setChannelId(channelId); | |
| 72 | + recordInfo.setName(getText(rootElement, "Name")); | |
| 73 | + if (getText(rootElement, "SumNum") == null || getText(rootElement, "SumNum") == "") { | |
| 74 | + recordInfo.setSumNum(0); | |
| 75 | + } else { | |
| 76 | + recordInfo.setSumNum(Integer.parseInt(getText(rootElement, "SumNum"))); | |
| 77 | + } | |
| 78 | + String sn = getText(rootElement, "SN"); | |
| 79 | + Element recordListElement = rootElement.element("RecordList"); | |
| 80 | + if (recordListElement == null || recordInfo.getSumNum() == 0) { | |
| 81 | + logger.info("无录像数据"); | |
| 82 | + RequestMessage msg = new RequestMessage(); | |
| 83 | + msg.setKey(key); | |
| 84 | + msg.setData(recordInfo); | |
| 85 | + deferredResultHolder.invokeAllResult(msg); | |
| 86 | + } else { | |
| 87 | + Iterator<Element> recordListIterator = recordListElement.elementIterator(); | |
| 88 | + List<RecordItem> recordList = new ArrayList<RecordItem>(); | |
| 89 | + if (recordListIterator != null) { | |
| 90 | + RecordItem record = new RecordItem(); | |
| 91 | + logger.info("处理录像列表数据..."); | |
| 92 | + // 遍历DeviceList | |
| 93 | + while (recordListIterator.hasNext()) { | |
| 94 | + Element itemRecord = recordListIterator.next(); | |
| 95 | + Element recordElement = itemRecord.element("DeviceID"); | |
| 96 | + if (recordElement == null) { | |
| 97 | + logger.info("记录为空,下一个..."); | |
| 98 | + continue; | |
| 99 | + } | |
| 100 | + record = new RecordItem(); | |
| 101 | + record.setDeviceId(getText(itemRecord, "DeviceID")); | |
| 102 | + record.setName(getText(itemRecord, "Name")); | |
| 103 | + record.setFilePath(getText(itemRecord, "FilePath")); | |
| 104 | + record.setAddress(getText(itemRecord, "Address")); | |
| 105 | + record.setStartTime( | |
| 106 | + DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "StartTime"))); | |
| 107 | + record.setEndTime( | |
| 108 | + DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "EndTime"))); | |
| 109 | + record.setSecrecy(itemRecord.element("Secrecy") == null ? 0 | |
| 110 | + : Integer.parseInt(getText(itemRecord, "Secrecy"))); | |
| 111 | + record.setType(getText(itemRecord, "Type")); | |
| 112 | + record.setRecorderId(getText(itemRecord, "RecorderID")); | |
| 113 | + recordList.add(record); | |
| 114 | + } | |
| 115 | + recordInfo.setRecordList(recordList); | |
| 116 | + } | |
| 117 | + | |
| 118 | + // 改用单独线程统计已获取录像文件数量,避免多包并行分别统计不完整的问题 | |
| 119 | + String cacheKey = CACHE_RECORDINFO_KEY + device.getDeviceId() + sn; | |
| 120 | + redis.set(cacheKey + "_" + uuid, recordList, 90); | |
| 121 | + if (!threadNameList.contains(cacheKey)) { | |
| 122 | + threadNameList.add(cacheKey); | |
| 123 | + CheckForAllRecordsThread chk = new CheckForAllRecordsThread(cacheKey, recordInfo); | |
| 124 | + chk.setName(cacheKey); | |
| 125 | + chk.setDeferredResultHolder(deferredResultHolder); | |
| 126 | + chk.setRedis(redis); | |
| 127 | + chk.setLogger(logger); | |
| 128 | + chk.start(); | |
| 129 | + if (logger.isDebugEnabled()) { | |
| 130 | + logger.debug("Start Thread " + cacheKey + "."); | |
| 131 | + } | |
| 132 | + } else { | |
| 133 | + if (logger.isDebugEnabled()) { | |
| 134 | + logger.debug("Thread " + cacheKey + " already started."); | |
| 135 | + } | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } catch (SipException e) { | |
| 139 | + e.printStackTrace(); | |
| 140 | + } catch (InvalidArgumentException e) { | |
| 141 | + e.printStackTrace(); | |
| 142 | + } catch (ParseException e) { | |
| 143 | + e.printStackTrace(); | |
| 144 | + } catch (DocumentException e) { | |
| 145 | + e.printStackTrace(); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 150 | + public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) { | |
| 151 | + | |
| 152 | + } | |
| 153 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
| 1 | 1 | package com.genersoft.iot.vmp.storager; |
| 2 | 2 | |
| 3 | -import java.util.List; | |
| 4 | - | |
| 5 | 3 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 6 | 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| ... | ... | @@ -9,6 +7,8 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 9 | 7 | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| 10 | 8 | import com.github.pagehelper.PageInfo; |
| 11 | 9 | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | 12 | /** |
| 13 | 13 | * @description:视频设备数据存储接口 |
| 14 | 14 | * @author: swwheihei |
| ... | ... | @@ -373,7 +373,18 @@ public interface IVideoManagerStorager { |
| 373 | 373 | */ |
| 374 | 374 | void updateMediaServer(MediaServerItem mediaServerItem); |
| 375 | 375 | |
| 376 | + /** | |
| 377 | + * 根据媒体ID获取启用/不启用的代理列表 | |
| 378 | + * @param id 媒体ID | |
| 379 | + * @param b 启用/不启用 | |
| 380 | + * @return | |
| 381 | + */ | |
| 376 | 382 | List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean b); |
| 377 | 383 | |
| 378 | - Device queryVideoDeviceByChannelId(String platformGbId); | |
| 384 | + /** | |
| 385 | + * 根据通道ID获取其所在设备 | |
| 386 | + * @param channelId 通道ID | |
| 387 | + * @return | |
| 388 | + */ | |
| 389 | + Device queryVideoDeviceByChannelId(String channelId); | |
| 379 | 390 | } | ... | ... |