전자 결재 DTD(exchange.dtd, pack.dtd) 정의 및 생성 및 테스트 반영

dev
Jonguk. Lim 6 months ago
parent 9c14262418
commit c7f827b305

@ -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> 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 {
* </pre>
*/
@JacksonXmlProperty(localName = "result", isAttribute = true)
@JsonProperty(required = true)
private String result;
/**
@ -158,16 +173,18 @@ public class ExchangeCommon {
* </pre>
*/
@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> 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;
}
}

@ -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;
}
}

@ -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;
/**
* <pre>
*
* </pre>
*/
@JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
protected String filename;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
public static class Header {
/**
* <pre>
* docType
* send | fail |arrive | receive | invalid | submit | return |approval
* | | | || | |
*</pre>
*/
@JacksonXmlProperty
@JsonProperty(required = true)
protected Type type;
/**
* <pre>
* : YYYY-MM-DD HH:mm:ss
*</pre>
*/
@JacksonXmlProperty
@JsonProperty(required = true)
protected String date;
/**
* <pre>
*
*</pre>
*/
@JacksonXmlProperty
@JsonProperty(required = true)
protected String sender;
/**
* <pre>
*
*</pre>
*/
@JacksonXmlProperty
@JsonProperty(required = true)
protected String receiver;
/**
* <pre>
* ID
*</pre>
*/
@JacksonXmlProperty(localName = "sender_userid")
@JsonProperty(required = true)
protected String senderUserid;
/**
* <pre>
* ID
*</pre>
*/
@JacksonXmlProperty(localName = "receiver_userid")
@JsonProperty(required = true)
protected String receiverUserid;
/**
* <pre>
*
* 0 ~ n
*</pre>
*/
@JacksonXmlProperty(localName = "sender_email")
protected String senderEmail;
/**
* <pre>
* - base64 encoding
* CDATA
*</pre>
*/
@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));
// }
/**
* <pre>
* - base64 encoding
* CDATA
*</pre>
*/
@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));
//}
/**
* <pre>
*
*</pre>
*/
@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 {
/**
* <pre>
@ -128,29 +233,91 @@ public class PackDto {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
public static class Content {
/**
* <pre>
* content - base64 encoding
* CDATA
*</pre>
*/
@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));
// }
/**
* <pre>
* content
* exchange -
* notification -
* attch -
* attch_xml - XML
* attch_xsl - XSL
* fail - (text)
* </pre>
*/
@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) {

@ -1,27 +1,27 @@
<?xml version="1.0" encoding="EUC-KR" ?>
<!ELEMENT pack (header, contents)>
<!ATTLIST pack filename CDATA #REQUIRED >
<!ELEMENT header (type, date, sender, receiver, sender_userid, receiver_userid, sender_email?,sender_orgname, sender_systemname?, administrative_num)>
<!ELEMENT pack (header, contents)>
<!ATTLIST pack filename CDATA #REQUIRED >
<!ELEMENT type EMPTY>
<!ATTLIST type doc-type (send|fail|arrive|receive|invalid|submit|return|approval) #REQUIRED >`
<!ELEMENT date (#PCDATA)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT receiver (#PCDATA)>
<!ELEMENT sender_userid (#PCDATA)>
<!ELEMENT receiver_userid (#PCDATA)>
<!ELEMENT sender_email (#PCDATA)>
<!ELEMENT sender_orgname (#PCDATA)>
<!ELEMENT sender_systemname (#PCDATA)>
<!ELEMENT administrative_num (#PCDATA)>
<!ELEMENT header (type, date, sender, receiver, sender_userid, receiver_userid, sender_email?,sender_orgname, sender_systemname?, administrative_num)>
<!ELEMENT contents (content)*>
<!ELEMENT type EMPTY>
<!ATTLIST type doc-type (send|fail|arrive|receive|invalid|submit|return|approval) #REQUIRED >
<!ELEMENT date (#PCDATA)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT receiver (#PCDATA)>
<!ELEMENT sender_userid (#PCDATA)>
<!ELEMENT receiver_userid (#PCDATA)>
<!ELEMENT sender_email (#PCDATA)>
<!ELEMENT sender_orgname (#PCDATA)>
<!ELEMENT sender_systemname (#PCDATA)>
<!ELEMENT administrative_num (#PCDATA)>
<!ELEMENT content (#PCDATA)>
<!ATTLIST content content-role CDATA #REQUIRED >
<!ATTLIST content content-transfer-encoding CDATA "base64" >
<!ATTLIST content filename CDATA #REQUIRED >
<!ATTLIST content content-type CDATA #IMPLIED >
<!ATTLIST content charset CDATA #IMPLIED >
<!ELEMENT contents (content)*>
<!ELEMENT content (#PCDATA)>
<!ATTLIST content content-role CDATA #REQUIRED >
<!ATTLIST content content-transfer-encoding CDATA "base64" >
<!ATTLIST content filename CDATA #REQUIRED >
<!ATTLIST content content-type CDATA #IMPLIED >
<!ATTLIST content charset CDATA #IMPLIED >

@ -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<PackDto>() {});
FileInputStream fileInputStream = new FileInputStream("pack.xml");
byte[] bytes = fileInputStream.readAllBytes();
String content = new String(bytes);
PackDto dto = xml.parse(content, new TypeReference<PackDto>() {});
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 = """
<!DOCTYPE EXCHANGE SYSTEM "exchange.dtd">
<!DOCTYPE pack SYSTEM "pack.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> T toObjByXml(String xml, final Class<T> 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());
}
}
}

Loading…
Cancel
Save