I am using camel to transfer files from one endpoint to another. I am starting multiple routes in which some routes need to decrypt the files. How can i make the unmarshal process optional in a specific route based on a boolean condition?
from(source)
.choice()
.when(isEncrypted())) //Java boolean value
.unmarshal(decrypt(pgpEncryptionDetails))
.endChoice()
to(destination);
PGPDataFormat decrypt(PGPEncryptionDetails pgpEncryptionDetails) {
PGPDataFormat pgpDataFormat = new PGPDataFormat();
pgpDataFormat.setKeyFileName(pgpEncryptionDetails.getPrivateKeyPath());
pgpDataFormat.setPassword(pgpEncryptionDetails.getPassphrase());
pgpDataFormat.setKeyUserid(pgpEncryptionDetails.getUserId());
return pgpDataFormat;
}
I know how to do with a simple expression but here my condition not depends on exchange.
Its working for me.
You can use a method call expression to call a method on a java bean which implements the predicate
And then use the method in the Camel route