转换cmoutmsg消息的xml 去除多余的空标签
This commit is contained in:
@@ -57,6 +57,12 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.woodstox</groupId>
|
||||||
|
<artifactId>woodstox-core</artifactId>
|
||||||
|
<version>5.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.oracle</groupId>
|
<groupId>com.oracle</groupId>
|
||||||
<artifactId>ojdbc6</artifactId>
|
<artifactId>ojdbc6</artifactId>
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
package com.gzzn.omms.msgexchangeapi.entity.msg;
|
package com.gzzn.omms.msgexchangeapi.entity.msg;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -184,6 +186,7 @@ public class MSG
|
|||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private final static long serialVersionUID = 1L;
|
private final static long serialVersionUID = 1L;
|
||||||
@XmlElement(name = "META", required = true)
|
@XmlElement(name = "META", required = true)
|
||||||
@JsonProperty("META")
|
@JsonProperty("META")
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class CmoutmsgServiceImpl implements ICmoutmsgService {
|
|||||||
//发送消息到数据库
|
//发送消息到数据库
|
||||||
Cmoutmsg cmoutmsg = new Cmoutmsg();
|
Cmoutmsg cmoutmsg = new Cmoutmsg();
|
||||||
cmoutmsg.setCoutmsgsDateInserted(new Date());
|
cmoutmsg.setCoutmsgsDateInserted(new Date());
|
||||||
cmoutmsg.setCoutmsgsClobMsg(exchangeService.objectToXmlstr(rqfdMsg));
|
cmoutmsg.setCoutmsgsClobMsg(exchangeService.getCoutmsgsClobMsg(rqfdMsg));
|
||||||
cmoutmsg.setRoutingid(SUBSYSTEMS.OSH5RQFD.name());
|
cmoutmsg.setRoutingid(SUBSYSTEMS.OSH5RQFD.name());
|
||||||
|
|
||||||
Cmoutmsg rtCmoutmsg = cmoutmsgDao.save(cmoutmsg);
|
Cmoutmsg rtCmoutmsg = cmoutmsgDao.save(cmoutmsg);
|
||||||
|
|||||||
+38
-1
@@ -1,9 +1,15 @@
|
|||||||
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
import javax.xml.stream.XMLInputFactory;
|
||||||
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
@@ -44,7 +50,6 @@ public class ExchangeServiceImpl implements IExchangeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
|
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
|
||||||
@@ -54,4 +59,36 @@ public class ExchangeServiceImpl implements IExchangeService {
|
|||||||
throw new ExchangeServiceException(e.getMessage(),e);
|
throw new ExchangeServiceException(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCoutmsgsClobMsg(MSG msg) {
|
||||||
|
try {
|
||||||
|
// First create Stax components we need
|
||||||
|
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
|
||||||
|
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
|
||||||
|
|
||||||
|
StringWriter out = new StringWriter();
|
||||||
|
XMLStreamWriter sw = xmlOutputFactory.createXMLStreamWriter(out);
|
||||||
|
|
||||||
|
// then Jackson components
|
||||||
|
XmlMapper mapper = new XmlMapper(xmlInputFactory);
|
||||||
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
|
||||||
|
|
||||||
|
sw.writeStartDocument();
|
||||||
|
sw.writeStartElement("MSG");
|
||||||
|
sw.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||||
|
sw.writeAttribute("xsi", "http://www.w3.org/2001/XMLSchema-instance", "noNamespaceSchemaLocation", "unisysaodbsis.xsd");
|
||||||
|
|
||||||
|
// Write whatever content POJOs...
|
||||||
|
mapper.writeValue(sw, msg.getMETA());
|
||||||
|
mapper.writeValue(sw, msg.getRQFD());
|
||||||
|
|
||||||
|
sw.writeEndDocument();
|
||||||
|
|
||||||
|
return out.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ExchangeServiceException(e.getMessage(),e);
|
||||||
|
}
|
||||||
|
}// end function
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
||||||
|
|
||||||
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
||||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,4 +12,5 @@ public interface IExchangeService {
|
|||||||
public String xmlstrToJson(String xml) throws ExchangeServiceException;
|
public String xmlstrToJson(String xml) throws ExchangeServiceException;
|
||||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException;
|
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException;
|
||||||
public String objectToXmlstr(Object object) throws ExchangeServiceException;
|
public String objectToXmlstr(Object object) throws ExchangeServiceException;
|
||||||
|
public String getCoutmsgsClobMsg(MSG msg) throws ExchangeServiceException;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user