use of org.apache.camel.dataformat.protobuf.ProtobufDataFormat in project camel by apache.
the class ProtobufDataFormatAutoConfiguration method configureProtobufDataFormatFactory.
@Bean(name = "protobuf-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ProtobufDataFormat.class)
public DataFormatFactory configureProtobufDataFormatFactory(final CamelContext camelContext, final ProtobufDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
ProtobufDataFormat dataformat = new ProtobufDataFormat();
if (CamelContextAware.class.isAssignableFrom(ProtobufDataFormat.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;
}
};
}
use of org.apache.camel.dataformat.protobuf.ProtobufDataFormat in project wildfly-camel by wildfly-extras.
the class ProtobufIntegrationTest method testMarshall.
@Test
public void testMarshall() throws Exception {
final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(format);
}
});
Person person = Person.newBuilder().setId(1).setName("John Doe").build();
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", person, String.class);
Assert.assertEquals("John Doe", result.trim());
} finally {
camelctx.stop();
}
}
use of org.apache.camel.dataformat.protobuf.ProtobufDataFormat in project wildfly-camel by wildfly-extras.
the class ProtobufIntegrationTest method testUnmarshall.
@Test
public void testUnmarshall() throws Exception {
final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal(format);
}
});
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Person person = Person.newBuilder().setId(1).setName("John Doe").build();
person.writeTo(baos);
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Person result = producer.requestBody("direct:start", baos.toByteArray(), Person.class);
Assert.assertEquals("John Doe", result.getName().trim());
} finally {
camelctx.stop();
}
}
Aggregations