Search in sources :

Example 46 with Converter

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;
}
Also used : BodyPart(javax.mail.BodyPart) MimeMultipart(javax.mail.internet.MimeMultipart) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter) IOConverter(org.apache.camel.converter.IOConverter)

Example 47 with Converter

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;
}
Also used : EntityManager(javax.persistence.EntityManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Converter(org.apache.camel.Converter)

Example 48 with Converter

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;
}
Also used : Pojo(org.apache.camel.itest.Pojo) Converter(org.apache.camel.Converter)

Example 49 with Converter

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;
}
Also used : Foo(org.apache.camel.test.blueprint.Foo) Converter(org.apache.camel.Converter)

Example 50 with Converter

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;
}
Also used : XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) Converter(org.apache.camel.Converter)

Aggregations

Converter (org.apache.camel.Converter)71 TypeConverter (org.apache.camel.TypeConverter)11 FallbackConverter (org.apache.camel.FallbackConverter)10 InputStream (java.io.InputStream)8 ByteBuffer (java.nio.ByteBuffer)7 IOConverter (org.apache.camel.converter.IOConverter)7 InputSource (org.xml.sax.InputSource)6 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 List (java.util.List)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 SAXSource (javax.xml.transform.sax.SAXSource)3 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3