我如何在骆驼路线中使用Java布尔条件? [英] How do i use java boolean condition in camel route?

查看:117
本文介绍了我如何在骆驼路线中使用Java布尔条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用骆驼将文件从一个端点传输到另一个端点.我正在启动多条路由,其中​​一些路由需要解密文件.如何根据布尔条件在特定路由中使解组过程成为可选项目?

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.

推荐答案

对我有用.

from(source)
    .process(exchange -> decryptIfEncrypted(pgpEncryptionDetails))
to(destination);

ProcessDefinition decryptIfEncrypted(PGPEncryptionDetails pgpEncryptionDetails) {
    if (isPgpEncryped()) {
        PGPDataFormat pgpDataFormat = new PGPDataFormat();
        pgpDataFormat.setKeyFileName(pgpEncryptionDetails.getPrivateKeyPath());
        pgpDataFormat.setPassword(pgpEncryptionDetails.getPassphrase());
        pgpDataFormat.setKeyUserid(pgpEncryptionDetails.getUserId());
        return new ProcessDefinition().unmarshal(pgpDataFormat);
    }
    return new ProcessDefinition();
}

这篇关于我如何在骆驼路线中使用Java布尔条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆