Search in sources :

Example 1 with StringDataFormat

use of org.apache.camel.model.dataformat.StringDataFormat in project camel by apache.

the class DataFormatClause method string.

/**
     * Uses the String data format supporting encoding using given charset
     */
public T string(String charset) {
    StringDataFormat sdf = new StringDataFormat();
    sdf.setCharset(charset);
    return dataFormat(sdf);
}
Also used : StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat)

Example 2 with StringDataFormat

use of org.apache.camel.model.dataformat.StringDataFormat in project camel by apache.

the class TransformerBuilderTest method testDataFormatTransformer.

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

        @Override
        public void configure() throws Exception {
            transformer().fromType("xml:foo").toType("json:bar").withDataFormat(new StringDataFormat());
            from("direct:input").log("test");
        }
    };
    ctx.addRoutes(builder);
    ctx.start();
    Transformer transformer = ctx.resolveTransformer(new DataType("xml:foo"), new DataType("json:bar"));
    assertNotNull(transformer);
    assertEquals(DataFormatTransformer.class, transformer.getClass());
    DataFormatTransformer dft = (DataFormatTransformer) transformer;
    Field f = DataFormatTransformer.class.getDeclaredField("dataFormatType");
    f.setAccessible(true);
    Object dataFormatType = f.get(dft);
    assertEquals(StringDataFormat.class, dataFormatType.getClass());
}
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) StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat) DataType(org.apache.camel.spi.DataType) DataFormatTransformer(org.apache.camel.impl.transformer.DataFormatTransformer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 3 with StringDataFormat

use of org.apache.camel.model.dataformat.StringDataFormat 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 4 with StringDataFormat

use of org.apache.camel.model.dataformat.StringDataFormat in project camel by apache.

the class ManagedTransformerRegistryTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            transformer().fromType("xml:foo").toType("json:bar").withUri("direct:transformer");
            transformer().fromType(ManagedTransformerRegistryTest.class).toType("xml:test").withDataFormat(new StringDataFormat());
            transformer().scheme("custom").withJava(MyTransformer.class);
            from("direct:start").to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat)

Aggregations

StringDataFormat (org.apache.camel.model.dataformat.StringDataFormat)4 CamelContext (org.apache.camel.CamelContext)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Field (java.lang.reflect.Field)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 ExplicitCamelContextNameStrategy (org.apache.camel.impl.ExplicitCamelContextNameStrategy)1 DataFormatTransformer (org.apache.camel.impl.transformer.DataFormatTransformer)1 ProcessorTransformer (org.apache.camel.impl.transformer.ProcessorTransformer)1 CustomTransformerDefinition (org.apache.camel.model.transformer.CustomTransformerDefinition)1 DataFormatTransformerDefinition (org.apache.camel.model.transformer.DataFormatTransformerDefinition)1 EndpointTransformerDefinition (org.apache.camel.model.transformer.EndpointTransformerDefinition)1 DataType (org.apache.camel.spi.DataType)1 Transformer (org.apache.camel.spi.Transformer)1