| | |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.gb28181.SipLayer; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import gov.nist.core.Host; |
| | | import gov.nist.javax.sip.address.AddressImpl; |
| | | import gov.nist.javax.sip.address.SipUri; |
| | | import gov.nist.javax.sip.header.To; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.sip.ResponseEvent; |
| | | import javax.sip.address.Address; |
| | | import javax.sip.address.URI; |
| | | import javax.sip.header.CallIdHeader; |
| | | import javax.sip.header.ToHeader; |
| | | import javax.sip.header.WWWAuthenticateHeader; |
| | | import javax.sip.message.Response; |
| | | |
| | |
| | | @Component |
| | | public class RegisterResponseProcessor implements ISIPResponseProcessor { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(RegisterRequestProcessor.class); |
| | | private Logger logger = LoggerFactory.getLogger(RegisterResponseProcessor.class); |
| | | |
| | | @Autowired |
| | | private ISIPCommanderForPlatform sipCommanderForPlatform; |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorager storager; |
| | | |
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage; |
| | | |
| | | public RegisterResponseProcessor() { |
| | | } |
| | | |
| | | /** |
| | | * 处理Register响应 |
| | |
| | | */ |
| | | @Override |
| | | public void process(ResponseEvent evt, SipLayer layer, SipConfig config) { |
| | | // TODO Auto-generated method stub |
| | | Response response = evt.getResponse(); |
| | | ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME); |
| | | SipUri uri = (SipUri)toHeader.getAddress().getURI(); |
| | | String platformGBId = uri.getAuthority().getUser(); |
| | | logger.info(String.format("收到 %s 的注册%S请求", platformGBId, response.getStatusCode() )); |
| | | CallIdHeader callIdHeader = (CallIdHeader) response.getHeader(CallIdHeader.NAME); |
| | | String callId = callIdHeader.getCallId(); |
| | | |
| | | ParentPlatform parentPlatform = storager.queryParentPlatById(platformGBId); |
| | | String platformGBId = redisCatchStorage.queryPlatformRegisterInfo(callId); |
| | | if (platformGBId == null) { |
| | | logger.info(String.format("未找到callId: %s 的注册/注销平台id", callId )); |
| | | return; |
| | | } |
| | | |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformGBId); |
| | | if (parentPlatformCatch == null) { |
| | | logger.warn(String.format("收到 %s 的注册/注销%S请求, 但是平台缓存信息未查询到!!!", platformGBId, response.getStatusCode())); |
| | | return; |
| | | } |
| | | String action = parentPlatformCatch.getParentPlatform().getExpires().equals("0") ? "注销" : "注册"; |
| | | logger.info(String.format("收到 %s %s的%S响应", platformGBId, action, response.getStatusCode() )); |
| | | ParentPlatform parentPlatform = parentPlatformCatch.getParentPlatform(); |
| | | if (parentPlatform == null) { |
| | | logger.warn(String.format("收到 %s 的注册%S请求, 但是平台信息未查询到!!!", platformGBId, response.getStatusCode())); |
| | | logger.warn(String.format("收到 %s %s的%S请求, 但是平台信息未查询到!!!", platformGBId, action, response.getStatusCode())); |
| | | return; |
| | | } |
| | | |
| | | if (response.getStatusCode() == 401) { |
| | | |
| | | WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME); |
| | | String realm = www.getRealm(); |
| | | String nonce = www.getNonce(); |
| | | String scheme = www.getScheme(); |
| | | |
| | | CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME); |
| | | String callId = callIdHeader.getCallId(); |
| | | sipCommanderForPlatform.register(parentPlatform, callId, realm, nonce, scheme); |
| | | sipCommanderForPlatform.register(parentPlatform, callId, www, null, null); |
| | | }else if (response.getStatusCode() == 200){ |
| | | // 注册成功 |
| | | logger.info(String.format("%s 注册成功", platformGBId )); |
| | | parentPlatform.setStatus(true); |
| | | storager.updateParentPlatform(parentPlatform); |
| | | // 注册/注销成功 |
| | | logger.info(String.format("%s %s成功", platformGBId, action)); |
| | | redisCatchStorage.delPlatformRegisterInfo(callId); |
| | | parentPlatform.setStatus("注册".equals(action)); |
| | | // 取回Expires设置,避免注销过程中被置为0 |
| | | ParentPlatform parentPlatformTmp = storager.queryParentPlatByServerGBId(platformGBId); |
| | | String expires = parentPlatformTmp.getExpires(); |
| | | parentPlatform.setExpires(expires); |
| | | parentPlatform.setId(parentPlatformTmp.getId()); |
| | | storager.updateParentPlatformStatus(platformGBId, "注册".equals(action)); |
| | | |
| | | redisCatchStorage.updatePlatformRegister(parentPlatform); |
| | | |
| | | redisCatchStorage.updatePlatformKeepalive(parentPlatform); |
| | | |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | } |
| | | } |
| | | |