| | |
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException; |
| | |
| | | logger.warn("[接收到DeviceInfo应答消息,但是设备已经离线]:" + (device != null ? device.getDeviceId():"" )); |
| | | return; |
| | | } |
| | | ServerTransaction serverTransaction = getServerTransaction(evt); |
| | | try { |
| | | rootElement = getRootElement(evt, device.getCharset()); |
| | | |
| | | if (rootElement == null) { |
| | | logger.warn("[ 接收到DeviceInfo应答消息 ] content cannot be null, {}", evt.getRequest()); |
| | | try { |
| | | responseAck(serverTransaction, Response.BAD_REQUEST); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[命令发送失败] DeviceInfo应答消息 BAD_REQUEST: {}", e.getMessage()); |
| | | } |
| | | return; |
| | | } |
| | | Element deviceIdElement = rootElement.element("DeviceID"); |
| | | String channelId = deviceIdElement.getTextTrim(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + device.getDeviceId() + channelId; |
| | |
| | | device.setManufacturer(getText(rootElement, "Manufacturer")); |
| | | device.setModel(getText(rootElement, "Model")); |
| | | device.setFirmware(getText(rootElement, "Firmware")); |
| | | if (StringUtils.isEmpty(device.getStreamMode())) { |
| | | if (ObjectUtils.isEmpty(device.getStreamMode())) { |
| | | device.setStreamMode("UDP"); |
| | | } |
| | | deviceService.updateDevice(device); |
| | | // storager.updateDevice(device); |
| | | |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setKey(key); |
| | | msg.setData(device); |
| | | deferredResultHolder.invokeAllResult(msg); |
| | | // 回复200 OK |
| | | responseAck(evt, Response.OK); |
| | | } catch (DocumentException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidArgumentException e) { |
| | | e.printStackTrace(); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } catch (SipException e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException(e); |
| | | } |
| | | try { |
| | | // 回复200 OK |
| | | responseAck(serverTransaction, Response.OK); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[命令发送失败] DeviceInfo应答消息 200: {}", e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |