Search in sources :

Example 21 with MessageDeliveryException

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;
}
Also used : URISyntaxException(java.net.URISyntaxException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) URI(java.net.URI)

Example 22 with MessageDeliveryException

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();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) CountDownLatch(java.util.concurrent.CountDownLatch) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 23 with MessageDeliveryException

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);
    }
}
Also used : MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) ExecutionException(java.util.concurrent.ExecutionException)

Example 24 with MessageDeliveryException

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;
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) MessagingException(org.springframework.messaging.MessagingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 25 with MessageDeliveryException

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));
    }
}
Also used : RendezvousChannel(org.springframework.integration.channel.RendezvousChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Test(org.junit.Test)

Aggregations

MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)47 Test (org.junit.Test)19 GenericMessage (org.springframework.messaging.support.GenericMessage)17 QueueChannel (org.springframework.integration.channel.QueueChannel)13 MessagingException (org.springframework.messaging.MessagingException)10 MessageChannel (org.springframework.messaging.MessageChannel)8 Message (org.springframework.messaging.Message)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 DirectChannel (org.springframework.integration.channel.DirectChannel)5 MessageHandler (org.springframework.messaging.MessageHandler)5 MessageHeaders (org.springframework.messaging.MessageHeaders)4 PollableChannel (org.springframework.messaging.PollableChannel)4 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 FileNotFoundException (java.io.FileNotFoundException)2 Date (java.util.Date)2 List (java.util.List)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2