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);
}
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());
}
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;
}
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");
}
};
}
Aggregations