|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.sip.InvalidArgumentException; | 
|---|
|  |  |  | import javax.sip.RequestEvent; | 
|---|
|  |  |  | import javax.sip.ServerTransaction; | 
|---|
|  |  |  | import javax.sip.SipException; | 
|---|
|  |  |  | import javax.sip.message.Request; | 
|---|
|  |  |  | import javax.sip.message.Response; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private SIPCommander cmder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private IVideoManagerStorager storager; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private IRedisCatchStorage redisCatchStorage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private EventPublisher publisher; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private RedisUtil redis; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private DeferredResultHolder deferredResultHolder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private DeviceOffLineDetector offLineDetector; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private static final String NOTIFY_ALARM = "Alarm"; | 
|---|
|  |  |  | private static final String NOTIFY_MOBILE_POSITION = "MobilePosition"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void process(RequestEvent evt) { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void process(RequestEvent evt) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Element rootElement = getRootElement(evt); | 
|---|
|  |  |  | String cmd = XmlUtil.getText(rootElement, "CmdType"); | 
|---|
|  |  |  | 
|---|
|  |  |  | logger.info("接收到消息:" + cmd); | 
|---|
|  |  |  | response200Ok(evt); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (DocumentException | SipException |InvalidArgumentException | ParseException e) { | 
|---|
|  |  |  | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理MobilePosition移动位置Notify | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param evt | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void processNotifyMobilePosition(RequestEvent evt) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //回复 200 OK | 
|---|
|  |  |  | // 回复 200 OK | 
|---|
|  |  |  | Element rootElement = getRootElement(evt); | 
|---|
|  |  |  | MobilePosition mobilePosition = new MobilePosition(); | 
|---|
|  |  |  | Element deviceIdElement = rootElement.element("DeviceID"); | 
|---|
|  |  |  | 
|---|
|  |  |  | mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID")); | 
|---|
|  |  |  | mobilePosition.setTime(XmlUtil.getText(rootElement, "Time")); | 
|---|
|  |  |  | mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); | 
|---|
|  |  |  | mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); | 
|---|
|  |  |  | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) { | 
|---|
|  |  |  | mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); | 
|---|
|  |  |  | if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) { | 
|---|
|  |  |  | mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(rootElement, "Speed"))); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mobilePosition.setSpeed(0.0); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*** | 
|---|
|  |  |  | * 处理alarm设备报警Notify | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param evt | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void processNotifyAlarm(RequestEvent evt) { | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceAlarm.setLatitude(0.00); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if ( deviceAlarm.getAlarmMethod().equals("4")) { | 
|---|
|  |  |  | if (deviceAlarm.getAlarmMethod().equals("4")) { | 
|---|
|  |  |  | MobilePosition mobilePosition = new MobilePosition(); | 
|---|
|  |  |  | mobilePosition.setDeviceId(deviceAlarm.getDeviceId()); | 
|---|
|  |  |  | mobilePosition.setTime(deviceAlarm.getAlarmTime()); | 
|---|
|  |  |  | 
|---|
|  |  |  | Element rootElement = getRootElement(evt); | 
|---|
|  |  |  | Element deviceIdElement = rootElement.element("DeviceID"); | 
|---|
|  |  |  | String deviceId = deviceIdElement.getText(); | 
|---|
|  |  |  | Device device = storager.queryVideoDevice(deviceId); | 
|---|
|  |  |  | Element deviceListElement = rootElement.element("DeviceList"); | 
|---|
|  |  |  | if (deviceListElement == null) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); | 
|---|
|  |  |  | if (deviceListIterator != null) { | 
|---|
|  |  |  | Device device = storager.queryVideoDevice(deviceId); | 
|---|
|  |  |  | if (device == null) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | DeviceChannel deviceChannel = new DeviceChannel(); | 
|---|
|  |  |  | deviceChannel.setName(channelName); | 
|---|
|  |  |  | deviceChannel.setChannelId(channelDeviceId); | 
|---|
|  |  |  | // ONLINE OFFLINE  HIKVISION DS-7716N-E4 NVR的兼容性处理 | 
|---|
|  |  |  | // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 | 
|---|
|  |  |  | if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) { | 
|---|
|  |  |  | deviceChannel.setStatus(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode")); | 
|---|
|  |  |  | deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block")); | 
|---|
|  |  |  | deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address")); | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Parental") == null || XmlUtil.getText(itemDevice, "Parental") == "") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Parental") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "Parental") == "") { | 
|---|
|  |  |  | deviceChannel.setParental(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental"))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID")); | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "SafetyWay") == null || XmlUtil.getText(itemDevice, "SafetyWay")== "") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "SafetyWay") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "SafetyWay") == "") { | 
|---|
|  |  |  | deviceChannel.setSafetyWay(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay"))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "RegisterWay") == null || XmlUtil.getText(itemDevice, "RegisterWay") =="") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "RegisterWay") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "RegisterWay") == "") { | 
|---|
|  |  |  | deviceChannel.setRegisterWay(1); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay"))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum")); | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Certifiable") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "Certifiable") == "") { | 
|---|
|  |  |  | deviceChannel.setCertifiable(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable"))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "ErrCode") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "ErrCode") == "") { | 
|---|
|  |  |  | deviceChannel.setErrCode(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode"))); | 
|---|
|  |  |  | 
|---|
|  |  |  | deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime")); | 
|---|
|  |  |  | deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy")); | 
|---|
|  |  |  | deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress")); | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") =="") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") { | 
|---|
|  |  |  | deviceChannel.setPort(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setLatitude(0.00); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") { | 
|---|
|  |  |  | if (XmlUtil.getText(itemDevice, "PTZType") == null | 
|---|
|  |  |  | || XmlUtil.getText(itemDevice, "PTZType") == "") { | 
|---|
|  |  |  | deviceChannel.setPTZType(0); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType"))); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 回复200 OK | 
|---|
|  |  |  | response200Ok(evt); | 
|---|
|  |  |  | if (offLineDetector.isOnline(deviceId)) { | 
|---|
|  |  |  | publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); | 
|---|
|  |  |  | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*** | 
|---|
|  |  |  | /*** | 
|---|
|  |  |  | * 回复200 OK | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param evt | 
|---|
|  |  |  | * @throws SipException | 
|---|
|  |  |  | * @throws InvalidArgumentException | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException { | 
|---|
|  |  |  | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); | 
|---|
|  |  |  | getServerTransaction(evt).sendResponse(response); | 
|---|
|  |  |  | ServerTransaction serverTransaction = getServerTransaction(evt); | 
|---|
|  |  |  | serverTransaction.sendResponse(response); | 
|---|
|  |  |  | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private Element getRootElement(RequestEvent evt) throws DocumentException { | 
|---|
|  |  |  | private Element getRootElement(RequestEvent evt) throws DocumentException { | 
|---|
|  |  |  | Request request = evt.getRequest(); | 
|---|
|  |  |  | SAXReader reader = new SAXReader(); | 
|---|
|  |  |  | reader.setEncoding("gbk"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setCmder(SIPCommander cmder) { | 
|---|
|  |  |  | this.cmder = cmder; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setStorager(IVideoManagerStorager storager) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setRedis(RedisUtil redis) { | 
|---|
|  |  |  | this.redis = redis; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) { | 
|---|
|  |  |  | this.deferredResultHolder = deferredResultHolder; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setOffLineDetector(DeviceOffLineDetector offLineDetector) { | 
|---|