Search in sources :

Example 1 with DataFormat

use of org.apache.camel.spi.DataFormat in project camel by apache.

the class OsgiDataFormatResolverTest method testOsgiResolverFindDataFormatFallbackTest.

@Test
public void testOsgiResolverFindDataFormatFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar-dataformat", new SampleDataFormat(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    OsgiDataFormatResolver resolver = new OsgiDataFormatResolver(getBundleContext());
    DataFormat dataformat = resolver.resolveDataFormat("allstar", camelContext);
    assertNotNull("We should find the super dataformat", dataformat);
    assertTrue("We should get the super dataformat here", dataformat instanceof SampleDataFormat);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DataFormat(org.apache.camel.spi.DataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with DataFormat

use of org.apache.camel.spi.DataFormat in project camel by apache.

the class OsgiDataFormatResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.

@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("allstar", new SampleDataFormat(false));
    registry.put("allstar-dataformat", new SampleDataFormat(true));
    CamelContext camelContext = new DefaultCamelContext(registry);
    OsgiDataFormatResolver resolver = new OsgiDataFormatResolver(getBundleContext());
    DataFormat dataformat = resolver.resolveDataFormat("allstar", camelContext);
    assertNotNull("We should find the super dataformat", dataformat);
    assertTrue("We should get the super dataformat here", dataformat instanceof SampleDataFormat);
    assertFalse("We should NOT find the fallback dataformat", ((SampleDataFormat) dataformat).isFallback());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DataFormat(org.apache.camel.spi.DataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with DataFormat

use of org.apache.camel.spi.DataFormat in project camel by apache.

the class DozerProducer method resolveMarshaller.

/**
     * Find and configure an unmarshaller for the specified data format.
     */
private synchronized MarshalProcessor resolveMarshaller(Exchange exchange, String dataFormatId) throws Exception {
    if (marshaller == null) {
        DataFormat dataFormat = DataFormatDefinition.getDataFormat(exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
        if (dataFormat == null) {
            throw new Exception("Unable to resolve data format for marshalling: " + dataFormatId);
        }
        // Wrap the data format in a processor and start/configure it.  
        // Stop/shutdown is handled when the corresponding methods are 
        // called on this producer.
        marshaller = new MarshalProcessor(dataFormat);
        marshaller.setCamelContext(exchange.getContext());
        marshaller.start();
    }
    return marshaller;
}
Also used : MarshalProcessor(org.apache.camel.processor.MarshalProcessor) DataFormat(org.apache.camel.spi.DataFormat)

Example 4 with DataFormat

use of org.apache.camel.spi.DataFormat in project camel by apache.

the class DozerProducer method resolveUnmarshaller.

/**
     * Find and configure an unmarshaller for the specified data format.
     */
private synchronized UnmarshalProcessor resolveUnmarshaller(Exchange exchange, String dataFormatId) throws Exception {
    if (unmarshaller == null) {
        DataFormat dataFormat = DataFormatDefinition.getDataFormat(exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
        if (dataFormat == null) {
            throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId);
        }
        // Wrap the data format in a processor and start/configure it.  
        // Stop/shutdown is handled when the corresponding methods are 
        // called on this producer.
        unmarshaller = new UnmarshalProcessor(dataFormat);
        unmarshaller.setCamelContext(exchange.getContext());
        unmarshaller.start();
    }
    return unmarshaller;
}
Also used : UnmarshalProcessor(org.apache.camel.processor.UnmarshalProcessor) DataFormat(org.apache.camel.spi.DataFormat)

Example 5 with DataFormat

use of org.apache.camel.spi.DataFormat in project camel by apache.

the class DataFormatComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String name = ObjectHelper.before(remaining, ":");
    // try to lookup data format in the registry or create it from resource
    DataFormat df = getCamelContext().resolveDataFormat(name);
    if (df == null) {
        // if not, try to find a factory in the registry
        df = getCamelContext().createDataFormat(name);
    }
    if (df == null) {
        throw new IllegalArgumentException("Cannot find data format with name: " + name);
    }
    String operation = ObjectHelper.after(remaining, ":");
    if (!"marshal".equals(operation) && !"unmarshal".equals(operation)) {
        throw new IllegalArgumentException("Operation must be either marshal or unmarshal, was: " + operation);
    }
    // set reference properties first as they use # syntax that fools the regular properties setter
    EndpointHelper.setReferenceProperties(getCamelContext(), df, parameters);
    EndpointHelper.setProperties(getCamelContext(), df, parameters);
    DataFormatEndpoint endpoint = new DataFormatEndpoint(uri, this, df);
    endpoint.setOperation(operation);
    setProperties(endpoint, parameters);
    return endpoint;
}
Also used : DataFormat(org.apache.camel.spi.DataFormat)

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