use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class AbstractWebServiceOutboundGateway method handleRequestMessage.
@Override
public final Object handleRequestMessage(Message<?> requestMessage) {
URI uri = null;
try {
uri = this.prepareUri(requestMessage);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
if (uri == null) {
throw new MessageDeliveryException(requestMessage, "Failed to determine URI for " + "Web Service request in outbound gateway: " + this.getComponentName());
}
Object responsePayload = this.doHandle(uri.toString(), requestMessage, this.requestCallback);
if (responsePayload != null) {
boolean shouldIgnore = (this.ignoreEmptyResponses && responsePayload instanceof String && !StringUtils.hasText((String) responsePayload));
if (!shouldIgnore) {
return responsePayload;
}
}
return null;
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class RequestReplyScenariosWithTempReplyQueuesTests method testConcurrently.
@Test
public void testConcurrently() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("mult-producer-and-consumers-temp-reply.xml", this.getClass());
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
ExecutorService executor = Executors.newFixedThreadPool(10);
final int testNumbers = 30;
final CountDownLatch latch = new CountDownLatch(testNumbers);
final AtomicInteger failures = new AtomicInteger();
final AtomicInteger timeouts = new AtomicInteger();
final AtomicInteger missmatches = new AtomicInteger();
for (int i = 0; i < testNumbers; i++) {
final int y = i;
executor.execute(() -> {
try {
String reply = (String) gateway.exchange(new GenericMessage<String>(String.valueOf(y))).getPayload();
if (!String.valueOf(y).equals(reply)) {
missmatches.incrementAndGet();
}
} catch (Exception e) {
if (e instanceof MessageDeliveryException) {
timeouts.incrementAndGet();
} else {
failures.incrementAndGet();
}
}
latch.countDown();
});
}
assertTrue(latch.await(30, TimeUnit.SECONDS));
print(failures, timeouts, missmatches, testNumbers);
assertEquals(0, missmatches.get());
assertEquals(0, failures.get());
assertEquals(0, timeouts.get());
context.close();
executor.shutdownNow();
}
use of org.springframework.messaging.MessageDeliveryException in project spring-framework by spring-projects.
the class DefaultStompSession method execute.
private void execute(Message<byte[]> message) {
if (logger.isTraceEnabled()) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (accessor != null) {
logger.trace("Sending " + accessor.getDetailedLogMessage(message.getPayload()));
}
}
TcpConnection<byte[]> conn = this.connection;
Assert.state(conn != null, "Connection closed");
try {
conn.send(message).get();
} catch (ExecutionException ex) {
throw new MessageDeliveryException(message, ex.getCause());
} catch (Throwable ex) {
throw new MessageDeliveryException(message, ex);
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-framework by spring-projects.
the class AbstractMessageChannel method send.
@Override
public final boolean send(Message<?> message, long timeout) {
Assert.notNull(message, "Message must not be null");
Message<?> messageToUse = message;
ChannelInterceptorChain chain = new ChannelInterceptorChain();
boolean sent = false;
try {
messageToUse = chain.applyPreSend(messageToUse, this);
if (messageToUse == null) {
return false;
}
sent = sendInternal(messageToUse, timeout);
chain.applyPostSend(messageToUse, this, sent);
chain.triggerAfterSendCompletion(messageToUse, this, sent, null);
return sent;
} catch (Exception ex) {
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex);
if (ex instanceof MessagingException) {
throw (MessagingException) ex;
}
throw new MessageDeliveryException(messageToUse, "Failed to send message to " + this, ex);
} catch (Throwable err) {
MessageDeliveryException ex2 = new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err);
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2);
throw ex2;
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class ContentEnricherTests method requestChannelSendTimingOut.
@Test
public void requestChannelSendTimingOut() {
final String requestChannelName = "Request_Channel";
final long requestTimeout = 200L;
QueueChannel replyChannel = new QueueChannel();
QueueChannel requestChannel = new RendezvousChannel();
requestChannel.setBeanName(requestChannelName);
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setRequestTimeout(requestTimeout);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
try {
enricher.handleMessage(requestMessage);
} catch (MessageDeliveryException e) {
assertThat(e.getMessage(), equalToIgnoringCase("failed to send message to channel '" + requestChannelName + "' within timeout: " + requestTimeout));
}
}
Aggregations