Search in sources :

Example 1 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class CxfConverter method soapMessageToString.

@Converter
public static String soapMessageToString(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    soapMessage.writeTo(baos);
    return baos.toString(IOHelper.getCharsetName(exchange));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

Example 2 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class CxfConverter method soapMessageToInputStream.

@Converter
public static InputStream soapMessageToInputStream(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException {
    CachedOutputStream cos = new CachedOutputStream(exchange);
    soapMessage.writeTo(cos);
    InputStream in = cos.getInputStream();
    return in;
}
Also used : InputStream(java.io.InputStream) CachedOutputStream(org.apache.camel.converter.stream.CachedOutputStream) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

Example 3 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class ElasticsearchActionRequestConverter method toMultiGetRequest.

@SuppressWarnings("unchecked")
@Converter
public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
    List<Item> items = (List<Item>) document;
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    Iterator<Item> it = items.iterator();
    while (it.hasNext()) {
        MultiGetRequest.Item item = it.next();
        multiGetRequest.add(item);
    }
    return multiGetRequest;
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) List(java.util.List) Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) Converter(org.apache.camel.Converter)

Example 4 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class ElasticsearchActionRequestConverter method toSearchRequest.

@Converter
public static SearchRequest toSearchRequest(Object queryObject, Exchange exchange) {
    SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class)).types(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class));
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    String queryText = null;
    if (queryObject instanceof Map<?, ?>) {
        Map<String, Object> mapQuery = (Map<String, Object>) queryObject;
        // Remove 'query' prefix from the query object for backward compatibility
        if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
            mapQuery = (Map<String, Object>) mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
        }
        try {
            XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
            queryText = contentBuilder.map(mapQuery).string();
        } catch (IOException e) {
            LOG.error(e.getMessage());
        }
    } else if (queryObject instanceof String) {
        queryText = (String) queryObject;
        ObjectMapper mapper = new ObjectMapper();
        try {
            JsonNode jsonTextObject = mapper.readValue(queryText, JsonNode.class);
            JsonNode parentJsonNode = jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
            if (parentJsonNode != null) {
                queryText = parentJsonNode.toString();
            }
        } catch (IOException e) {
            LOG.error(e.getMessage());
        }
    } else {
        // Cannot convert the queryObject into SearchRequest
        return null;
    }
    searchSourceBuilder.query(QueryBuilders.wrapperQuery(queryText));
    searchRequest.source(searchSourceBuilder);
    return searchRequest;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Map(java.util.Map) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Converter(org.apache.camel.Converter)

Example 5 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class ElasticsearchActionRequestConverter method toMultiSearchRequest.

@SuppressWarnings("unchecked")
@Converter
public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
    List<SearchRequest> items = (List<SearchRequest>) document;
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    Iterator<SearchRequest> it = items.iterator();
    while (it.hasNext()) {
        SearchRequest item = it.next();
        multiSearchRequest.add(item);
    }
    return multiSearchRequest;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) List(java.util.List) 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