From c7f827b305903c44164db24f7bb3c4cf984a03b4 Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Thu, 9 May 2024 17:26:51 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=84=EC=9E=90=20=EA=B2=B0=EC=9E=AC=20DTD(e?= =?UTF-8?q?xchange.dtd,=20pack.dtd)=20=EC=A0=95=EC=9D=98=20=EB=B0=8F=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adds/inf/mois/model/ExchangeCommon.java | 74 ++++++-- .../xit/adds/inf/mois/model/ExchangeDto.java | 11 +- .../cokr/xit/adds/inf/mois/model/PackDto.java | 171 +++++++++++++++++- src/main/resources/xsd/pack.dtd | 44 ++--- .../xit/adds/inf/mois/model/PackDtoTest.java | 106 +++++++++-- 5 files changed, 347 insertions(+), 59 deletions(-) diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java index 85fb6ee..8d12a98 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeCommon.java @@ -3,6 +3,7 @@ package cokr.xit.adds.inf.mois.model; import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; @@ -37,22 +38,27 @@ public class ExchangeCommon { @Builder public static class Common { @JacksonXmlProperty(localName = "SENDER") + @JsonProperty(required = true) private Sender sender; @JacksonXmlProperty(localName = "RECEIVER") + @JsonProperty(required = true) private Receiver receiver; @JacksonXmlProperty(localName = "TITLE") - @JacksonXmlCData + @JsonProperty(required = true) private String title; @JacksonXmlProperty(localName = "CREATED_DATE") + @JsonProperty(required = true) private String createdDate; @JacksonXmlProperty(localName = "ATTACHNUM") + @JsonProperty(required = true) private int attachnum; @JacksonXmlProperty(localName = "ADMINISTRATIVE_NUM") + @JsonProperty(required = true) private String administrativeNum; } @@ -62,9 +68,11 @@ public class ExchangeCommon { @Builder public static class Sender { @JacksonXmlProperty(localName = "SERVERID") + @JsonProperty(required = true) private String serverid; @JacksonXmlProperty(localName = "USERID") + @JsonProperty(required = true) private String userid; @JacksonXmlProperty(localName = "EMAIL") @@ -77,28 +85,29 @@ public class ExchangeCommon { @Builder public static class Receiver { @JacksonXmlProperty(localName = "SERVERID") + @JsonProperty(required = true) private String serverid; @JacksonXmlProperty(localName = "USERID") + @JsonProperty(required = true) private String userid; @JacksonXmlProperty(localName = "EMAIL") private String email; } - - @JsonInclude(JsonInclude.Include.NON_NULL) @NoArgsConstructor @AllArgsConstructor @Builder public static class Docnum { @JacksonXmlProperty(localName = "docnumcode", isAttribute = true) + @JsonProperty(required = true) + @JacksonXmlCData private String docnumcode; @XmlValue @JacksonXmlText - @JacksonXmlCData private String value; } @@ -111,9 +120,11 @@ public class ExchangeCommon { * 진행| 완료 */ @JacksonXmlProperty(localName = "status", isAttribute = true) + @JsonProperty(required = true) private String status; @JacksonXmlProperty(localName = "LINES") + @JsonProperty(required = true) private Lines lines; } @@ -124,6 +135,7 @@ public class ExchangeCommon { public static class Lines { @JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty(localName = "LINE") + @JsonProperty(required = true) private List line; } @@ -133,9 +145,11 @@ public class ExchangeCommon { @Builder public static class Line { @JacksonXmlProperty(localName = "LEVEL") + @JsonProperty(required = true) private String level; @JacksonXmlProperty(localName = "SANCTION") + @JsonProperty(required = true) private Sanction sanction; } @@ -150,6 +164,7 @@ public class ExchangeCommon { * */ @JacksonXmlProperty(localName = "result", isAttribute = true) + @JsonProperty(required = true) private String result; /** @@ -158,16 +173,18 @@ public class ExchangeCommon { * */ @JacksonXmlProperty(localName = "type", isAttribute = true) + @JsonProperty(required = true) private String type; @JacksonXmlProperty(localName = "PERSON") + @JsonProperty(required = true) private Person person; @JacksonXmlProperty(localName = "COMMENT") - @JacksonXmlCData private String comment; @JacksonXmlProperty(localName = "DATE") + @JsonProperty(required = true) private String date; } @@ -177,20 +194,23 @@ public class ExchangeCommon { @Builder public static class Person { @JacksonXmlProperty(localName = "USERID") + @JsonProperty(required = true) private String userid; @JacksonXmlProperty(localName = "NAME") + @JsonProperty(required = true) private String name; @JacksonXmlProperty(localName = "POSITION") + @JsonProperty(required = true) private String position; @JacksonXmlProperty(localName = "DEPT") - @JacksonXmlCData + @JsonProperty(required = true) private String dept; @JacksonXmlProperty(localName = "ORG") - @JacksonXmlCData + @JsonProperty(required = true) private String org; } @@ -200,6 +220,7 @@ public class ExchangeCommon { @Builder public static class ModificationFlag { @JacksonXmlProperty(localName = "MODIFIABLE") + @JsonProperty(required = true) private Modifiable modifiable; @JacksonXmlProperty(localName = "MODIFIED") @@ -215,6 +236,7 @@ public class ExchangeCommon { * yes | no */ @JacksonXmlProperty(localName = "modifyflag", isAttribute = true) + @JsonProperty(required = true) @Builder.Default private String modifyflag = "no"; } @@ -234,14 +256,17 @@ public class ExchangeCommon { @Builder public static class Addendum { @JacksonXmlProperty(localName = "comment", isAttribute = true) + @JsonProperty(required = true) + @JacksonXmlCData private String comment; @JacksonXmlProperty(localName = "name", isAttribute = true) + @JsonProperty(required = true) + @JacksonXmlCData private String name; @XmlValue @JacksonXmlText - @JacksonXmlCData private String value; } @@ -255,6 +280,7 @@ public class ExchangeCommon { @JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty(localName = "ATTACHMENT") + @JsonProperty(required = true) private List attachment; } @@ -276,10 +302,19 @@ public class ExchangeCommon { @Builder public static class XMLFile { @JacksonXmlProperty(localName = "filename", isAttribute = true) - String filename; + @JsonProperty(required = true) + @JacksonXmlCData + private String filename; @JacksonXmlProperty(localName = "desc", isAttribute = true) - String desc; + @JsonProperty(required = true) + @JacksonXmlCData + private String desc; + + @XmlValue + @JacksonXmlText + @JsonProperty(required = true) + private String value; } @JsonInclude(JsonInclude.Include.NON_NULL) @@ -288,10 +323,19 @@ public class ExchangeCommon { @Builder public static class XSLFile { @JacksonXmlProperty(localName = "filename", isAttribute = true) - String filename; + @JsonProperty(required = true) + @JacksonXmlCData + private String filename; @JacksonXmlProperty(localName = "desc", isAttribute = true) - String desc; + @JsonProperty(required = true) + @JacksonXmlCData + private String desc; + + @XmlValue + @JacksonXmlText + @JsonProperty(required = true) + private String value; } @JsonInclude(JsonInclude.Include.NON_NULL) @@ -300,14 +344,18 @@ public class ExchangeCommon { @Builder public static class Attachment { @JacksonXmlProperty(localName = "filename", isAttribute = true) + @JsonProperty(required = true) + @JacksonXmlCData private String filename; @JacksonXmlProperty(localName = "desc", isAttribute = true) + @JsonProperty(required = true) + @JacksonXmlCData private String desc; @XmlValue @JacksonXmlText - @JacksonXmlCData + @JsonProperty(required = true) private String value; } } diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java index c6d97d1..43ba2cc 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangeDto.java @@ -1,7 +1,7 @@ package cokr.xit.adds.inf.mois.model; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @@ -31,10 +31,10 @@ import lombok.NoArgsConstructor; @Builder public class ExchangeDto extends ExchangeCommon { @JacksonXmlProperty(localName = "HEADER") + @JsonProperty(required = true) private Header header; @JacksonXmlProperty(localName = "BODY") - @JacksonXmlCData private String body; @JacksonXmlProperty(localName = "ATTACHMENTS") @@ -46,9 +46,11 @@ public class ExchangeDto extends ExchangeCommon { @Builder public static class Header { @JacksonXmlProperty(localName = "COMMON") + @JsonProperty(required = true) private Common common; @JacksonXmlProperty(localName = "DIRECTION") + @JsonProperty(required = true) private Direction direction; @JacksonXmlProperty(localName = "ADDENDA") @@ -82,6 +84,7 @@ public class ExchangeDto extends ExchangeCommon { * all | final */ @JacksonXmlProperty(isAttribute = true, localName = "notification") + @JsonProperty(required = true) @Builder.Default String notification = "all"; @@ -89,6 +92,7 @@ public class ExchangeDto extends ExchangeCommon { private Lines lines; @JacksonXmlProperty(localName = "MODIFICATION_FLAG") + @JsonProperty(required = true) private ModificationFlag modificationFlag; } @@ -98,12 +102,15 @@ public class ExchangeDto extends ExchangeCommon { @Builder public static class ToAdministrativeSystem { @JacksonXmlProperty(localName = "DOCNUM") + @JsonProperty(required = true) private Docnum docnum; @JacksonXmlProperty(localName = "SANCTION_INFO") + @JsonProperty(required = true) private SanctionInfo sanctionInfo; @JacksonXmlProperty(localName = "MODIFICATION_FLAG") + @JsonProperty(required = true) private ModificationFlag modificationFlag; } } diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java index 4e1ddf4..a2a3f15 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java @@ -1,11 +1,16 @@ package cokr.xit.adds.inf.mois.model; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.Base64Utils; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @@ -14,6 +19,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; import jakarta.xml.bind.annotation.XmlValue; import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; /** @@ -35,6 +41,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor @Builder +@Getter public class PackDto { @JacksonXmlProperty @JsonProperty(required = true) @@ -44,59 +51,157 @@ public class PackDto { @JsonProperty(required = true) protected Contents contents; + /** + *
+     * 전송 파일명
+     * 
+ */ @JacksonXmlProperty(localName = "filename", isAttribute = true) @JsonProperty(required = true) protected String filename; @JsonInclude(JsonInclude.Include.NON_EMPTY) @NoArgsConstructor - @AllArgsConstructor @Builder + @Getter public static class Header { + /** + *
+         * docType 속성
+         * send | fail |arrive | receive | invalid | submit | return |approval
+         * 발송 | 실패  | 도달  | 수신     |사용자없음| 상신    | 반송   |결재
+         *
+ */ @JacksonXmlProperty @JsonProperty(required = true) protected Type type; + /** + *
+         * 날자 : YYYY-MM-DD HH:mm:ss
+         *
+ */ @JacksonXmlProperty @JsonProperty(required = true) protected String date; + /** + *
+         * 송신시스템
+         *
+ */ @JacksonXmlProperty @JsonProperty(required = true) protected String sender; + /** + *
+         * 수신시스템
+         *
+ */ @JacksonXmlProperty @JsonProperty(required = true) protected String receiver; + /** + *
+         * 송신자ID
+         *
+ */ @JacksonXmlProperty(localName = "sender_userid") @JsonProperty(required = true) protected String senderUserid; + /** + *
+         * 수신자ID
+         *
+ */ @JacksonXmlProperty(localName = "receiver_userid") @JsonProperty(required = true) protected String receiverUserid; + /** + *
+         * 송신자 이메일
+         * 0 ~ n
+         *
+ */ @JacksonXmlProperty(localName = "sender_email") protected String senderEmail; + /** + *
+         * 송신 기관명 - base64 encoding
+         * CDATA
+         *
+ */ @JacksonXmlProperty(localName = "sender_orgname") @JsonProperty(required = true) + @JacksonXmlCData protected String senderOrgname; + // public String getSenderOrgname() { + // return new String(Base64Utils.decodeFromString(senderOrgname)); + // } + // public void setSenderOrgname(String senderOrgname) { + // this.senderOrgname = Base64Utils.encodeToString(senderOrgname.getBytes(StandardCharsets.UTF_8)); + // } + /** + *
+         * 송신 시스템명 - base64 encoding
+         * CDATA
+         *
+ */ @JacksonXmlProperty(localName = "sender_systemname") @JsonProperty(required = true) + @JacksonXmlCData protected String senderSystemname; + // public String getSenderSystemname() { + // return new String(Base64Utils.decodeFromString(senderSystemname)); + // } + //public void setSenderSystemname(String senderSystemname) { + // this.senderSystemname = Base64Utils.encodeToString(senderSystemname.getBytes(StandardCharsets.UTF_8)); + //} + /** + *
+         * 행정정보처리번호
+         *
+ */ @JacksonXmlProperty(localName = "administrative_num") @JsonProperty(required = true) protected String administrativeNum; + + public Header( + Type type, + String date, + String sender, + String receiver, + String senderUserid, + String receiverUserid, + String senderEmail, + String senderOrgname, + String senderSystemname, + String administrativeNum) { + this.type = type; + this.date = date; + this.sender = sender; + this.receiver = receiver; + this.senderUserid = senderUserid; + this.receiverUserid = receiverUserid; + this.senderEmail = senderEmail; + this.senderOrgname = StringUtils.isEmpty(senderOrgname)? senderOrgname : Base64Utils.encodeToString(senderOrgname.getBytes(StandardCharsets.UTF_8)); + this.senderSystemname = StringUtils.isEmpty(senderSystemname)? senderSystemname : Base64Utils.encodeToString(senderSystemname.getBytes(StandardCharsets.UTF_8)); + this.administrativeNum = administrativeNum; + } } @JsonInclude(JsonInclude.Include.NON_EMPTY) @NoArgsConstructor @AllArgsConstructor @Builder + @Getter public static class Type { /** *
@@ -128,29 +233,91 @@ public class PackDto {
 
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
     @NoArgsConstructor
-    @AllArgsConstructor
     @Builder
+    @Getter
     public static class Content {
+        /**
+         * 
+         * content 내용 - base64 encoding
+         * CDATA
+         *
+ */ @XmlValue @JacksonXmlText + @JacksonXmlCData protected String value; + // public String getValue() { + // return new String(Base64Utils.decodeFromString(value)); + // } + // public void setValue(String value) { + // this.value = Base64Utils.encodeToString(value.getBytes(StandardCharsets.UTF_8)); + // } + /** + *
+         * content 내용의 의미
+         * exchange - 연계 본문 문서 파일
+         * notification - 결재 처리 정보 통보 문서 파일
+         * attch - 일반 첨부 파일
+         * attch_xml - 행정 정보 XML 파일
+         * attch_xsl - 행정 정보 XSL 파일
+         * fail - 연계 모듈 에서 발송 실패 내용(text)
+         * 
+ */ @JacksonXmlProperty(localName = "content-role", isAttribute = true) @JsonProperty(required = true) protected String contentRole; + /** + * 인코딩 방식 - default base64 + */ @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true) protected String contentTransferEncoding = "base64"; + /** + * 파일이름 - base64 encoding + * CDATA + */ @JacksonXmlProperty(localName = "filename", isAttribute = true) @JsonProperty(required = true) + @JacksonXmlCData protected String filename; + // public String getFilename() { + // return new String(Base64Utils.decodeFromString(filename)); + // } + // public void setFilename(String filename) { + // this.filename = Base64Utils.encodeToString(filename.getBytes(StandardCharsets.UTF_8)); + // } + + /** + * content-type(MIME) + */ @JacksonXmlProperty(localName = "content-type", isAttribute = true) protected String contentType; + /** + * charset + */ @JacksonXmlProperty(localName = "charset", isAttribute = true) protected String charset; + + public Content( + String value, + String contentRole, + String contentTransferEncoding, + String filename, + String contentType, + String charset) { + this.value = StringUtils.isEmpty(value)? value : Base64Utils.encodeToString(value.getBytes(StandardCharsets.UTF_8)); + this.contentRole = contentRole; + if(!StringUtils.isEmpty(contentTransferEncoding)){ + this.contentTransferEncoding = contentTransferEncoding; + } + this.filename = StringUtils.isEmpty(filename)? filename : Base64Utils.encodeToString(filename.getBytes(StandardCharsets.UTF_8)); + this.contentType = contentType; + this.charset = charset; + } } public void configureXmlMapper(XmlMapper xmlMapper) { diff --git a/src/main/resources/xsd/pack.dtd b/src/main/resources/xsd/pack.dtd index 3de3a16..d05b49a 100644 --- a/src/main/resources/xsd/pack.dtd +++ b/src/main/resources/xsd/pack.dtd @@ -1,27 +1,27 @@ - - - - + + - - ` - - - - - - - - - + - + + + + + + + + + + + - - - - - - \ No newline at end of file + + + + + + + + diff --git a/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java index 5db65ef..953b7cd 100644 --- a/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java +++ b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java @@ -1,20 +1,36 @@ package cokr.xit.adds.inf.mois.model; -import java.io.FileOutputStream; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; +import java.io.StringReader; import java.util.List; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.util.Base64Utils; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import cokr.xit.adds.core.spring.exception.ApiCustomException; import cokr.xit.foundation.data.XML; import lombok.extern.slf4j.Slf4j; @@ -79,10 +95,20 @@ public class PackDtoTest { // xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); // }; // xml.configure(configurer); - PackDto dto = xml.parse(packXml, new TypeReference() {}); + FileInputStream fileInputStream = new FileInputStream("pack.xml"); + byte[] bytes = fileInputStream.readAllBytes(); + String content = new String(bytes); + + PackDto dto = xml.parse(content, new TypeReference() {}); log.info("dto: {}", dto); xml.write(System.out, dto, true); + assertEquals("senderOrgname", new String(Base64Utils.decodeFromString(dto.getHeader().getSenderOrgname()))); + assertEquals("senderSystemname", new String(Base64Utils.decodeFromString(dto.getHeader().getSenderSystemname()))); + assertEquals("filename", new String(Base64Utils.decodeFromString(dto.getContents().getContent().get(0).getFilename()))); + assertEquals("content-value", new String(Base64Utils.decodeFromString(dto.getContents().getContent().get(0).getValue()))); + + // XmlMapper xmlMapper = new XmlMapper(); // xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); // PackDto dto = xmlMapper.readValue(packXml, PackDto.class); @@ -102,27 +128,53 @@ public class PackDtoTest { XMLOutputFactory factory = mapper.getFactory().getXMLOutputFactory(); String dtd = """ - + """; - // FIXME: 파일명 생성 - try (FileOutputStream fos = new FileOutputStream("pack.xml");) { - XML xml = new XML(); - //dto.configureXmlMapper(xml.getXmlMapper()); - xml.write(fos, dto, true); - xml.write(System.out, dto, true); - - - // XmlMapper xmlMapper = new XmlMapper(); - // dto.configureXmlMapper(xmlMapper); - // //xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); - // String str = xmlMapper.writeValueAsString(dto); - // System.out.println("Generated XML:"); - // System.out.println(str); - //fos.flush(); - - }catch (Exception e) { + try (FileWriter w = new FileWriter("pack.xml")) { + XMLStreamWriter sw = factory.createXMLStreamWriter(w); + sw.writeStartDocument("EUC-KR", "1.0"); + sw.writeDTD("\n"+dtd); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + mapper.writeValue(sw, dto); + + // StringWriter swr = new StringWriter(); + // mapper.writeValue(swr, dto); + // System.out.println(swr.toString()); + + // FileInputStream fileInputStream = new FileInputStream("pack.xml"); + // byte[] bytes = fileInputStream.readAllBytes(); + // String content = new String(bytes); + // System.out.println(content); + + // PackDto rtnDto = toObjByXml(content, PackDto.class); + // + // StringWriter swr = new StringWriter(); + // mapper.writeValue(swr, content); + //System.out.println(swr.toString()); + + }catch (XMLStreamException e) { e.printStackTrace(); } + + + + // FIXME: 파일명 생성 + // try (FileOutputStream fos = new FileOutputStream("pack.xml");) { + // XML xml = new XML(); + // //dto.configureXmlMapper(xml.getXmlMapper()); + // xml.write(fos, dto, true); + // xml.write(System.out, dto, true); + // // XmlMapper xmlMapper = new XmlMapper(); + // // dto.configureXmlMapper(xmlMapper); + // // //xmlMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); + // // String str = xmlMapper.writeValueAsString(dto); + // // System.out.println("Generated XML:"); + // // System.out.println(str); + // //fos.flush(); + // + // }catch (Exception e) { + // e.printStackTrace(); + // } } private static PackDto getPackDto() { @@ -146,6 +198,7 @@ public class PackDtoTest { .contentRole("contentRole") .contentType("constentType") .charset("utf8") + .filename("filename") .value("content-value") .build(); @@ -160,4 +213,17 @@ public class PackDtoTest { return packDto; } + + private static T toObjByXml(String xml, final Class cls){ + ObjectMapper OM = new ObjectMapper(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(new StringReader(xml))); + return new XML().parse(xml, cls); + } catch (ParserConfigurationException | SAXException | IOException e) { + throw ApiCustomException.create(e.getMessage()); + } + } }