本文整理汇总了Java中org.apache.camel.impl.DefaultMessage.setBody方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMessage.setBody方法的具体用法?Java DefaultMessage.setBody怎么用?Java DefaultMessage.setBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.impl.DefaultMessage
的用法示例。
在下文中一共展示了DefaultMessage.setBody方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: splitMessage
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
/**
* The split message method returns something that is iteratable such as a java.util.List.
*
* @param header the header of the incoming message with the name user
* @param body the payload of the incoming message
* @return a list containing each part splitted
*/
public List<Message> splitMessage(@Header(value = "user") String header, @Body String body) {
// we can leverage the Parameter Binding Annotations
// http://camel.apache.org/parameter-binding-annotations.html
// to access the message header and body at same time,
// then create the message that we want, splitter will
// take care rest of them.
// *NOTE* this feature requires Camel version >= 1.6.1
List<Message> answer = new ArrayList<Message>();
String[] parts = header.split(",");
for (String part : parts) {
DefaultMessage message = new DefaultMessage();
message.setHeader("user", part);
message.setBody(body);
answer.add(message);
}
return answer;
}
示例2: mapSwitchYardToCamel
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
/**
* Maps a SwitchYard exchange to a Camel exchange. Keep in mind that the camel message created
* during mapping is *not* associate with the exchange. You need to call setIn() or setOut()
* with the returned reference depending on your use case.
* @param syExchange switchyard exchange
* @param camelExchange camel exchange
* @return mapped camel message
*/
public static DefaultMessage mapSwitchYardToCamel(
org.switchyard.Exchange syExchange,
org.apache.camel.Exchange camelExchange) {
DefaultMessage camelMessage = new SwitchYardMessage();
camelMessage.setBody(syExchange.getMessage().getContent());
mapSwitchYardPropertiesToCamel(syExchange.getContext(), camelExchange, camelMessage);
for (String attachmentName : syExchange.getMessage().getAttachmentMap().keySet()) {
camelMessage.addAttachment(attachmentName,
new DataHandler(syExchange.getMessage().getAttachment(attachmentName)));
}
return camelMessage;
}
示例3: toCamelMessage
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
/**
* 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;
}
示例4: splitProducts
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
public List<Message> splitProducts(Order order){
List<Message> messages = new ArrayList<Message>();
for(Item item : order.getItems()){
ProductOrder po = new ProductOrder();
po.setCustomer(order.getCustomer());
po.setProduct(item.getProduct());
po.setQuanitity(item.getQuantity());
DefaultMessage message = new DefaultMessage();
message.setBody(po);
//Set the header with the manufacturer
if (item.getProduct().startsWith("abc")) {
message.setHeader("manufacturer", "abc");
} else if(item.getProduct().startsWith("xyz")) {
message.setHeader("manufacturer", "xyz");
}
messages.add(message);
}
return messages;
}
示例5: createCamelExchange
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
/**
* Create a camel exchange
* @return exchange
*/
private Exchange createCamelExchange() {
DefaultMessage message = new DefaultMessage();
message.setBody("foobar");
message.setExchange(new DefaultExchange(new SwitchYardCamelContextImpl(false)));
return message.getExchange();
}
示例6: sendMessage
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
protected void sendMessage(final String uri, final Object obj) {
Exchange exchange = new DefaultExchange(contextFactory.getContext());
DefaultMessage message = new DefaultMessage(camelContext);
message.setBody(obj);
exchange.setIn(message);
ProducerTemplate template = contextFactory.getContext().createProducerTemplate();
template.send(uri, exchange);
}
示例7: createExchange
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
public Exchange createExchange(Object pojo) {
DefaultMessage msg = new DefaultMessage();
msg.setBody(pojo);
DefaultExchange exchange = new DefaultExchange(this, getExchangePattern());
exchange.setIn(msg);
return exchange;
}
示例8: createExhangeWithBody
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
private static Exchange createExhangeWithBody(final String payload) {
final Exchange exchange = new DefaultExchange(CONTEXT);
final DefaultMessage in = new DefaultMessage(CONTEXT);
exchange.setIn(in);
in.setBody(payload);
return exchange;
}
示例9: process
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
DefaultMessage message = new DefaultMessage();
message.setBody("current time: " + new Date());
exchange.setOut(message);
}
示例10: fillFromDataValue
import org.apache.camel.impl.DefaultMessage; //导入方法依赖的package包/类
/**
* Fill a Message from a DataValue
*
* @param value
* the value to feed from
* @param result
* the result to feed to
*/
public static void fillFromDataValue(final DataValue value, final DefaultMessage result) {
result.setBody(value);
result.setFault(value.getStatusCode().isBad());
}