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