use of org.apache.camel.spi.DataFormat in project camel by apache.
the class BlueprintDataFormatResolver method resolveDataFormat.
@Override
public DataFormat resolveDataFormat(String name, CamelContext context) {
DataFormat dataFormat = null;
DataFormatResolver resolver = context.getRegistry().lookupByNameAndType(".camelBlueprint.dataformatResolver." + name, DataFormatResolver.class);
if (resolver != null) {
LOG.debug("Found dataformat resolver: {} in registry: {}", name, resolver);
dataFormat = resolver.resolveDataFormat(name, context);
}
if (dataFormat == null) {
dataFormat = super.resolveDataFormat(name, context);
}
return dataFormat;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DefaultDataFormatResolver method createDataFormatFromResource.
private DataFormat createDataFormatFromResource(String name, CamelContext context) {
DataFormat dataFormat = null;
Class<?> type = null;
try {
if (dataformatFactory == null) {
dataformatFactory = context.getFactoryFinder(DATAFORMAT_RESOURCE_PATH);
}
type = dataformatFactory.findClass(name);
} catch (NoFactoryAvailableException e) {
// ignore
} catch (Exception e) {
throw new IllegalArgumentException("Invalid URI, no DataFormat registered for scheme: " + name, e);
}
if (type == null) {
type = context.getClassResolver().resolveClass(name);
}
if (type != null) {
if (DataFormat.class.isAssignableFrom(type)) {
dataFormat = (DataFormat) context.getInjector().newInstance(type);
} else {
throw new IllegalArgumentException("Resolving dataformat: " + name + " detected type conflict: Not a DataFormat implementation. Found: " + type.getName());
}
}
return dataFormat;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DefaultDataFormatResolver method createDataFormat.
@Override
public DataFormat createDataFormat(String name, CamelContext context) {
DataFormat dataFormat = null;
// lookup in registry first
DataFormatFactory dataFormatFactory = ResolverHelper.lookupDataFormatFactoryInRegistryWithFallback(context, name);
if (dataFormatFactory != null) {
dataFormat = dataFormatFactory.newInstance();
}
if (dataFormat == null) {
dataFormat = createDataFormatFromResource(name, context);
}
return dataFormat;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class ZipDataFormatTest method testMarshalMandatoryConversionFailed.
public void testMarshalMandatoryConversionFailed() throws Exception {
DataFormat dataFormat = new ZipDataFormat();
try {
dataFormat.marshal(new DefaultExchange(new DefaultCamelContext()), new Object(), new ByteArrayOutputStream());
fail("Should have thrown an exception");
} catch (NoTypeConversionAvailableException e) {
// expected
}
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class CsvTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// START SNIPPET: e1
// setup beanio data format using the mapping file, loaded from the classpath
DataFormat format = new BeanIODataFormat("org/apache/camel/dataformat/beanio/csv/mappings.xml", "stream1");
// a route which uses the bean io data format to format a CSV data
// to java objects
from("direct:unmarshal").unmarshal(format).split(body()).to("mock:beanio-unmarshal");
// convert list of java objects back to flat format
from("direct:marshal").marshal(format).to("mock:beanio-marshal");
// END SNIPPET: e1
}
};
}
Aggregations