Search in sources :

Example 1 with EndpointTransformerDefinition

use of org.apache.camel.model.transformer.EndpointTransformerDefinition in project camel by apache.

the class TransformerListCommandTest method doTest.

private String doTest(boolean verbose) throws Exception {
    CamelContext context = new DefaultCamelContext();
    EndpointTransformerDefinition etd = new EndpointTransformerDefinition();
    etd.setFromType("xml:foo");
    etd.setToType("json:bar");
    etd.setUri("direct:transformer");
    context.getTransformers().add(etd);
    DataFormatTransformerDefinition dftd = new DataFormatTransformerDefinition();
    dftd.setFromType(this.getClass());
    dftd.setToType("xml:test");
    dftd.setDataFormatType(new StringDataFormat());
    context.getTransformers().add(dftd);
    CustomTransformerDefinition ctd = new CustomTransformerDefinition();
    ctd.setScheme("custom");
    ctd.setClassName(MyTransformer.class.getName());
    context.getTransformers().add(ctd);
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();
    CamelController controller = new DummyCamelController(context);
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    TransformerListCommand command = new TransformerListCommand(null, false, verbose, false);
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    context.stop();
    return out;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EndpointTransformerDefinition(org.apache.camel.model.transformer.EndpointTransformerDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DataFormatTransformerDefinition(org.apache.camel.model.transformer.DataFormatTransformerDefinition) CustomTransformerDefinition(org.apache.camel.model.transformer.CustomTransformerDefinition) StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat)

Example 2 with EndpointTransformerDefinition

use of org.apache.camel.model.transformer.EndpointTransformerDefinition in project camel by apache.

the class TransformerBuilder method configure.

/**
     * Configure a Transformer according to the configurations built on this builder
     * and register it into given {@code CamelContext}.
     * 
     * @param camelContext {@code CamelContext}
     */
public void configure(CamelContext camelContext) {
    TransformerDefinition transformer;
    if (uri != null) {
        EndpointTransformerDefinition etd = new EndpointTransformerDefinition();
        etd.setUri(uri);
        transformer = etd;
    } else if (dataFormat != null) {
        DataFormatTransformerDefinition dtd = new DataFormatTransformerDefinition();
        dtd.setDataFormatType(dataFormat);
        transformer = dtd;
    } else if (clazz != null) {
        CustomTransformerDefinition ctd = new CustomTransformerDefinition();
        ctd.setClassName(clazz.getName());
        transformer = ctd;
    } else if (beanRef != null) {
        CustomTransformerDefinition ctd = new CustomTransformerDefinition();
        ctd.setRef(beanRef);
        transformer = ctd;
    } else {
        throw new IllegalArgumentException("No Transformer type was specified");
    }
    if (scheme != null) {
        transformer.setScheme(scheme);
    } else {
        transformer.setFromType(from);
        transformer.setToType(to);
    }
    camelContext.getTransformers().add(transformer);
}
Also used : CustomTransformerDefinition(org.apache.camel.model.transformer.CustomTransformerDefinition) DataFormatTransformerDefinition(org.apache.camel.model.transformer.DataFormatTransformerDefinition) TransformerDefinition(org.apache.camel.model.transformer.TransformerDefinition) EndpointTransformerDefinition(org.apache.camel.model.transformer.EndpointTransformerDefinition) CustomTransformerDefinition(org.apache.camel.model.transformer.CustomTransformerDefinition) EndpointTransformerDefinition(org.apache.camel.model.transformer.EndpointTransformerDefinition) DataFormatTransformerDefinition(org.apache.camel.model.transformer.DataFormatTransformerDefinition)

Aggregations

CustomTransformerDefinition (org.apache.camel.model.transformer.CustomTransformerDefinition)2 DataFormatTransformerDefinition (org.apache.camel.model.transformer.DataFormatTransformerDefinition)2 EndpointTransformerDefinition (org.apache.camel.model.transformer.EndpointTransformerDefinition)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 CamelContext (org.apache.camel.CamelContext)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ExplicitCamelContextNameStrategy (org.apache.camel.impl.ExplicitCamelContextNameStrategy)1 StringDataFormat (org.apache.camel.model.dataformat.StringDataFormat)1 TransformerDefinition (org.apache.camel.model.transformer.TransformerDefinition)1