|  |  | 
 |  |  | 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.message.Response; | 
 |  |  | import java.text.ParseException; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 状态信息(心跳)报送 | 
 |  |  |  */ | 
 |  |  | @Component | 
 |  |  | public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | 
 |  |  |  | 
 |  |  | 
 |  |  |             String received = viaHeader.getReceived(); | 
 |  |  |             int rPort = viaHeader.getRPort(); | 
 |  |  |             // 解析本地地址替代 | 
 |  |  |             if (StringUtils.isEmpty(received) || rPort == -1) { | 
 |  |  |             if (ObjectUtils.isEmpty(received) || rPort == -1) { | 
 |  |  |                 received = viaHeader.getHost(); | 
 |  |  |                 rPort = viaHeader.getPort(); | 
 |  |  |             } | 
 |  |  | 
 |  |  |                 device.setHostAddress(received.concat(":").concat(String.valueOf(rPort))); | 
 |  |  |             } | 
 |  |  |             device.setKeepaliveTime(DateUtil.getNow()); | 
 |  |  |             // 回复200 OK | 
 |  |  |             responseAck(evt, Response.OK); | 
 |  |  |             if (device.getOnline() == 1) { | 
 |  |  |                 // 回复200 OK | 
 |  |  |                 responseAck(evt, Response.OK); | 
 |  |  |                 deviceService.updateDevice(device); | 
 |  |  |             }else { | 
 |  |  |                 // 对于已经离线的设备判断他的注册是否已经过期 | 
 |  |  |                 if (!deviceService.expire(device)){ | 
 |  |  |                     deviceService.online(device); | 
 |  |  |                     // 回复200 OK | 
 |  |  |                     responseAck(evt, Response.OK); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } catch (SipException e) { |