Accesing json data sent through a post request in Apache Camel

118 Views Asked by At

I am new to Apache Camel. I want to access the data sent through a post request in order to download a file from S3. This is the router that I wrote.

public static class HelloRoute extends RouteBuilder {
       
        @Override
        public void configure() {
            rest("/")
                .post("file-from-s3")
                    .route()
                    .setHeader(AWS2S3Constants.KEY, constant("filename"))
                    .to("aws2-s3://bucketnameaccessKey=INSERT&secretKey=INSERT&region=INSERT&operation=getObject")
                    .to("file:/tmp/")
                    .endRest();
        }

The corresponding json data that will be sent ->

{
     "filename" : "test.txt",
     "bucketname": "testbucket",
     "accessKey" : "key",
     "secretKey" : "key2",
     "region"    : "region"

}

How to do I access these json values in the code above?

1

There are 1 best solutions below

0
burki On

You need to unmarshal the JSON request data first. You can choose from a variety of libs and ways to do this, check out the Camel docs for JSON.

Then the message body contains the structure you unmarshalled your data to (POJO, Map). So you can access it on various ways by using Simple directly in the Route or a Bean method that is called from the route etc.