NotifyRequestBuilder 及 测试样例 调整
This commit is contained in:
parent
89225fa9c3
commit
1d44613e88
@ -21,6 +21,13 @@ import javax.sip.message.Request;
|
||||
@ToString(callSuper = true)
|
||||
public class NotifyRequestBuilder extends RequestBuilder implements NotifyBuilder {
|
||||
@SneakyThrows
|
||||
public Request createNotifyRequest(String callId, long cSeq, String event, byte[] content, Request request){
|
||||
SIPRequest sipRequest = (SIPRequest) request;
|
||||
String toTag = sipRequest.getToTag();
|
||||
int expires = sipRequest.getExpires().getExpires();
|
||||
return createNotifyRequest(callId, cSeq, event, content, toTag, expires);
|
||||
}
|
||||
@SneakyThrows
|
||||
public Request createNotifyRequest(String callId, long cSeq, String event, byte[] content, String toTag, int expire) {
|
||||
SIPRequest notifyRequest = (SIPRequest) createNotifyRequest(callId, cSeq, event, content, toTag);
|
||||
SubscriptionState subscriptionState = (SubscriptionState) notifyRequest.getHeader(SubscriptionState.NAME);
|
||||
@ -28,10 +35,14 @@ public class NotifyRequestBuilder extends RequestBuilder implements NotifyBuilde
|
||||
return notifyRequest;
|
||||
}
|
||||
|
||||
public Request createNotifyRequest(String callId, long cSeq, String event, byte[] content) {
|
||||
return createNotifyRequest(callId, cSeq, event, content, "");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Request createNotifyRequest(String callId, long cSeq, String event, byte[] content, String toTag) {
|
||||
SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, content);
|
||||
if(StringUtils.isNotBlank(toTag)){
|
||||
if (StringUtils.isNotBlank(toTag)) {
|
||||
request.getToHeader().setTag(toTag);
|
||||
}
|
||||
return SipBuilder.addHeaders(request,
|
||||
|
@ -7,6 +7,8 @@ import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogDeviceListDT
|
||||
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogResponseDTO;
|
||||
import cn.skcks.docking.gb28181.sip.manscdp.catalog.response.CatalogSubscribeResponseDTO;
|
||||
import cn.skcks.docking.gb28181.sip.manscdp.keepalive.notify.KeepaliveNotifyDTO;
|
||||
import cn.skcks.docking.gb28181.sip.method.message.request.MessageRequestBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.message.response.MessageResponseBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.notify.request.NotifyRequestBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.register.request.RegisterRequestBuilder;
|
||||
import cn.skcks.docking.gb28181.sip.method.register.response.RegisterResponseBuilder;
|
||||
@ -38,6 +40,26 @@ public class RequestTest {
|
||||
|
||||
public static final String domain = "4405010000";
|
||||
|
||||
@Test
|
||||
void messageTest(){
|
||||
MessageRequestBuilder messageRequestBuilder = MessageRequestBuilder.builder()
|
||||
.localIp(localIp)
|
||||
.localPort(localPort)
|
||||
.localId(localId)
|
||||
.targetIp(remoteIp)
|
||||
.targetPort(remotePort)
|
||||
.targetId(remoteId)
|
||||
.transport(ListeningPoint.TCP)
|
||||
.build();
|
||||
String callId = IdUtil.fastSimpleUUID();
|
||||
Request messageRequest = messageRequestBuilder.createMessageRequest(callId, 1, new byte[]{});
|
||||
log.info("\n{}", messageRequest);
|
||||
|
||||
MessageResponseBuilder messageResponseBuilder = MessageResponseBuilder.builder().build();
|
||||
Response messageResponse = messageResponseBuilder.createMessageResponse(messageRequest, new byte[]{}, SipUtil.nanoId());
|
||||
log.info("\n{}", messageResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void subscribeTest(){
|
||||
@ -58,7 +80,7 @@ public class RequestTest {
|
||||
.build();
|
||||
|
||||
Request subscribeRequest = subscribeRequestBuilder.createSubscribeRequest(callId,
|
||||
1, catalogQueryDTO.getCmdType(), MANSCDPUtils.toByteXml(catalogQueryDTO));
|
||||
1, catalogQueryDTO.getCmdType(), MANSCDPUtils.toByteXml(catalogQueryDTO),90);
|
||||
log.info("\n{}",subscribeRequest);
|
||||
|
||||
catalogQueryDTO = MANSCDPUtils.parse(subscribeRequest.getRawContent(), CatalogQueryDTO.class);
|
||||
@ -85,7 +107,7 @@ public class RequestTest {
|
||||
.sn(String.valueOf(2))
|
||||
.deviceId(localId)
|
||||
.build();
|
||||
Request notifyRequest = notifyRequestBuilder.createNotifyRequest(callId, 2, CmdType.KEEPALIVE, MANSCDPUtils.toByteXml(keepaliveNotifyDTO), null);
|
||||
Request notifyRequest = notifyRequestBuilder.createNotifyRequest(callId, 2, CmdType.KEEPALIVE, MANSCDPUtils.toByteXml(keepaliveNotifyDTO));
|
||||
log.info("\n{}", notifyRequest);
|
||||
|
||||
CatalogDeviceListDTO catalogDeviceListDTO = CatalogDeviceListDTO.builder()
|
||||
@ -99,7 +121,8 @@ public class RequestTest {
|
||||
.build();
|
||||
|
||||
String toTag = ((SIPRequest)subscribeRequest).getFromTag();
|
||||
Request catalogNotifyRequest = notifyRequestBuilder.createNotifyRequest(callId, 3, CmdType.CATALOG, MANSCDPUtils.toByteXml(catalogResponseDTO), toTag);
|
||||
int expires = subscribeRequest.getExpires().getExpires();
|
||||
Request catalogNotifyRequest = notifyRequestBuilder.createNotifyRequest(callId, 3, CmdType.CATALOG, MANSCDPUtils.toByteXml(catalogResponseDTO), toTag,expires);
|
||||
log.info("\n{}", catalogNotifyRequest);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user