use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class MessageChannelsMonitorIntegrationTests method testQueues.
@Test
public void testQueues() throws Exception {
ClassPathXmlApplicationContext context = createContext("queue-channel.xml", "queue");
try {
int before = service.getCounter();
CountDownLatch latch = new CountDownLatch(10);
service.setLatch(latch);
for (int i = 0; i < 5; i++) {
channel.send(new GenericMessage<String>("bar"));
Thread.sleep(20L);
}
try {
channel.send(new GenericMessage<String>("fail"));
} catch (MessageHandlingException e) {
// ignore
}
for (int i = 0; i < 5; i++) {
channel.send(new GenericMessage<String>("bar"));
Thread.sleep(20L);
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(before + 10, service.getCounter());
// The handler monitor is registered under the endpoint id (since it is explicit)
int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
assertEquals("No send statistics for input channel", 11, sends);
int receives = messageChannelsMonitor.getChannelReceiveCount("" + channel);
assertEquals("No send statistics for input channel", 11, receives);
int errors = messageChannelsMonitor.getChannelErrorRate("" + channel).getCount();
assertEquals("Expect no errors for input channel (handler fails)", 0, errors);
} finally {
context.close();
}
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class MessageChannelsMonitorIntegrationTests method testErrors.
@Test
public void testErrors() throws Exception {
ClassPathXmlApplicationContext context = createContext("anonymous-channel.xml", "anonymous");
try {
int before = service.getCounter();
CountDownLatch latch = new CountDownLatch(10);
service.setLatch(latch);
for (int i = 0; i < 5; i++) {
channel.send(new GenericMessage<String>("bar"));
Thread.sleep(20L);
}
try {
channel.send(new GenericMessage<String>("fail"));
} catch (MessageHandlingException e) {
// ignore
}
for (int i = 0; i < 5; i++) {
channel.send(new GenericMessage<String>("bar"));
Thread.sleep(20L);
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(before + 10, service.getCounter());
// The handler monitor is registered under the endpoint id (since it is explicit)
int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
assertEquals("No send statistics for input channel", 11, sends, 0.01);
int errors = messageChannelsMonitor.getChannelErrorRate("" + channel).getCount();
assertEquals("No error statistics for input channel", 1, errors, 0.01);
} finally {
context.close();
}
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class XmlValidatingMessageSelector method accept.
@Override
public boolean accept(Message<?> message) {
SAXParseException[] validationExceptions = null;
try {
validationExceptions = this.xmlValidator.validate(this.converter.convertToSource(message.getPayload()));
} catch (Exception e) {
throw new MessageHandlingException(message, e);
}
boolean validationSuccess = ObjectUtils.isEmpty(validationExceptions);
if (!validationSuccess) {
if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors", new AggregatedXmlMessageValidationException(Arrays.<Throwable>asList(validationExceptions)));
}
this.logger.debug("Message was rejected due to XML Validation errors");
}
return validationSuccess;
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class XPathMessageSplitter method splitMessage.
@Override
protected Object splitMessage(Message<?> message) {
try {
Object payload = message.getPayload();
Object result = null;
if (payload instanceof Node) {
result = splitNode((Node) payload);
} else {
Document document = this.xmlPayloadConverter.convertToDocument(payload);
Assert.notNull(document, "unsupported payload type [" + payload.getClass().getName() + "]");
result = splitDocument(document);
}
return result;
} catch (ParserConfigurationException e) {
throw new MessageConversionException(message, "failed to create DocumentBuilder", e);
} catch (Exception e) {
throw new MessageHandlingException(message, "failed to split Message payload", e);
}
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class SimpleWebServiceOutboundGatewayTests method testDomPoxMessageFactory.
@Test
public void testDomPoxMessageFactory() throws Exception {
String uri = "http://www.example.org";
SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
gateway.setBeanFactory(mock(BeanFactory.class));
final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
requestFuture.set(messageContext.getRequest());
return super.handleRequest(messageContext);
}
};
gateway.setInterceptors(interceptorAdapter);
gateway.setMessageFactory(new DomPoxMessageFactory());
gateway.afterPropertiesSet();
String request = "<test>foo</test>";
try {
gateway.handleMessage(new GenericMessage<>(request));
fail("Expected MessageHandlingException");
} catch (MessageHandlingException e) {
// expected
}
WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
assertNotNull(requestMessage);
assertThat(requestMessage, instanceOf(PoxMessage.class));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringResult stringResult = new StringResult();
transformer.transform(requestMessage.getPayloadSource(), stringResult);
assertEquals(request, stringResult.toString());
}
Aggregations