Example usage for org.springframework.messaging MessagingException getMessage

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

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.springframework.integration.handler.AsyncHandlerTests.java

@Test
public void testGatewayWithException() throws Exception {
    this.whichTest = 0;
    GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class);
    gpfb.setBeanFactory(mock(BeanFactory.class));
    DirectChannel input = new DirectChannel();
    gpfb.setDefaultRequestChannel(input);
    gpfb.setDefaultReplyTimeout(10000L);
    gpfb.afterPropertiesSet();/*  w  ww. ja  v a 2s  .  c o m*/
    Foo foo = (Foo) gpfb.getObject();
    this.handler.setOutputChannel(null);
    EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler);
    consumer.afterPropertiesSet();
    consumer.start();
    this.latch.countDown();
    try {
        foo.exchange("foo");
    } catch (MessagingException e) {
        assertThat(e.getClass().getSimpleName(), equalTo("RuntimeException"));
        assertThat(e.getMessage(), equalTo("foo"));
    }
}

From source file:org.springframework.integration.ip.tcp.connection.ConnectionEventTests.java

@Test
public void testOutboundGatewayNoConnectionEvents() {
    TcpOutboundGateway gw = new TcpOutboundGateway();
    AbstractClientConnectionFactory ccf = new AbstractClientConnectionFactory("localhost", 0) {
    };//from ww w.  j a v a2 s.  c o m
    final AtomicReference<ApplicationEvent> theEvent = new AtomicReference<ApplicationEvent>();
    ccf.setApplicationEventPublisher(new ApplicationEventPublisher() {

        @Override
        public void publishEvent(Object event) {
        }

        @Override
        public void publishEvent(ApplicationEvent event) {
            theEvent.set(event);
        }

    });
    gw.setConnectionFactory(ccf);
    DirectChannel requestChannel = new DirectChannel();
    requestChannel
            .subscribe(message -> ((MessageChannel) message.getHeaders().getReplyChannel()).send(message));
    gw.start();
    Message<String> message = MessageBuilder.withPayload("foo").setHeader(IpHeaders.CONNECTION_ID, "bar")
            .build();
    gw.onMessage(message);
    assertNotNull(theEvent.get());
    TcpConnectionFailedCorrelationEvent event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
    assertEquals("bar", event.getConnectionId());
    MessagingException messagingException = (MessagingException) event.getCause();
    assertSame(message, messagingException.getFailedMessage());
    assertEquals("Cannot correlate response - no pending reply for bar", messagingException.getMessage());

    message = new GenericMessage<String>("foo");
    gw.onMessage(message);
    assertNotNull(theEvent.get());
    event = (TcpConnectionFailedCorrelationEvent) theEvent.get();
    assertNull(event.getConnectionId());
    messagingException = (MessagingException) event.getCause();
    assertSame(message, messagingException.getFailedMessage());
    assertEquals("Cannot correlate response - no connection id", messagingException.getMessage());
}

From source file:org.springframework.integration.zip.transformer.UnZipTransformerTests.java

/**
 * UnCompress a ZIP archive containing multiple files. The result will be
 * a collection of files.//from w  w w.  ja  v  a  2 s.  c  o m
 *
 * @throws IOException
 */
@Test
public void unzipMultipleFilesAsInputStreamWithExpectSingleResultTrue() throws IOException {

    final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/countries.zip");
    final InputStream is = resource.getInputStream();

    final Message<InputStream> message = MessageBuilder.withPayload(is).build();

    final UnZipTransformer unZipTransformer = new UnZipTransformer();
    unZipTransformer.setZipResultType(ZipResultType.BYTE_ARRAY);
    unZipTransformer.setExpectSingleResult(true);
    unZipTransformer.afterPropertiesSet();

    try {
        unZipTransformer.transform(message);
    } catch (MessagingException e) {
        Assert.assertTrue(e.getMessage().contains(
                "The UnZip operation extracted " + "5 result objects but expectSingleResult was 'true'."));
        return;
    }

    Assert.fail("Expected a MessagingException to be thrown.");

}

From source file:org.springframework.integration.zip.transformer.UnZipTransformerTests.java

@Test
public void unzipInvalidZipFile() throws IOException, InterruptedException {

    File fileToUnzip = this.testFolder.newFile();
    FileUtils.writeStringToFile(fileToUnzip, "hello world");

    UnZipTransformer unZipTransformer = new UnZipTransformer();
    unZipTransformer.setZipResultType(ZipResultType.BYTE_ARRAY);
    unZipTransformer.setExpectSingleResult(true);
    unZipTransformer.afterPropertiesSet();

    Message<File> message = MessageBuilder.withPayload(fileToUnzip).build();

    try {//ww  w .  j  a  v  a 2 s.  c o  m
        unZipTransformer.transform(message);
        Assert.fail("Expected a MessagingException to be thrown.");
    } catch (MessagingException e) {
        Assert.assertTrue(
                e.getMessage().contains(String.format("Not a zip file: '%s'.", fileToUnzip.getAbsolutePath())));
    }
}