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));
}
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;
}
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;
}
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;
}
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;
}
Aggregations