use of org.apache.camel.Converter in project camel by apache.
the class SpringIntegrationConverter method toSpringMessage.
@Converter
public static org.springframework.messaging.Message<?> toSpringMessage(final org.apache.camel.Message camelMessage) throws Exception {
if (camelMessage instanceof SpringIntegrationMessage) {
SpringIntegrationMessage siMessage = (SpringIntegrationMessage) camelMessage;
org.springframework.messaging.Message<?> message = siMessage.getMessage();
if (message != null) {
return message;
}
}
// Create a new spring message and copy the attributes and body from the camel message
MessageHeaders messageHeaders = new MessageHeaders(camelMessage.getHeaders());
return new GenericMessage<Object>(camelMessage.getBody(), messageHeaders);
}
use of org.apache.camel.Converter in project camel by apache.
the class ElasticsearchActionRequestConverter method toMultiGetRequest.
@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 AnnotationTypeConverterLoader method loadConverterMethods.
/**
* Loads all of the converter methods for the given type
*/
protected void loadConverterMethods(TypeConverterRegistry registry, Class<?> type) {
if (visitedClasses.contains(type)) {
return;
}
visitedClasses.add(type);
try {
Method[] methods = type.getDeclaredMethods();
CachingInjector<?> injector = null;
for (Method method : methods) {
// in two different jars (as is the case sometimes with specs).
if (ObjectHelper.hasAnnotation(method, Converter.class, true)) {
boolean allowNull = false;
if (method.getAnnotation(Converter.class) != null) {
allowNull = method.getAnnotation(Converter.class).allowNull();
}
injector = handleHasConverterAnnotation(registry, type, injector, method, allowNull);
} else if (ObjectHelper.hasAnnotation(method, FallbackConverter.class, true)) {
boolean allowNull = false;
if (method.getAnnotation(FallbackConverter.class) != null) {
allowNull = method.getAnnotation(FallbackConverter.class).allowNull();
}
injector = handleHasFallbackConverterAnnotation(registry, type, injector, method, allowNull);
}
}
Class<?> superclass = type.getSuperclass();
if (superclass != null && !superclass.equals(Object.class)) {
loadConverterMethods(registry, superclass);
}
} catch (NoClassDefFoundError e) {
boolean ignore = false;
// does the class allow to ignore the type converter when having load errors
if (ObjectHelper.hasAnnotation(type, Converter.class, true)) {
if (type.getAnnotation(Converter.class) != null) {
ignore = type.getAnnotation(Converter.class).ignoreOnLoadError();
}
}
// if we should ignore then only log at debug level
if (ignore) {
LOG.debug("Ignoring converter type: " + type.getCanonicalName() + " as a dependent class could not be found: " + e, e);
} else {
LOG.warn("Ignoring converter type: " + type.getCanonicalName() + " as a dependent class could not be found: " + e, e);
}
}
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlConverter method toDOMNodeFromSAX.
@Converter
public Node toDOMNodeFromSAX(SAXSource source) throws ParserConfigurationException, IOException, SAXException, TransformerException {
DOMResult result = new DOMResult();
toResult(source, result);
return result.getNode();
}
use of org.apache.camel.Converter in project camel by apache.
the class XmlConverter method toByteArray.
/**
* Converts the given input Source into bytes
*/
@Converter
public byte[] toByteArray(Source source, Exchange exchange) throws TransformerException {
if (source instanceof BytesSource) {
return ((BytesSource) source).getData();
} else {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
if (exchange != null) {
// check the camelContext properties first
Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX, exchange.getContext());
if (properties.size() > 0) {
toResult(source, new StreamResult(buffer), properties);
return buffer.toByteArray();
}
}
// using the old way to deal with it
toResult(source, new StreamResult(buffer));
return buffer.toByteArray();
}
}
Aggregations