Example usage for org.springframework.messaging MessagingException getCause

List of usage examples for org.springframework.messaging MessagingException getCause

Introduction

In this page you can find the example usage for org.springframework.messaging MessagingException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:nz.co.senanque.messaging.ErrorEndpoint.java

public void unpackMessage(Message<?> message, Object context) {
    // this is always an error so extract the error message and throw an exception.
    final MessagingException messagingException = (MessagingException) message.getPayload();
    throw new WorkflowException(messagingException.getCause().getMessage());
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testMethodInvokingRouter2() {
    Message<String> fooMessage = MessageBuilder.withPayload("foo").setHeader("targetChannel", "foo").build();
    Message<String> barMessage = MessageBuilder.withPayload("bar").setHeader("targetChannel", "bar").build();
    Message<String> badMessage = MessageBuilder.withPayload("bad").setHeader("targetChannel", "bad").build();

    this.routerMethod2Input.send(fooMessage);

    Message<?> result1a = this.fooChannel.receive(2000);
    assertNotNull(result1a);/*from   ww w. j a  v  a 2 s . c om*/
    assertEquals("foo", result1a.getPayload());
    assertNull(this.barChannel.receive(0));

    this.routerMethod2Input.send(barMessage);
    assertNull(this.fooChannel.receive(0));
    Message<?> result2b = this.barChannel.receive(2000);
    assertNotNull(result2b);
    assertEquals("bar", result2b.getPayload());

    try {
        this.routerMethod2Input.send(badMessage);
        fail("DestinationResolutionException expected.");
    } catch (MessagingException e) {
        assertThat(e.getCause(), instanceOf(DestinationResolutionException.class));
        assertThat(e.getCause().getMessage(),
                containsString("failed to look up MessageChannel with name 'bad-channel'"));
    }

}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testMethodInvokingRouter3() {
    Message<String> fooMessage = new GenericMessage<>("foo");
    Message<String> barMessage = new GenericMessage<>("bar");
    Message<String> badMessage = new GenericMessage<>("bad");

    this.routerMethod3Input.send(fooMessage);

    Message<?> result1a = this.fooChannel.receive(2000);
    assertNotNull(result1a);/*from w w w .  j ava 2s  . c om*/
    assertEquals("foo", result1a.getPayload());
    assertNull(this.barChannel.receive(0));

    this.routerMethod3Input.send(barMessage);
    assertNull(this.fooChannel.receive(0));
    Message<?> result2b = this.barChannel.receive(2000);
    assertNotNull(result2b);
    assertEquals("bar", result2b.getPayload());

    try {
        this.routerMethod3Input.send(badMessage);
        fail("DestinationResolutionException expected.");
    } catch (MessagingException e) {
        assertThat(e.getCause(), instanceOf(DestinationResolutionException.class));
        assertThat(e.getCause().getMessage(),
                containsString("failed to look up MessageChannel with name 'bad-channel'"));
    }
}

From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java

@Test
public void testInt3412FileMode() {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(ftpSessionFactory);
    assertFalse(template.exists("ftpTarget/appending.txt"));
    Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt")
            .build();//w  w w .java2s.c  o  m
    appending.send(m);
    appending.send(m);

    assertLength6(template);

    ignoring.send(m);
    assertLength6(template);
    try {
        failing.send(m);
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
    }

}

From source file:org.springframework.integration.ftp.session.FtpRemoteFileTemplateTests.java

@Test
public void testFileCloseOnBadConnect() throws Exception {
    @SuppressWarnings("unchecked")
    SessionFactory<FTPFile> sessionFactory = mock(SessionFactory.class);
    when(sessionFactory.getSession()).thenThrow(new RuntimeException("bar"));
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
    template.setRemoteDirectoryExpression(new LiteralExpression("foo"));
    template.afterPropertiesSet();/* w ww  .  j a  v  a2s.  c  o  m*/
    File file = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    FileOutputStream fileOutputStream = new FileOutputStream(file);
    fileOutputStream.write("foo".getBytes());
    fileOutputStream.close();
    try {
        template.send(new GenericMessage<File>(file));
        fail("exception expected");
    } catch (MessagingException e) {
        assertEquals("bar", e.getCause().getMessage());
    }
    File newFile = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    assertTrue(file.renameTo(newFile));
    file.delete();
    newFile.delete();
}

From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java

@Test
public void testInt3412FileMode() {
    Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt")
            .build();/*from w  ww.j a va 2 s .co  m*/
    appending.send(m);
    appending.send(m);

    SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sessionFactory);
    assertLength6(template);

    ignoring.send(m);
    assertLength6(template);
    try {
        failing.send(m);
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
    }

}