java - How do I set the Content-Type on a camel-restlet producer request? -


i need consume simple rest service, implementation breaks if request goes out content-type: application/x-www-form-urlencoded. need set "application/json"or faced status 415.

i using restlet producer component because used throughout , far had hit sweet spot between functionality , simplicity. far.

anyway, trying set header in route seems have 0 effect , content-type of request remains application/x-www-form-urlencoded. here test code:

    from("direct:getimg")             .setheader(restletconstants.restlet_login, simple("admin"))             .setheader(restletconstants.restlet_password, simple("admin"))             .setheader(exchange.content_type, simple("application/json"))             .to("restlet:http://requestb.in/12sowlx1?restletmethod=get&throwexceptiononfailure=false") 

i missing something, cant find example. can point right way it?

thanks!

you should call processor before call restlet , set content type in exchange. this:

from("direct:getimg").process(new processor() {         @override         public void process(exchange exchange) throws exception {             exchange.getin().setheader(exchange.content_type, mediatype.application_xml);         }     }).to("restlet:http://requestb.in/12sowlx1?restletmethod=get&throwexceptiononfailure=false"); 

i have tested , works. let me know result.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -