From 3f6b28350a5b1c0636f1f87e19bc0defba855aed Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 25 Sep 2023 00:14:39 +0800 Subject: [PATCH] =?UTF-8?q?MANSCDPUtils.Builder=20=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=20=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E7=BC=96=E7=A0=81=20=E9=BB=98=E8=AE=A4=E4=B8=BA=20GB28181=20?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=20GB2312=20=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/sip/utils/MANSCDPUtils.java | 28 +++++-------------- .../gb28181/sip/manscdp/MANSCDPTest.java | 16 +++++------ 2 files changed, 14 insertions(+), 30 deletions(-) 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);