use of org.apache.camel.converter.crypto.PGPDataFormat in project camel by apache.
the class PGPDataFormatAutoConfiguration method configurePGPDataFormatFactory.
@Bean(name = "pgp-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(PGPDataFormat.class)
public DataFormatFactory configurePGPDataFormatFactory(final CamelContext camelContext, final PGPDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
PGPDataFormat dataformat = new PGPDataFormat();
if (CamelContextAware.class.isAssignableFrom(PGPDataFormat.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.PGPDataFormat in project wildfly-camel by wildfly-extras.
the class CryptoDataFormatIntegrationTest method testMarshallUnmarshallPgp.
@Test
public void testMarshallUnmarshallPgp() throws Exception {
final PGPDataFormat encrypt = new PGPDataFormat();
encrypt.setKeyFileName(PUBRING_GPG);
encrypt.setKeyUserid(KEY_USERID);
final PGPDataFormat decrypt = new PGPDataFormat();
decrypt.setKeyFileName(SECRING_GPG);
decrypt.setKeyUserid(KEY_USERID);
decrypt.setPassword(KEY_PASSWORD);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(encrypt).unmarshal(decrypt);
}
});
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