You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "kraythe ." <kr...@gmail.com> on 2014/06/04 16:55:20 UTC

Re: How could I post a Map to my restful api by camel?

All params passed in a HTTP Query string are converted to headers in the
exchange. And of course the actual URL the user used would be available in
a header as well. So you don't even need to go to the extent you have here.
Most of the time you are actually trying to remove headers or transform
them so you don't confuse a remote service. Your code should be:

from("servlet:/myApiCall")
  .setHeader("app param x", constant("myconstant"))
  .setHeader(Exchange.HTTP_PATH, simple(/* expression to build path from
headers*/)
  .setHeader(Exchange.HTTP_QUERY, simple(/* expression to build new query
from headers */)
  .to("http4://www.myapp.com/ ....");

In this manner all can be done in the DSL.



*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*


On Thu, May 29, 2014 at 1:13 AM, sleeper <lu...@126.com> wrote:

> I have a web app,which provides some restful api,some of them have been
> marked as @POST.
>
> In my camel router,I wanna post a Map params to the restful api,how could I
> do it?
>
> Exchange res = template.request("direct:///start", new Processor() {
>         public void process(Exchange exchange) throws Exception {
>                 exchange.getIn().setHeader("to", targetApp);//targetApp is
> my restful api
> uri
>                 exchange.getOut().setBody(params);//params is a
> java.util.Map type
>         }
> });
>
> here is the problem
> 1)when I set the map type into the body,My rest can not get the request.
> 2)when I turn the map into a String type,My rest get the request,but where
> is my params data gone??
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-could-I-post-a-Map-to-my-restful-api-by-camel-tp5751684.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>