Search in sources :

Example 56 with MessageHandlingException

use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.

the class UriVariableTests method testInt2720XmppUriVariables.

@Test
public void testInt2720XmppUriVariables() throws Exception {
    willThrow(new WebServiceIOException("intentional")).given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
    try {
        this.inputXmpp.send(message);
    } catch (MessageHandlingException e) {
        // expected
        Class<?> causeType = e.getCause().getClass();
        // offline
        assertTrue(WebServiceIOException.class.equals(causeType));
    }
    ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
    Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
    assertEquals("user@jabber.org", argument.getValue().getTo().toString());
    assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 57 with MessageHandlingException

use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.

the class UnicastSendingMessageHandler method handleMessageInternal.

@Override
public void handleMessageInternal(Message<?> message) throws MessageHandlingException, MessageDeliveryException {
    if (this.acknowledge) {
        Assert.state(this.isRunning(), "When 'acknowledge' is enabled, adapter must be running");
        startAckThread();
    }
    CountDownLatch countdownLatch = null;
    String messageId = message.getHeaders().getId().toString();
    try {
        boolean waitForAck = this.waitForAck;
        if (waitForAck) {
            countdownLatch = new CountDownLatch(this.ackCounter);
            this.ackControl.put(messageId, countdownLatch);
        }
        convertAndSend(message);
        if (waitForAck) {
            try {
                if (!countdownLatch.await(this.ackTimeout, TimeUnit.MILLISECONDS)) {
                    throw new MessagingException(message, "Failed to receive UDP Ack in " + this.ackTimeout + " millis");
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    } catch (MessagingException e) {
        throw e;
    } catch (Exception e) {
        closeSocketIfNeeded();
        throw new MessageHandlingException(message, "failed to send UDP packet", e);
    } finally {
        if (countdownLatch != null) {
            this.ackControl.remove(messageId);
        }
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) CountDownLatch(java.util.concurrent.CountDownLatch) MessagingException(org.springframework.messaging.MessagingException) SocketException(java.net.SocketException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) IOException(java.io.IOException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Example 58 with MessageHandlingException

use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.

the class DatagramPacketMessageMapper method getPayloadAsBytes.

private byte[] getPayloadAsBytes(Message<?> message) {
    byte[] bytes = null;
    Object payload = message.getPayload();
    if (payload instanceof byte[]) {
        bytes = (byte[]) payload;
    } else if (payload instanceof String) {
        try {
            bytes = ((String) payload).getBytes(this.charset);
        } catch (UnsupportedEncodingException e) {
            throw new MessageHandlingException(message, e);
        }
    } else {
        throw new MessageHandlingException(message, "The datagram packet mapper expects " + "either a byte array or String payload, but received: " + payload.getClass());
    }
    return bytes;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Example 59 with MessageHandlingException

use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.

the class TcpMessageMapper method getPayloadAsBytes.

/**
 * Extracts the payload as a byte array.
 */
private byte[] getPayloadAsBytes(Message<?> message) {
    byte[] bytes = null;
    Object payload = message.getPayload();
    if (payload instanceof byte[]) {
        bytes = (byte[]) payload;
    } else if (payload instanceof String) {
        try {
            bytes = ((String) payload).getBytes(this.charset);
        } catch (UnsupportedEncodingException e) {
            throw new MessageHandlingException(message, e);
        }
    } else {
        throw new MessageHandlingException(message, "When using a byte array serializer, the socket mapper expects " + "either a byte array or String payload, but received: " + payload.getClass());
    }
    return bytes;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Example 60 with MessageHandlingException

use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.

the class TcpSendingMessageHandler method obtainConnection.

protected TcpConnection obtainConnection(Message<?> message) {
    TcpConnection connection = null;
    Assert.notNull(this.clientConnectionFactory, "'clientConnectionFactory' cannot be null");
    try {
        connection = this.clientConnectionFactory.getConnection();
    } catch (Exception e) {
        logger.error("Error creating connection", e);
        throw new MessageHandlingException(message, "Failed to obtain a connection", e);
    }
    return connection;
}
Also used : TcpConnection(org.springframework.integration.ip.tcp.connection.TcpConnection) IOException(java.io.IOException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Aggregations

MessageHandlingException (org.springframework.messaging.MessageHandlingException)65 Test (org.junit.Test)34 ErrorMessage (org.springframework.messaging.support.ErrorMessage)14 IOException (java.io.IOException)12 GenericMessage (org.springframework.messaging.support.GenericMessage)12 Message (org.springframework.messaging.Message)10 File (java.io.File)9 MessagingException (org.springframework.messaging.MessagingException)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 MessageRejectedException (org.springframework.integration.MessageRejectedException)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)4 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)3