use of org.apache.camel.dataformat.avro.AvroDataFormat in project wildfly-camel by wildfly-extras.
the class AvroDataFormatTest method testMarshalUnmarshal.
@Test
public void testMarshalUnmarshal() throws Exception {
DataFormat avro = new AvroDataFormat(getSchema());
GenericRecord input = new GenericData.Record(getSchema());
input.put("name", "Kermit");
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(avro).unmarshal(avro);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
GenericRecord result = producer.requestBody("direct:start", input, GenericRecord.class);
Assert.assertEquals("Kermit", result.get("name").toString());
} finally {
camelctx.stop();
}
}
use of org.apache.camel.dataformat.avro.AvroDataFormat in project camel by apache.
the class AvroDataFormatAutoConfiguration method configureAvroDataFormatFactory.
@Bean(name = "avro-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(AvroDataFormat.class)
public DataFormatFactory configureAvroDataFormatFactory(final CamelContext camelContext, final AvroDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
AvroDataFormat dataformat = new AvroDataFormat();
if (CamelContextAware.class.isAssignableFrom(AvroDataFormat.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
return dataformat;
}
};
}
Aggregations