Search in sources :

Example 41 with MessagingException

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

the class RoutingSlipTests method testInvalidRoutingSlipRoutStrategy.

@Test
public void testInvalidRoutingSlipRoutStrategy() {
    try {
        new RoutingSlipHeaderValueMessageProcessor(new Date());
        fail("IllegalArgumentException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(IllegalArgumentException.class));
        assertThat(e.getMessage(), containsString("The RoutingSlip can contain " + "only bean names of MessageChannel or RoutingSlipRouteStrategy, " + "or MessageChannel and RoutingSlipRouteStrategy instances"));
    }
    try {
        this.invalidRoutingSlipChannel.send(new GenericMessage<>("foo"));
        fail("MessagingException expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessagingException.class));
        assertThat(e.getMessage(), containsString("replyChannel must be a MessageChannel or String"));
    }
}
Also used : RoutingSlipHeaderValueMessageProcessor(org.springframework.integration.transformer.support.RoutingSlipHeaderValueMessageProcessor) Date(java.util.Date) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Example 42 with MessagingException

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

the class TcpConnectionSupport method waitForListenerRegistration.

private void waitForListenerRegistration() {
    try {
        Assert.state(this.listenerRegisteredLatch.await(1, TimeUnit.MINUTES), "TcpListener not registered");
        this.manualListenerRegistration = false;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MessagingException("Interrupted while waiting for listener registration", e);
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException)

Example 43 with MessagingException

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

the class MBeanTreePollingMessageSource method doReceive.

/**
 * Provides the mapped tree object
 */
@Override
protected Object doReceive() {
    Assert.notNull(this.server, "MBeanServer is required");
    try {
        Map<String, Object> beans = new HashMap<String, Object>();
        Set<ObjectInstance> results = this.server.queryMBeans(this.queryName, this.queryExpression);
        for (ObjectInstance instance : results) {
            Object result = this.converter.convert(this.server, instance);
            beans.put(instance.getObjectName().getCanonicalName(), result);
        }
        return beans;
    } catch (Exception e) {
        throw new MessagingException("Failed to retrieve tree snapshot", e);
    }
}
Also used : HashMap(java.util.HashMap) MessagingException(org.springframework.messaging.MessagingException) ObjectInstance(javax.management.ObjectInstance) MalformedObjectNameException(javax.management.MalformedObjectNameException) MessagingException(org.springframework.messaging.MessagingException)

Example 44 with MessagingException

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

the class RemoteFileTemplate method sendFileToRemoteDirectory.

private void sendFileToRemoteDirectory(InputStream inputStream, String temporaryRemoteDirectory, String remoteDirectory, String fileName, Session<F> session, FileExistsMode mode) throws IOException {
    remoteDirectory = this.normalizeDirectoryPath(remoteDirectory);
    temporaryRemoteDirectory = this.normalizeDirectoryPath(temporaryRemoteDirectory);
    String remoteFilePath = remoteDirectory + fileName;
    String tempRemoteFilePath = temporaryRemoteDirectory + fileName;
    // write remote file first with temporary file extension if enabled
    String tempFilePath = tempRemoteFilePath + (this.useTemporaryFileName ? this.temporaryFileSuffix : "");
    if (this.autoCreateDirectory) {
        try {
            RemoteFileUtils.makeDirectories(remoteDirectory, session, this.remoteFileSeparator, this.logger);
        } catch (IllegalStateException e) {
            // Revert to old FTP behavior if recursive mkdir fails, for backwards compatibility
            session.mkdir(remoteDirectory);
        }
    }
    try {
        boolean rename = this.useTemporaryFileName;
        if (FileExistsMode.REPLACE.equals(mode)) {
            session.write(inputStream, tempFilePath);
        } else if (FileExistsMode.APPEND.equals(mode)) {
            session.append(inputStream, tempFilePath);
        } else {
            if (exists(remoteFilePath)) {
                if (FileExistsMode.FAIL.equals(mode)) {
                    throw new MessagingException("The destination file already exists at '" + remoteFilePath + "'.");
                } else {
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("File not transferred to '" + remoteFilePath + "'; already exists.");
                    }
                }
                rename = false;
            } else {
                session.write(inputStream, tempFilePath);
            }
        }
        // then rename it to its final name if necessary
        if (rename) {
            session.rename(tempFilePath, remoteFilePath);
        }
    } catch (Exception e) {
        throw new MessagingException("Failed to write to '" + tempFilePath + "' while uploading the file", e);
    } finally {
        inputStream.close();
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) FileNotFoundException(java.io.FileNotFoundException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 45 with MessagingException

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

the class TcpSendingMessageHandlerTests method testConnectionException.

@Test
public void testConnectionException() throws Exception {
    TcpSendingMessageHandler handler = new TcpSendingMessageHandler();
    AbstractConnectionFactory mockCcf = mock(AbstractClientConnectionFactory.class);
    Mockito.doAnswer(invocation -> {
        throw new SocketException("Failed to connect");
    }).when(mockCcf).getConnection();
    handler.setConnectionFactory(mockCcf);
    try {
        handler.handleMessage(new GenericMessage<String>("foo"));
        fail("Expected exception");
    } catch (Exception e) {
        assertTrue(e instanceof MessagingException);
        assertTrue(e.getCause() != null);
        assertTrue(e.getCause() instanceof SocketException);
        assertEquals("Failed to connect", e.getCause().getMessage());
    }
}
Also used : SocketException(java.net.SocketException) AbstractConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory) MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) SocketException(java.net.SocketException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MessagingException (org.springframework.messaging.MessagingException)145 Test (org.junit.Test)61 IOException (java.io.IOException)25 Message (org.springframework.messaging.Message)23 QueueChannel (org.springframework.integration.channel.QueueChannel)22 ErrorMessage (org.springframework.messaging.support.ErrorMessage)21 CountDownLatch (java.util.concurrent.CountDownLatch)17 MessageHandlingException (org.springframework.messaging.MessageHandlingException)16 BeanFactory (org.springframework.beans.factory.BeanFactory)15 MessageChannel (org.springframework.messaging.MessageChannel)15 GenericMessage (org.springframework.messaging.support.GenericMessage)15 MessageHandler (org.springframework.messaging.MessageHandler)14 File (java.io.File)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 DirectChannel (org.springframework.integration.channel.DirectChannel)12 ArrayList (java.util.ArrayList)11 PollableChannel (org.springframework.messaging.PollableChannel)11 Lock (java.util.concurrent.locks.Lock)8 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)8