You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sammohamed <sm...@freelancersunion.org> on 2012/02/01 23:15:03 UTC

GPG encryption in camel 2.8.3

Hi,

We currently have a system using camel 2.8.3 in production and i am hesitant
to upgrade us to 2.9 simply so I can have GPG encryption for one route.  My
situation is as follows:

1) I generate a fixed width file from a repository bean using flat-pack
2) I want to encrypt the file that's generated in step 1
3) I want to SFTP the file to a third party vendor (I have this working)

Here is my route:
[code]
from("quartz://retirement/retirement-sync-timer?cron={{retirement.cron}}")
                .routeId("retirement-timed-sync")
                .noAutoStartup()
                .to(memberRepositoryEndPoint);

FlatpackDataFormat df = new FlatpackDataFormat();
        df.setDefinition(new
ClassPathResource("META-INF/smooks/fuintegration/retirement-fixed-width-mapping.xml"));
        df.setFixed(true);
        df.setIgnoreFirstRecord(false);

        from(memberRepositoryEndPoint)
                .to("log:org.fuwt?level=INFO")
                .routeId("retirement_file_generation")
                .marshal(df)
                .convertBodyTo(String.class)
                .log("log:org.fuwt?level=ERROR&showAll=false")
                .to(localFileEndPoint);

FUGPGUtils.encrypt(inFilePath <-- file generated by flat pack, pubKeyPath,
outFilePath);

from(encryptedFileEndPoint)
                .to("log:org.fuwt?level=INFO")
                .routeId("miliman_sftp_exchange")
                .to(sftpFileEndPoint);
[/code]

The Unit test for this route fails because the FUGPGUtils class says the
flatpack generated file doesn't exist.  n FUGPGUtils I use bouncy castle's
opengpg library for encryption and unit test for that class proves it is
working fine.  

When I remove the encryption call from the route and I just have camel SFTP
the flat pack generated file, the route works perfectly.  It's just that
when I add the encryption call, which is using something totally outside
camel (albeit in the same thread), the route breaks down.

So I need to know:

1) Should I split up the route into 3 routes: i.e. one route for flatpack
file generation, one route for encryption, and one route for sftp'ing?
2) Or should I try to fix the route as is?

Any help is appreciated

thanks

Sam

--
View this message in context: http://camel.465427.n5.nabble.com/GPG-encryption-in-camel-2-8-3-tp5448999p5448999.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: GPG encryption in camel 2.8.3

Posted by sammohamed <sm...@freelancersunion.org>.
Hi,

I was able to get it to work.  I'm not sure if this is best practice, but
here is what my route now looks like

FlatpackDataFormat df = new FlatpackDataFormat();
        df.setDefinition(new
ClassPathResource("META-INF/smooks/fuintegration/retirement-fixed-width-mapping.xml"));
        df.setFixed(true);
        df.setIgnoreFirstRecord(false);

        from(memberRepositoryEndPoint)
                .to("log:org.fuwt?level=INFO")
                .routeId("retirement_file_generation")
                .marshal(df)
                .convertBodyTo(String.class)
                .log("log:org.fuwt?level=ERROR&showAll=false")
                .to(localFileEndPoint);

from(localFileEndPoint)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                        Properties properties = new Properties();
                       
properties.load(this.getClass().getResourceAsStream("/default.fu-integration.properties"));

                        String inFilePath =
properties.getProperty("retirement.outgoing_file.dir").concat(fileName);
                        String outFilePath =
properties.getProperty("retirement.encrypted_outgoing_file.dir").concat(fileName);
                        String pubKeyPath =
properties.getProperty("retirement.miliman.pubkeypath");

                        Security.addProvider(new BouncyCastleProvider());

                        FUPGPUtils.encrypt(inFilePath, pubKeyPath,
outFilePath);
                    }
                });

from(encryptedFileEndPoint)
                .to("log:org.fuwt?level=INFO")
                .routeId("miliman_sftp_exchange")
                .to(sftpFileEndPoint);

Many thanks for your help

Sam

--
View this message in context: http://camel.465427.n5.nabble.com/GPG-encryption-in-camel-2-8-3-tp5448999p5451035.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: GPG encryption in camel 2.8.3

Posted by sammohamed <sm...@freelancersunion.org>.
Hi,

I'll try adding the encryption as a processor, with the from as the local
file and the end as a mock end point, then pickup the encrypted file and
sftp it.

Will report back here with results or more questions

thanks

Sam

--
View this message in context: http://camel.465427.n5.nabble.com/GPG-encryption-in-camel-2-8-3-tp5448999p5450981.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: GPG encryption in camel 2.8.3

Posted by "Willem.Jiang" <wi...@gmail.com>.
Hi,

I think you made a mistake of the route configure code and the processor
code.
The Java DSL which you used to define the route is just a configuration
code, it tell camel to build the route as you want, they are not the
processing code which camel uses in the runtime.

If you want to camel context call the encryption code of GPG, you can
consider to use Bean[1]or implement your customer Processor[2] to do the job
at runtime.

[1]http://camel.apache.org/bean.html
[2]http://camel.apache.org/processor.html

Willem

--
View this message in context: http://camel.465427.n5.nabble.com/GPG-encryption-in-camel-2-8-3-tp5448999p5449388.html
Sent from the Camel - Users mailing list archive at Nabble.com.