Search in sources :

Example 11 with DataFormat

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;
}
Also used : DataFormatResolver(org.apache.camel.spi.DataFormatResolver) OsgiDataFormatResolver(org.apache.camel.core.osgi.OsgiDataFormatResolver) DataFormat(org.apache.camel.spi.DataFormat)

Example 12 with 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;
}
Also used : DataFormat(org.apache.camel.spi.DataFormat) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException)

Example 13 with 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;
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) DataFormat(org.apache.camel.spi.DataFormat)

Example 14 with 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
    }
}
Also used : NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) DataFormat(org.apache.camel.spi.DataFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 15 with DataFormat

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
        }
    };
}
Also used : BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) RouteBuilder(org.apache.camel.builder.RouteBuilder) DataFormat(org.apache.camel.spi.DataFormat) BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat)

Aggregations

DataFormat (org.apache.camel.spi.DataFormat)45 RouteBuilder (org.apache.camel.builder.RouteBuilder)20 Exchange (org.apache.camel.Exchange)8 Processor (org.apache.camel.Processor)8 JaxbDataFormat (org.apache.camel.converter.jaxb.JaxbDataFormat)6 CamelContext (org.apache.camel.CamelContext)5 Test (org.junit.Test)5 JAXBContext (javax.xml.bind.JAXBContext)2 Rfc5425FrameDecoder (org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 QRY_A19 (ca.uhn.hl7v2.model.v24.message.QRY_A19)1 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Key (java.security.Key)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1