Java Code Examples for org.apache.camel.impl.DefaultMessage#setBody()

The following examples show how to use org.apache.camel.impl.DefaultMessage#setBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMessageConverter.java    From hazelcastmq with Apache License 2.0 6 votes vote down vote up
/**
 * Converts from a Camel message to a HzMq message. The headers are simply
 * copied unmodified. The body is mapped by type:
 * <ul>
 * <li>If the content type is text/plain, the body is set as a String</li>
 * <li>all others: the body is set as a byte[] (or null)</li>
 * </ul>
 *
 * @param mqMsg the HzMq message to convert
 *
 * @return the new Camel message
 */
@Override
public Message toCamelMessage(HazelcastMQMessage mqMsg) {
  DefaultMessage camelMsg = new DefaultMessage();

  camelMsg.setHeaders((Map) mqMsg.getHeaders().getHeaderMap());

  if (mqMsg.getContentType() != null && mqMsg.getContentType().equals(
      "text/plain")) {
    camelMsg.setBody(mqMsg.getBodyAsString());
  }
  else {
    camelMsg.setBody(mqMsg.getBody());
  }

  return camelMsg;
}
 
Example 2
Source File: InputGenerator.java    From java-course-ee with MIT License 3 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {

    DefaultMessage message = new DefaultMessage();
    message.setBody("current time: " + new Date());

    exchange.setOut(message);

}
 
Example 3
Source File: InputGenerator.java    From java-course-ee with MIT License 3 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {

    DefaultMessage message = new DefaultMessage();
    message.setBody("current time: " + new Date());

    exchange.setOut(message);

}