| | |
| | | import java.text.ParseException;
|
| | | import java.util.*;
|
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.Address;
|
| | | import javax.sip.address.SipURI;
|
| | |
|
| | | import javax.sip.header.FromHeader;
|
| | | import javax.sip.header.Header;
|
| | | import javax.sip.header.HeaderAddress;
|
| | | import javax.sip.header.ToHeader;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.ListeningPoint;
|
| | | import javax.sip.ObjectInUseException;
|
| | | import javax.sip.RequestEvent;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.SipProvider;
|
| | | import javax.sip.message.Request;
|
| | | import javax.sip.message.Response;
|
| | |
|
| | |
| | | import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
| | | import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.utils.GpsUtil;
|
| | | import com.genersoft.iot.vmp.utils.SipUtils;
|
| | | import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
| | | import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
| | | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
|
| | |
| | | private DeferredResultHolder deferredResultHolder;
|
| | |
|
| | | private DeviceOffLineDetector offLineDetector;
|
| | |
|
| | | private IDeviceAlarmService deviceAlarmService;
|
| | |
|
| | | private final static String CACHE_RECORDINFO_KEY = "CACHE_RECORDINFO_";
|
| | |
|
| | |
| | | */
|
| | | private void processMessageMobilePosition(RequestEvent evt) {
|
| | | try {
|
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | logger.warn("处理MobilePosition移动位置消息时未找到设备信息");
|
| | | return;
|
| | | }
|
| | | Element rootElement = getRootElement(evt, device.getCharset());
|
| | |
|
| | | MobilePosition mobilePosition = new MobilePosition();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getTextTrim().toString();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device != null) {
|
| | | if (!StringUtils.isEmpty(device.getName())) {
|
| | | mobilePosition.setDeviceName(device.getName());
|
| | | }
|
| | | if (!StringUtils.isEmpty(device.getName())) {
|
| | | mobilePosition.setDeviceName(device.getName());
|
| | | }
|
| | | mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID"));
|
| | | mobilePosition.setDeviceId(deviceId);
|
| | | mobilePosition.setChannelId(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")));
|
| | |
| | | Element rootElement = getRootElement(evt);
|
| | | String requestName = rootElement.getName();
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getTextTrim().toString();
|
| | | String deviceId = deviceIdElement.getTextTrim();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device != null ) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | | }
|
| | | if (requestName.equals("Query")) {
|
| | | logger.info("接收到DeviceInfo查询消息");
|
| | | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
|
| | |
| | | if (device == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
| | |
|
| | | device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
| | | device.setModel(XmlUtil.getText(rootElement, "Model"));
|
| | | device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
| | |
| | | deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
| | | // deviceChannel.setParentId(parentPlatform.getDeviceGBId());
|
| | | deviceChannel.setRegisterWay(1);
|
| | | deviceChannel.setCivilCode(cmder.getSipConfig().getSipDomain());
|
| | | deviceChannel.setCivilCode(cmder.getSipConfig().getDomain());
|
| | | deviceChannel.setModel("live");
|
| | | deviceChannel.setOwner("wvp-pro");
|
| | | // deviceChannel.setAddress("test");
|
| | |
| | |
|
| | |
|
| | | } else {
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | return;
|
| | | }
|
| | | deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList");
|
| | | Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
|
| | | if (deviceListIterator != null) {
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 遍历DeviceList
|
| | | while (deviceListIterator.hasNext()) {
|
| | | Element itemDevice = deviceListIterator.next();
|
| | |
| | | */
|
| | | private void processMessageAlarm(RequestEvent evt) {
|
| | | try {
|
| | | Element rootElement = getRootElement(evt);
|
| | | String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | logger.warn("处理alarm设备报警信息未找到设备信息");
|
| | | return;
|
| | | }
|
| | | Element rootElement = getRootElement(evt, device.getCharset());
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getText().toString();
|
| | | String channelId = deviceIdElement.getText().toString();
|
| | | // 回复200 OK
|
| | | responseAck(evt);
|
| | |
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device == null) {
|
| | | return;
|
| | | if (device.getCharset() != null) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | | }
|
| | |
|
| | | if (rootElement.getName().equals("Notify")) { // 处理报警通知
|
| | | DeviceAlarm deviceAlarm = new DeviceAlarm();
|
| | | deviceAlarm.setDeviceId(deviceId);
|
| | | deviceAlarm.setChannelId(channelId);
|
| | | deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
|
| | | deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
|
| | | deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
|
| | |
| | | storager.insertMobilePosition(mobilePosition);
|
| | | }
|
| | | }
|
| | | // TODO: 需要实现存储报警信息、报警分类
|
| | | System.out.println("存储报警信息、报警分类");
|
| | | // 存储报警信息、报警分类
|
| | | deviceAlarmService.add(deviceAlarm);
|
| | |
|
| | | if (offLineDetector.isOnline(deviceId)) {
|
| | | publisher.deviceAlarmEventPublish(deviceAlarm);
|
| | |
| | | deferredResultHolder.invokeResult(msg);
|
| | | }
|
| | | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
| | | // } catch (DocumentException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
| | | }else{
|
| | | logger.warn("收到[ "+deviceId+" ]心跳信息, 但是设备不存在, 回复404");
|
| | | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) {
|
| | | serverTransaction.getDialog().delete();
|
| | | }
|
| | | }
|
| | |
|
| | | // if (device != null && device.getOnline() == 1) {
|
| | |
| | | Element rootElement = getRootElement(evt);
|
| | | Element deviceIdElement = rootElement.element("DeviceID");
|
| | | String deviceId = deviceIdElement.getText().toString();
|
| | | Device device = storager.queryVideoDevice(deviceId);
|
| | | if (device != null ) {
|
| | | rootElement = getRootElement(evt, device.getCharset());
|
| | | }
|
| | | recordInfo.setDeviceId(deviceId);
|
| | | recordInfo.setName(XmlUtil.getText(rootElement, "Name"));
|
| | | if (XmlUtil.getText(rootElement, "SumNum")== null || XmlUtil.getText(rootElement, "SumNum") =="") {
|
| | |
| | | */
|
| | | private void responseAck(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 void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.NOT_FOUND, 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 {
|
| | |
|
| | | return getRootElement(evt, "gb2312");
|
| | | }
|
| | |
|
| | | private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
|
| | | if (charset == null) {
|
| | | charset = "gb2312";
|
| | | }
|
| | | Request request = evt.getRequest();
|
| | | SAXReader reader = new SAXReader();
|
| | | reader.setEncoding("gbk");
|
| | | reader.setEncoding(charset);
|
| | | Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
|
| | | return xml.getRootElement();
|
| | | }
|
| | |
| | | public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
|
| | | this.cmderFroPlatform = cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public void setDeviceAlarmService(IDeviceAlarmService deviceAlarmService) {
|
| | | this.deviceAlarmService = deviceAlarmService;
|
| | | }
|
| | | }
|