简体   繁体   中英

Apache Camel: How to get parameters sent to a Camel Servlet using a HTTP POST request by a smart way?

I'm writing a route that may receive a TXT file with some parameters using a Camel Servlet Component. According to the Camel documentation I'm supposed to have the parameter set in the header of the message. But in the the case of a HTTP POST it seems that the header is not populated as expected.
I found that the body contains all the request, the file and the parameters.

Here is an example of content :

------WebKitFormBoundaryC9GDMXt2OAHARCZj
Content-Disposition: form-data; name="upfile"; filename="user.txt"
Content-Type: text/plain
hello world...
...
------WebKitFormBoundaryC9GDMXt2OAHARCZj 
Content-Disposition: form-data; name="userdata" testtest 
------WebKitFormBoundaryC9GDMXt2OAHARCZj 
Content-Disposition: form-data; name="id" 12344 
------WebKitFormBoundaryC9GDMXt2OAHARCZj--

Does someone know a way to get the parameters by a smart way?
Do I have to make my own parser in my processor?

ericg,

If you use HTTP POST, the parameters are indeed set in the message body. Maybe you should implements a processor in your route to get the parameters from the body and set them in the exchange headers if it's what you need

Best regards,

In the camel we can get HTTP post parameters, I am not sure to get the Content-Disposition. if we want to get Content-Disposition, we can write own processor method. But sure can get the parameters, your mentioned body content is your uploaded files content.

from(HTTP_INBOUND_URL)
        .log("The message : ${in.body}")
        .doTry()
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        // TODO Auto-generated method stub

                        String templateId = exchange.getIn().getHeader("templateId",
                                String.class);
}
})

Where templateId is your HTTP post parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM