GH-2748: More bean definitions into exceptions
Fixes https://github.com/spring-projects/spring-integration/issues/2748 * Refactor more `MessageHandlingException`s to include `this` into an exception message * Revert using `MessagingException` in some places which really are not about messaging. This helps to wrap them into `MessageHandlingException` later in the `MessageHandler` for the `BeanDefinition` reference * Remove `volatile` from configuration properties in the affected classes * Remove already deprecated `JmsOutboundGateway.setPriority()` * Add `resource` and `source` for `BeanDefinition` in the `AbstractChannelAdapterParser` & `AbstractInboundGatewayParser` * Document the feature
This commit is contained in:
committed by
Gary Russell
parent
0ed88c3268
commit
80d679a9b0
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.xml.selector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.integration.xml.AggregatedXmlMessageValidationExcepti
|
||||
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
|
||||
import org.springframework.integration.xml.XmlPayloadConverter;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -65,7 +65,7 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
|
||||
}
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
private static final Log LOGGER = LogFactory.getLog(XmlValidatingMessageSelector.class);
|
||||
|
||||
private final XmlValidator xmlValidator;
|
||||
|
||||
@@ -110,7 +110,6 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
|
||||
/**
|
||||
* Specify the Converter to use when converting payloads prior to validation.
|
||||
*
|
||||
* @param converter The payload converter.
|
||||
*/
|
||||
public void setConverter(XmlPayloadConverter converter) {
|
||||
@@ -120,21 +119,22 @@ public class XmlValidatingMessageSelector implements MessageSelector {
|
||||
|
||||
@Override
|
||||
public boolean accept(Message<?> message) {
|
||||
SAXParseException[] validationExceptions = null;
|
||||
SAXParseException[] validationExceptions;
|
||||
try {
|
||||
validationExceptions = this.xmlValidator.validate(this.converter.convertToSource(message.getPayload()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessageHandlingException(message, e);
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions);
|
||||
if (!validationSuccess) {
|
||||
String exceptionMessage = "Message was rejected due to XML Validation errors";
|
||||
if (this.throwExceptionOnRejection) {
|
||||
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors",
|
||||
throw new MessageRejectedException(message, exceptionMessage,
|
||||
new AggregatedXmlMessageValidationException(Arrays.asList(validationExceptions)));
|
||||
}
|
||||
else if (this.logger.isInfoEnabled()) {
|
||||
this.logger.info("Message was rejected due to XML Validation errors",
|
||||
else if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(exceptionMessage,
|
||||
new AggregatedXmlMessageValidationException(Arrays.asList(validationExceptions)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,13 +210,13 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
protected Object splitMessage(Message<?> message) {
|
||||
try {
|
||||
Object payload = message.getPayload();
|
||||
Object result = null;
|
||||
Object result;
|
||||
if (payload instanceof Node) {
|
||||
result = splitNode((Node) payload);
|
||||
}
|
||||
else {
|
||||
Document document = this.xmlPayloadConverter.convertToDocument(payload);
|
||||
Assert.notNull(document, "unsupported payload type [" + payload.getClass().getName() + "]");
|
||||
Assert.notNull(document, () -> "unsupported payload type [" + payload.getClass().getName() + "]");
|
||||
result = splitDocument(document);
|
||||
}
|
||||
return result;
|
||||
@@ -226,7 +226,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(message,
|
||||
() -> "Failed to split Message payload", ex);
|
||||
() -> "Failed to split Message payload in the [" + this + ']', ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,9 +369,7 @@ public class XPathMessageSplitter extends AbstractMessageSplitter {
|
||||
|
||||
private final Iterator<Node> delegate;
|
||||
|
||||
TransformFunctionIterator(Iterator<Node> delegate,
|
||||
Function<? super Node, ? extends String> function) {
|
||||
|
||||
TransformFunctionIterator(Iterator<Node> delegate, Function<? super Node, ? extends String> function) {
|
||||
super(null, delegate, function);
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user