You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "LaSalle, Craig" <Cr...@intuit.com> on 2010/07/29 03:12:07 UTC

Setting url {params} in REST call with Camel

Hi -

 

I'm using the "restlet" component to make a call to an external REST
api.

 

The route endpoint looks like:

 

to("restlet:http://localhost:8080/pscore/datajobs/{jobid}/patientaccount
?restletMethod=post").

 

To substitute the "jobid" at runtime, I've set the "jobid" in the
message header like:

 

exchange.getOut().setHeader("jobid", "1234");

exchange.getOut().setHeader("Content-Type", "application/xml");

exchange.getOut().setBody("<test>foo</test>");

 

In the external REST service, the "{jobid}" portion of the URL is not
getting set to the jobid value of "1234".

 

I haven't been able to find a clear example of how to substitute the url
parameters of a REST call with values at runtime. Has anyone else had
this problem, and worked through it?

 

Thanks,

-Craig LaSalle

 


Re: Setting url {params} in REST call with Camel

Posted by Christian Müller <ch...@gmail.com>.
Maybe my example will help you [1]...[4]...

Or try
<camel:route>
  <camel:from uri="file://[directory path]" />
  <camel:setHeader headerName="id">
    <camel:xpath>/order/item/id</camel:xpath>
  </camel:setHeader>
  <camel:setHeader headerName="CamelHttpPath">
    <camel:simple>/rest/${header[id]}/WebService</camel:simple>
  </camel:setHeader>
  <camel:to uri="http://localhost:9002/REST-Webservice" />
</camel:route>


[1]
https://github.com/muellerc/camel-in-daily-use/blob/master/part-2/src/test/java/org/apache/cmueller/camel/sus/cidu/part1/CustomerServiceResource.java
[2]
https://github.com/muellerc/camel-in-daily-use/blob/master/part-2/src/main/java/org/apache/cmueller/camel/sus/cidu/part1/PrepareRestRequest.java
[3]
https://github.com/muellerc/camel-in-daily-use/blob/master/part-2/src/main/java/org/apache/cmueller/camel/sus/cidu/part1/Route3.java
[4]
https://github.com/muellerc/camel-in-daily-use/blob/master/part-2/src/test/resources/part-1.cfg

Best,
Christian

On Mon, Aug 6, 2012 at 9:39 PM, Deepthi <de...@gmail.com> wrote:

> I am getting Route exception if i give the route in following manner:
>
> <camel:route>
>                         <camel:from
>                                 uri="file://[directory path]" />
>                         <camel:setHeader headerName="header1">
>
> <camel:xpath>/order/item/id</camel:xpath>
>                                 </camel:setHeader>
>                         <camel:to
>
> uri="http://localhost:9002/REST-Webservice/rest/{header1}/WebService" />
>                 </camel:route>
>
> Where am i going wrong? I see the test case executed in the same manner.
>
> Thanks,
> Deepthi
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Setting-url-params-in-REST-call-with-Camel-tp2257861p5716890.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: Setting url {params} in REST call with Camel

Posted by Deepthi <de...@gmail.com>.
I am getting Route exception if i give the route in following manner:

<camel:route>
                        <camel:from
                                uri="file://[directory path]" />
                        <camel:setHeader headerName="header1">
                                       
<camel:xpath>/order/item/id</camel:xpath>
                                </camel:setHeader>
                        <camel:to
                               
uri="http://localhost:9002/REST-Webservice/rest/{header1}/WebService" />
                </camel:route>

Where am i going wrong? I see the test case executed in the same manner.

Thanks,
Deepthi



--
View this message in context: http://camel.465427.n5.nabble.com/Setting-url-params-in-REST-call-with-Camel-tp2257861p5716890.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting url {params} in REST call with Camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have created a ticket to track this
https://issues.apache.org/activemq/browse/CAMEL-3021

On Tue, Aug 3, 2010 at 3:22 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Can you try with restletMethod=get
> Could be that the post method doesn't parse the uri for { } placeholders.
>
>
>
> On Thu, Jul 29, 2010 at 3:12 AM, LaSalle, Craig
> <Cr...@intuit.com> wrote:
>> Hi -
>>
>>
>>
>> I'm using the "restlet" component to make a call to an external REST
>> api.
>>
>>
>>
>> The route endpoint looks like:
>>
>>
>>
>> to("restlet:http://localhost:8080/pscore/datajobs/{jobid}/patientaccount
>> ?restletMethod=post").
>>
>>
>>
>> To substitute the "jobid" at runtime, I've set the "jobid" in the
>> message header like:
>>
>>
>>
>> exchange.getOut().setHeader("jobid", "1234");
>>
>> exchange.getOut().setHeader("Content-Type", "application/xml");
>>
>> exchange.getOut().setBody("<test>foo</test>");
>>
>>
>>
>> In the external REST service, the "{jobid}" portion of the URL is not
>> getting set to the jobid value of "1234".
>>
>>
>>
>> I haven't been able to find a clear example of how to substitute the url
>> parameters of a REST call with values at runtime. Has anyone else had
>> this problem, and worked through it?
>>
>>
>>
>> Thanks,
>>
>> -Craig LaSalle
>>
>>
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Setting url {params} in REST call with Camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Can you try with restletMethod=get
Could be that the post method doesn't parse the uri for { } placeholders.



On Thu, Jul 29, 2010 at 3:12 AM, LaSalle, Craig
<Cr...@intuit.com> wrote:
> Hi -
>
>
>
> I'm using the "restlet" component to make a call to an external REST
> api.
>
>
>
> The route endpoint looks like:
>
>
>
> to("restlet:http://localhost:8080/pscore/datajobs/{jobid}/patientaccount
> ?restletMethod=post").
>
>
>
> To substitute the "jobid" at runtime, I've set the "jobid" in the
> message header like:
>
>
>
> exchange.getOut().setHeader("jobid", "1234");
>
> exchange.getOut().setHeader("Content-Type", "application/xml");
>
> exchange.getOut().setBody("<test>foo</test>");
>
>
>
> In the external REST service, the "{jobid}" portion of the URL is not
> getting set to the jobid value of "1234".
>
>
>
> I haven't been able to find a clear example of how to substitute the url
> parameters of a REST call with values at runtime. Has anyone else had
> this problem, and worked through it?
>
>
>
> Thanks,
>
> -Craig LaSalle
>
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus