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.transform.MapTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:map-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);// www  .  ja  v  a2  s.  co  m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.XmlTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:xml-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);/* w  w w .  j  a  va2  s  .co m*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.JsonTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:json-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Customer customer = new Customer();
    customer.setFirstName("John");
    customer.setLastName("Smith");
    customer.setAddress("100 State Street");
    customer.setCity("Los Angeles");
    customer.setState("CA");
    customer.setZip("90064");

    System.out.println("toString(): " + customer.toString());

    Message<Customer> message = MessageBuilder.withPayload(customer).build();
    input.send(message);//from   ww  w .  ja  v a 2  s. co m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.Transformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*from   w  w w  .j a  va2s .  c o m*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.wiretap.WireTapExample.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:wiretap/wiretap.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);// w w w .  ja v a 2s  . c o m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.HeaderEnricher.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:header-enricher.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*from   www  . j  av a2  s  .c om*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}

From source file:com.apress.prospringintegration.webservice.client.TicketWebServiceDomClient.java

public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("client.xml");

    MessageChannel channel = context.getBean("ticketRequests", MessageChannel.class);

    String body = String.format(bodyTemplate, "Message Broker Down", "emergency");
    System.out.println(body);/*ww w .  j  a  va 2s.co  m*/
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    Message<?> message = messagingTemplate.sendAndReceive(channel, MessageBuilder.withPayload(body).build());

    System.out.println(message.getPayload());

}

From source file:com.apress.prospringintegration.transform.PayloadTypeTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:payload-type-transformer.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from  w ww.ja v  a  2 s .  co m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.claimcheck.ClaimCheckExample.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/spring/claimcheck-context.xml");

    MessageChannel input = context.getBean("checkinChannel", MessageChannel.class);
    PollableChannel output = context.getBean("checkoutChannel", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);//from  w w w  .  j a v a  2  s  . co m

    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:com.apress.prospringintegration.transform.ProgrammaticHeaderEnricher.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:programmatic-header-enricher.xml");

    MessageChannel input = context.getBean("input", MessageChannel.class);
    PollableChannel output = context.getBean("output", PollableChannel.class);

    Map<String, String> customerMap = new HashMap<String, String>();
    customerMap.put("firstName", "John");
    customerMap.put("lastName", "Smith");
    customerMap.put("address", "100 State Street");
    customerMap.put("city", "Los Angeles");
    customerMap.put("state", "CA");
    customerMap.put("zip", "90064");

    Message<Map<String, String>> message = MessageBuilder.withPayload(customerMap).build();
    input.send(message);/*from   w w  w  .java 2  s  .  c om*/

    Message<?> reply = output.receive();
    System.out.println("received: " + reply);
}