Fix Sonar smells for XML module
This commit is contained in:
committed by
Gary Russell
parent
7e0a5e90b4
commit
0c32a57e99
@@ -71,12 +71,7 @@ public class DefaultXmlPayloadConverter implements XmlPayloadConverter {
|
||||
}
|
||||
else if (object instanceof DOMSource) {
|
||||
Node node = ((DOMSource) object).getNode();
|
||||
if (node instanceof Document) {
|
||||
return (Document) node;
|
||||
}
|
||||
else {
|
||||
return nodeToDocument(node);
|
||||
}
|
||||
return nodeToDocument(node);
|
||||
}
|
||||
else if (object instanceof Source) {
|
||||
InputSource inputSource = sourceToInputSource((Source) object);
|
||||
@@ -111,6 +106,9 @@ public class DefaultXmlPayloadConverter implements XmlPayloadConverter {
|
||||
}
|
||||
|
||||
protected Document nodeToDocument(Node node) {
|
||||
if (node instanceof Document) {
|
||||
return (Document) node;
|
||||
}
|
||||
Document document = getDocumentBuilder().newDocument();
|
||||
document.appendChild(document.importNode(node, true));
|
||||
return document;
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.xml.transformer;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
@@ -29,7 +30,6 @@ import org.w3c.dom.Document;
|
||||
import org.springframework.integration.transformer.AbstractPayloadTransformer;
|
||||
import org.springframework.integration.xml.source.DomSourceFactory;
|
||||
import org.springframework.integration.xml.source.SourceFactory;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -96,8 +96,7 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object,
|
||||
|
||||
@Override
|
||||
public Object transformPayload(Object payload) {
|
||||
Source source = null;
|
||||
|
||||
Source source;
|
||||
try {
|
||||
if (this.mimeMessageUnmarshallerHelper != null) {
|
||||
Object result = this.mimeMessageUnmarshallerHelper.maybeUnmarshalMimeMessage(payload);
|
||||
@@ -127,15 +126,14 @@ public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object,
|
||||
else {
|
||||
source = this.sourceFactory.createSource(payload);
|
||||
}
|
||||
if (source == null) {
|
||||
throw new MessagingException(
|
||||
"failed to transform message, payload not assignable from " + Source.class.getName()
|
||||
+ "and no conversion possible");
|
||||
}
|
||||
Assert.state(source != null, () ->
|
||||
"failed to transform message, payload not assignable from " + Source.class.getName()
|
||||
+ "and no conversion possible");
|
||||
|
||||
return this.unmarshaller.unmarshal(source);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("failed to unmarshal payload", e);
|
||||
throw new UncheckedIOException("failed to unmarshal payload", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,9 +156,9 @@ public class XsltPayloadTransformer extends AbstractXmlTransformer implements Be
|
||||
String transformerFactoryClassName) {
|
||||
|
||||
Assert.notNull(xslResource, "'xslResource' must not be null.");
|
||||
Assert.isTrue(xslResource instanceof ClassPathResource || // NOSONAR boolean complexity
|
||||
Assert.isTrue(xslResource instanceof ClassPathResource ||
|
||||
xslResource instanceof FileSystemResource ||
|
||||
xslResource instanceof VfsResource ||
|
||||
xslResource instanceof VfsResource || // NOSONAR boolean complexity
|
||||
(SERVLET_CONTEXT_RESOURCE_CLASS != null
|
||||
&& SERVLET_CONTEXT_RESOURCE_CLASS.isInstance(xslResource)),
|
||||
"Only 'ClassPathResource', 'FileSystemResource', 'ServletContextResource' or 'VfsResource'" +
|
||||
|
||||
Reference in New Issue
Block a user