Search in sources :

Example 1 with ProcessorTransformer

use of org.apache.camel.impl.transformer.ProcessorTransformer in project camel by apache.

the class EndpointTransformerDefinition method doCreateTransformer.

@Override
protected Transformer doCreateTransformer(CamelContext context) throws Exception {
    Endpoint endpoint = uri != null ? context.getEndpoint(uri) : context.getRegistry().lookupByNameAndType(ref, Endpoint.class);
    SendProcessor processor = new SendProcessor(endpoint, ExchangePattern.InOut);
    return new ProcessorTransformer(context).setProcessor(processor).setModel(getScheme()).setFrom(getFromType()).setTo(getToType());
}
Also used : Endpoint(org.apache.camel.Endpoint) SendProcessor(org.apache.camel.processor.SendProcessor) ProcessorTransformer(org.apache.camel.impl.transformer.ProcessorTransformer)

Example 2 with ProcessorTransformer

use of org.apache.camel.impl.transformer.ProcessorTransformer in project camel by apache.

the class TransformerBuilderTest method testEndpointTransformer.

public void testEndpointTransformer() throws Exception {
    CamelContext ctx = new DefaultCamelContext();
    RouteBuilder builder = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            transformer().fromType("json:foo").toType("xml:bar").withUri("direct:transformer");
            from("direct:transformer").log("test");
        }
    };
    ctx.addRoutes(builder);
    ctx.start();
    Transformer transformer = ctx.resolveTransformer(new DataType("json:foo"), new DataType("xml:bar"));
    assertNotNull(transformer);
    assertEquals(ProcessorTransformer.class, transformer.getClass());
    ProcessorTransformer pt = (ProcessorTransformer) transformer;
    Field f = ProcessorTransformer.class.getDeclaredField("processor");
    f.setAccessible(true);
    Object processor = f.get(pt);
    assertEquals(SendProcessor.class, processor.getClass());
    SendProcessor sp = (SendProcessor) processor;
    assertEquals("direct://transformer", sp.getEndpoint().getEndpointUri());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Field(java.lang.reflect.Field) ProcessorTransformer(org.apache.camel.impl.transformer.ProcessorTransformer) Transformer(org.apache.camel.spi.Transformer) DataFormatTransformer(org.apache.camel.impl.transformer.DataFormatTransformer) DataType(org.apache.camel.spi.DataType) SendProcessor(org.apache.camel.processor.SendProcessor) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProcessorTransformer(org.apache.camel.impl.transformer.ProcessorTransformer)

Aggregations

ProcessorTransformer (org.apache.camel.impl.transformer.ProcessorTransformer)2 SendProcessor (org.apache.camel.processor.SendProcessor)2 Field (java.lang.reflect.Field)1 CamelContext (org.apache.camel.CamelContext)1 Endpoint (org.apache.camel.Endpoint)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DataFormatTransformer (org.apache.camel.impl.transformer.DataFormatTransformer)1 DataType (org.apache.camel.spi.DataType)1 Transformer (org.apache.camel.spi.Transformer)1