use of org.apache.camel.converter.crypto.CryptoDataFormat in project camel by apache.
the class CryptoDataFormatAutoConfiguration method configureCryptoDataFormatFactory.
@Bean(name = "crypto-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(CryptoDataFormat.class)
public DataFormatFactory configureCryptoDataFormatFactory(final CamelContext camelContext, final CryptoDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
CryptoDataFormat dataformat = new CryptoDataFormat();
if (CamelContextAware.class.isAssignableFrom(CryptoDataFormat.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.converter.crypto.CryptoDataFormat in project wildfly-camel by wildfly-extras.
the class CryptoDataFormatIntegrationTest method testMarshalUnmarshallDes.
@Test
public void testMarshalUnmarshallDes() throws Exception {
final KeyGenerator generator = KeyGenerator.getInstance("DES");
final CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(cryptoFormat).unmarshal(cryptoFormat);
}
});
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", "password", String.class);
Assert.assertEquals("password", result.trim());
} finally {
camelctx.stop();
}
}
Aggregations