How to invoke rest services with camel-restlet

664 views Asked by At

I'm trying to invoke rest services from camel using restlest. I need to set some http headers and other application specific headers.

This is the way I'm doing it:

from("timer:50000?repeatCount=1").process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {

            Message out = exchange.getOut();

            Map<String, Object> headers = new HashMap<>();

            headers.put(Exchange.CONTENT_TYPE, "application/json");
            headers.put("token", "value");

            out.setHeaders(headers);
        }
    })
    .to("restlet:https://host:443/api/1/customer?restletMethod=get");

But the resulting http request does not apply the headers at all.

What's wrong with this?

1

There are 1 answers

0
Fabrizio Del Franco On

For those who may have the same problem, I've figured it out, finally. I don't use Restlet any longer, but camel-http4 instead.

from("timer:50000?repeatCount=1").process(new Processor() {     
        @Override
        public void process(Exchange arg0) throws Exception {
            arg0.getOut().setBody("{ \"login\": \"blabla\", \"secret\":\"blabla\"}");
        }
    })
    .setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
    .setHeader("CamelHttpMethod", constant("POST"))
        .to("https4://test:443/rest/")