diff --git a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/utils/MANSCDPUtils.java b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/utils/MANSCDPUtils.java index 159cdce..9654694 100644 --- a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/utils/MANSCDPUtils.java +++ b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/utils/MANSCDPUtils.java @@ -46,14 +46,12 @@ public class MANSCDPUtils { @Builder.Default @JsonIgnore private String encoding = GB28181Constant.CHARSET; + private T data; - private T query; - - private T response; - - private T notify; - - private T control; + public XMLBuilder(T data){ + this.data = data; + this.encoding = GB28181Constant.CHARSET; + } } @SneakyThrows @@ -65,20 +63,8 @@ public class MANSCDPUtils { return byteArrayOutputStream.toByteArray(); } - public static String toQuery(XMLBuilder wrapper){ - return MANSCDPUtils.toXml(wrapper.getQuery(), wrapper.encoding); - } - - public static String toResponse(XMLBuilder wrapper){ - return MANSCDPUtils.toXml(wrapper.getResponse(), wrapper.encoding); - } - - public static String toNotify(XMLBuilder wrapper){ - return MANSCDPUtils.toXml(wrapper.getNotify(), wrapper.encoding); - } - - public static String toControl(XMLBuilder wrapper){ - return MANSCDPUtils.toXml(wrapper.getControl(), wrapper.encoding); + public static String toXml(XMLBuilder wrapper){ + return MANSCDPUtils.toXml(wrapper.getData(), wrapper.encoding); } public static String toXml(Object obj, String inputCharset,String outputCharset) { diff --git a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/manscdp/MANSCDPTest.java b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/manscdp/MANSCDPTest.java index 679f934..2cc821c 100644 --- a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/manscdp/MANSCDPTest.java +++ b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/manscdp/MANSCDPTest.java @@ -27,7 +27,7 @@ public class MANSCDPTest { .build(); MANSCDPUtils.XMLBuilder xmlBuilder = MANSCDPUtils.XMLBuilder.builder() - .notify(keepaliveNotifyDTO) + .data(keepaliveNotifyDTO) .build(); log.info("\n{}",MANSCDPUtils.toXml(xmlBuilder)); @@ -43,10 +43,8 @@ public class MANSCDPTest { .build(); log.info("\n{}", MANSCDPUtils.toXml(catalogQueryDTO)); - MANSCDPUtils.XMLBuilder query = MANSCDPUtils.XMLBuilder.builder() - .query(catalogQueryDTO) - .build(); - String serialize = MANSCDPUtils.toQuery(query); + MANSCDPUtils.XMLBuilder query = new MANSCDPUtils.XMLBuilder(catalogQueryDTO); + String serialize = MANSCDPUtils.toXml(query); log.info("\n{}", serialize); CatalogQueryDTO queryDTO = MANSCDPUtils.parse(serialize, CatalogQueryDTO.class); @@ -66,18 +64,18 @@ public class MANSCDPTest { .build(); // 默认 GB2312 编码 MANSCDPUtils.XMLBuilder response = MANSCDPUtils.XMLBuilder.builder() - .response(catalogResponseDTO) + .data(catalogResponseDTO) .build(); - serialize = MANSCDPUtils.toResponse(response); + serialize = MANSCDPUtils.toXml(response); log.info("\n{}", serialize); CatalogResponseDTO responseDTO = MANSCDPUtils.parse(serialize, CatalogResponseDTO.class); log.info("{}",responseDTO); // UTF8 编码 response = MANSCDPUtils.XMLBuilder.builder() .encoding(StandardCharsets.UTF_8.name()) - .response(catalogResponseDTO) + .data(catalogResponseDTO) .build(); - serialize = MANSCDPUtils.toResponse(response); + serialize = MANSCDPUtils.toXml(response); log.info("\n{}", serialize); responseDTO = MANSCDPUtils.parse(serialize, CatalogResponseDTO.class); log.info("{}",responseDTO);