/**
* {@inheritDoc}
*/
@Override
public Message compose(CamelBindingData source, Exchange exchange) throws Exception {
Message message = exchange.createMessage();
// map context properties
getContextMapper().mapFrom(source, exchange.getContext(message));
org.apache.camel.Message sourceMessage = source.getMessage();
// map content
QName msgType = getMessageType(exchange);
Object content;
if (msgType == null) {
content = sourceMessage.getBody();
} else if (QNameUtil.isJavaMessageType(msgType)) {
content = sourceMessage.getBody(QNameUtil.toJavaMessageType(msgType));
} else {
content = sourceMessage.getBody();
if (!(content instanceof String) && !(content instanceof Node)
&& !(content instanceof InputSource) && !(content instanceof Source)) {
// named binary content - content is not String nor XML, but has type name other than "java:*"
content = sourceMessage.getBody(InputStream.class);
}
}
message.setContent(content);
Set<String> attachements = sourceMessage.getAttachmentNames();
if (!attachements.isEmpty()) {
for (Entry<String, DataHandler> entry : sourceMessage.getAttachments().entrySet()) {
message.addAttachment(entry.getKey(), entry.getValue().getDataSource());
}
}
return message;
}