use of org.apache.camel.Converter in project camel by apache.
the class MailConverters method toString.
/**
* Converts the given JavaMail message to a String body.
* Can return null.
*/
@Converter
public static String toString(Message message) throws MessagingException, IOException {
Object content = message.getContent();
while (content instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) content;
if (multipart.getCount() > 0) {
BodyPart part = multipart.getBodyPart(0);
content = part.getContent();
}
}
if (content != null) {
return content.toString();
}
return null;
}
use of org.apache.camel.Converter in project camel by apache.
the class CustomerTransformer method toCustomer.
/**
* A transformation method to convert a person document into a customer
* entity
*/
@Converter
public static CustomerEntity toCustomer(PersonDocument doc, Exchange exchange) throws Exception {
EntityManager entityManager = exchange.getProperty(JpaConstants.ENTITY_MANAGER, EntityManager.class);
TransactionTemplate transactionTemplate = exchange.getContext().getRegistry().lookupByNameAndType("transactionTemplate", TransactionTemplate.class);
String user = doc.getUser();
CustomerEntity customer = findCustomerByName(transactionTemplate, entityManager, user);
// let's convert information from the document into the entity bean
customer.setUserName(user);
customer.setFirstName(doc.getFirstName());
customer.setSurname(doc.getLastName());
customer.setCity(doc.getCity());
LOG.info("Created object customer: {}", customer);
return customer;
}
use of org.apache.camel.Converter in project camel by apache.
the class MyConverter method toPojo.
@Converter
public static Pojo toPojo(String name) {
Pojo pojo = new Pojo();
pojo.setName(name);
return pojo;
}
use of org.apache.camel.Converter in project camel by apache.
the class FooConverter method convertToFoo.
@Converter
public Foo convertToFoo(String data) {
String[] s = data.split(",");
Foo foo = new Foo();
foo.setFirst(s[0]);
foo.setLast(s[1]);
return foo;
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlRpcConverter method toXmlRpcRequest.
@Converter
public static XmlRpcRequest toXmlRpcRequest(final Object[] parameters, Exchange exchange) {
// get the message operation name
String operationName = exchange.getIn().getHeader(XmlRpcConstants.METHOD_NAME, String.class);
// create the request object here
XmlRpcRequest request = new XmlRpcRequestImpl(operationName, parameters);
return request;
}
Aggregations