Example usage for org.springframework.integration.support MessageBuilder withPayload

List of usage examples for org.springframework.integration.support MessageBuilder withPayload

Introduction

In this page you can find the example usage for org.springframework.integration.support MessageBuilder withPayload.

Prototype

public static <T> MessageBuilder<T> withPayload(T payload) 

Source Link

Document

Create a builder for a new Message instance with the provided payload.

Usage

From source file:com.apress.prospringintegration.messageflow.workflow.LoggingServiceActivator.java

public Message<?> log(Message<?> msg) throws Exception {

    log.debug("===========================================");
    for (String m : msg.getHeaders().keySet())
        log.debug(String.format("%s = %s", m, msg.getHeaders().get(m)));

    log.debug(ToStringBuilder.reflectionToString(msg));

    log.debug("about to wait for " + this.delay + " ms");

    Thread.sleep(this.delay);

    log.debug("finished waiting. Returning");

    return MessageBuilder.withPayload("All clear!").copyHeadersIfAbsent(msg.getHeaders()).build();
}

From source file:apiserver.services.images.services.ImageInfoService.java

public Object execute(Message<?> message) throws IOException {

    FileInfoJob props = (FileInfoJob) message.getPayload();

    Map result = new HashMap();
    result.put(ApiServerConstants.WIDTH, props.getBufferedImage().getWidth());
    result.put(ApiServerConstants.HEIGHT, props.getBufferedImage().getHeight());

    // return results
    MessageBuilder mb = MessageBuilder.withPayload(result);
    mb.copyHeaders(message.getHeaders());
    return mb.build();
}

From source file:com.manning.siia.kitchen.RecipeSplitterTest.java

@Test
public void shouldSplitRecipe() {
    Recipe recipe = RecipeObjectMother.friedEggRecipe();
    recipes.send(MessageBuilder.withPayload(recipe).build());
    receiveAndCheckIngredientMessage(new Grocery("egg", new Amount(1, Amount.Unit.PIECES)));
    receiveAndCheckIngredientMessage(new Grocery("butter", new Amount(20, Amount.Unit.GRAMS)));
}

From source file:com.joshlong.lazyblogger.integrations.NewBlogPublishingServiceActivator.java

public Message<?> publishIncomingBlogEntry(Message<?> msg) {
    try {/*  w ww .j av a2s  . co  m*/

        BlogPost payload = (BlogPost) msg.getPayload();
        utilities.log("Publishing " + payload.toString());
        blogService.publish(payload);
        return MessageBuilder.withPayload(msg).copyHeadersIfAbsent(msg.getHeaders())
                .setReplyChannelName("filesOut").build();
    } catch (Throwable e) {
        utilities.log(ExceptionUtils.getFullStackTrace(e));
    }
    return null;
}

From source file:siia.channels.ChannelsBridgeTest.java

@Test
public void testChannels() throws Exception {
    Booking booking = new Booking();
    booking.setCustomerEmail("user@example.com");
    booking.setFlightId("AC100");
    Message<Booking> bookingMessage = MessageBuilder.withPayload(booking).build();
    bookingsChannel.send(bookingMessage);
    Assert.assertEquals(1, emailConfirmationService.getEmails().size());
    Assert.assertEquals("user@example.com", emailConfirmationService.getEmails().get(0).getRecipient());
}

From source file:biz.c24.io.spring.integration.transformer.IoTransformerIUTests.java

@Test
public void canTransform() throws Exception {

    C24Transformer transformer = new C24Transformer();
    transformer.setTransformClass(ExampleTransform.class);

    Message<?> message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = transformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(OutputDocumentRoot.class));

}

From source file:siia.channels.AllChannelsDirectTest.java

@Test
public void testChannels() throws Exception {
    Booking booking = new Booking();
    booking.setCustomerEmail("user@example.com");
    booking.setFlightId("AC100");
    Message<Booking> bookingMessage = MessageBuilder.withPayload(booking).build();
    bookingsChannel.send(bookingMessage);

    Assert.assertEquals(1, emailConfirmationService.getEmails().size());
    Assert.assertEquals("user@example.com", emailConfirmationService.getEmails().get(0).getRecipient());
}

From source file:biz.c24.io.spring.integration.config.FileSplitterTests.java

@Test
public void defaultBatchSize() throws Exception {
    Boolean result = (Boolean) transformer
            .doTransform(MessageBuilder.withPayload((resource.getFile())).build());
    Message<List<String>> message;
    int messageCount = 0;
    for (int i = 0; i < 10; i++) {
        message = (Message<List<String>>) feedChannel.receive();
        assertThat(message.getPayload().get(0), is(i + 1 + ""));
        messageCount++;/*from w w  w.j a v a2s.  c  o  m*/
    }
    assertThat(messageCount, is(10));

}

From source file:com.apress.prospringintegration.messagestore.util.MessageProducer.java

public void sendMessages(int correlationValue, Collection<String> payloadValues) throws Throwable {

    int sequenceNumber = 0;
    int size = payloadValues.size();

    for (String payloadValue : payloadValues) {
        Message<?> message = MessageBuilder.withPayload(payloadValue).setCorrelationId(this.correlationHeader)
                .setHeader(this.correlationHeader, correlationValue).setSequenceNumber(++sequenceNumber)
                .setSequenceSize(size).build();
        this.messagingTemplate.send(message);
    }/*from  w w  w.ja  va2s  . c  om*/
}

From source file:siia.booking.integration.WeatherTest.java

@Test
public void testToronto() {
    // 4118 is the Yahoo! WOEID (Where On Earth ID) for Toronto, Canada
    Message message = MessageBuilder.withPayload("4118").build();
    Message response = channelTemplate.sendAndReceive(message);
    System.out.println(response.getPayload());
}