Quantcast

RestFul service using camel

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RestFul service using camel

Richa
Hi,
I want to invoke a rest service using apache camel. Currently i am using the cxfrs component to configure my endpoint. My route looks like below:

from("cxfrs://http://localhost:8080/RestServiceApp/?resourceClasses="com.sample.Server.HelloWorld").log("Route Started");

My problem is that i want to invoke a method present in the server class (HelloWorld in my case). Can you please tell me how do i call a particular method?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Claus Ibsen-2
On Thu, Jan 31, 2013 at 7:04 PM, Richa <[hidden email]> wrote:

> Hi,
> I want to invoke a rest service using apache camel. Currently i am using the
> cxfrs component to configure my endpoint. My route looks like below:
>
> from("cxfrs://http://localhost:8080/RestServiceApp/?resourceClasses="com.sample.Server.HelloWorld").log("Route
> Started");
>
> My problem is that i want to invoke a method present in the server class
> (HelloWorld in my case). Can you please tell me how do i call a particular
> method?
>

When you use from, then you let Camel expose a REST service. You want
the opposite, to call a REST service on a remote server.
So for that you need to use .to instead.

So you need to consider when to invoke this REST service, what
triggers that call?

You can use a timer to call it at every X period

from timer
  to cxfrs

Or you can also just invoke it from java code using a ProducerTemplate
http://camel.apache.org/producertemplate.html



>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Richa
Thank you Claus. I get your point. I want to invoke a rest service hosted in a remote server and hence should be putting the rest url in as a to endpoint.

But i am unable to get through the format of the url to be passed as a TO endpoint. Firstly i am using cxfrs component to invoke the rest service

How do i tell camel as to which function of the rest service should we invoke. My current webservice uri is
cxfrs://http://localhost:8080/CounterWebApp/?resourceClasses="+Hello.class.getName()

How do i mention the method name of the rest service ?

Appreciate your help.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

whisky
It is your REST container responsibility to make the routing from an URI to
a server class/method invocation.

The camel part of the construct focus only on this URI.

You could use a routing strategy that map by name some URI parts to invoke
a named method, but it still code that run on the server side.


On Friday, February 1, 2013, Richa wrote:

> Thank you Claus. I get your point. I want to invoke a rest service hosted
> in
> a remote server and hence should be putting the rest url in as a to
> endpoint.
>
> But i am unable to get through the format of the url to be passed as a TO
> endpoint. Firstly i am using cxfrs component to invoke the rest service
>
> How do i tell camel as to which function of the rest service should we
> invoke. My current webservice uri is
> cxfrs://http://localhost:8080/CounterWebApp/?resourceClasses=
> "+Hello.class.getName()
>
> How do i mention the method name of the rest service ?
>
> Appreciate your help.
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5726721.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Sergey Beryozkin-3
Hi
On 01/02/13 15:54, Vincent Nonnenmacher wrote:
> It is your REST container responsibility to make the routing from an URI to
> a server class/method invocation.
>
> The camel part of the construct focus only on this URI.
>
> You could use a routing strategy that map by name some URI parts to invoke
> a named method, but it still code that run on the server side.
>
I think it is possible with CXF RS producer to introspect a given class
and its method (with CXF proxy-based client runtime), and construct HTTP
query, though I haven't used this option.
Willem, can you give me a favor and clarify if possible ?

Thanks, Sergey

>
> On Friday, February 1, 2013, Richa wrote:
>
>> Thank you Claus. I get your point. I want to invoke a rest service hosted
>> in
>> a remote server and hence should be putting the rest url in as a to
>> endpoint.
>>
>> But i am unable to get through the format of the url to be passed as a TO
>> endpoint. Firstly i am using cxfrs component to invoke the rest service
>>
>> How do i tell camel as to which function of the rest service should we
>> invoke. My current webservice uri is
>> cxfrs://http://localhost:8080/CounterWebApp/?resourceClasses=
>> "+Hello.class.getName()
>>
>> How do i mention the method name of the rest service ?
>>
>> Appreciate your help.
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5726721.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

whisky
I don't known about cxf I admit, I was reasoning more along with the
Camel-Restlet component, and REST concepts in general.

So you're perhaps right for the Rest server part of CXF RS, that allow this
direct invocation by matching class/method by name in the URI as a Routing
method




On Fri, Feb 1, 2013 at 4:58 PM, Sergey Beryozkin <[hidden email]>wrote:

> Hi
>
> On 01/02/13 15:54, Vincent Nonnenmacher wrote:
>
>> It is your REST container responsibility to make the routing from an URI
>> to
>> a server class/method invocation.
>>
>> The camel part of the construct focus only on this URI.
>>
>> You could use a routing strategy that map by name some URI parts to invoke
>> a named method, but it still code that run on the server side.
>>
>>  I think it is possible with CXF RS producer to introspect a given class
> and its method (with CXF proxy-based client runtime), and construct HTTP
> query, though I haven't used this option.
> Willem, can you give me a favor and clarify if possible ?
>
> Thanks, Sergey
>
>
>
>> On Friday, February 1, 2013, Richa wrote:
>>
>>  Thank you Claus. I get your point. I want to invoke a rest service hosted
>>> in
>>> a remote server and hence should be putting the rest url in as a to
>>> endpoint.
>>>
>>> But i am unable to get through the format of the url to be passed as a TO
>>> endpoint. Firstly i am using cxfrs component to invoke the rest service
>>>
>>> How do i tell camel as to which function of the rest service should we
>>> invoke. My current webservice uri is
>>> cxfrs://http://localhost:8080/**CounterWebApp/?**resourceClasses=<http://localhost:8080/CounterWebApp/?resourceClasses=>
>>> "+Hello.class.getName()
>>>
>>> How do i mention the method name of the rest service ?
>>>
>>> Appreciate your help.
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.**com/RestFul-service-using-**
>>> camel-tp5726656p5726721.html<http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5726721.html>
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Richa
Thank you for your reply. But can you please help me with a sample code. I am trying to invoke my rest service using the cxfrs. I am putting the method name in the exchange header, but still I am not able to invoke the message and get the response.  Kindly provide a sample code for my reference.
Thank you
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Christian Mueller
Something like this:
https://github.com/muellerc/camel-in-daily-use/blob/master/part-2/src/main/java/org/apache/cmueller/camel/sus/cidu/part1/PrepareRestRequest.java

Best,
Christian

On Tue, Feb 5, 2013 at 5:56 AM, Richa <[hidden email]> wrote:

> Thank you for your reply. But can you please help me with a sample code. I
> am
> trying to invoke my rest service using the cxfrs. I am putting the method
> name in the exchange header, but still I am not able to invoke the message
> and get the response.  Kindly provide a sample code for my reference.
> Thank you
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5726939.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Richa
Thank you for your reply Christian. It helped
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

SyedBhai
In reply to this post by Christian Mueller
THi Guys,
  My name is Syed.
  I have developed one JAX-RS webservice.
  In this webservice, the class is com.syed.WelcomeService (Its path is "/class1").  This class has a POST method.
  @Path("/post")
  @POST
  public String sayHello(String xyz) {...}

  I have deployed this webservice successfully in tomcat server.  I even invoked the service using jersey client API.

  Now I want to invoke this webservice using camel framework in my client program.
  I am really having hard time how to invoke this service through camel.
  Can you please help me?
  I don't want the entire program.
  I just need the camel configuration to interact with the webservice.
  Please.

Thanks,
Syed.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Sergey Beryozkin-3
Hi

Have a look at this thread:

http://camel.465427.n5.nabble.com/Routing-from-servlet-to-CXF-JAXRS-via-direct-td5733746.html#a5733749

that option is about using (CXF) JAX-RS server endpoint and getting
Camel Servlet transport linked to it.

Also consider experimenting with CXFRS simple binding; perhaps a restlet
component cam help too

Sergey

On 19/06/13 18:14, SyedBhai wrote:

> THi Guys,
>    My name is Syed.
>    I have developed one JAX-RS webservice.
>    In this webservice, the class is com.syed.WelcomeService (Its path is
> "/class1").  This class has a POST method.
>    @Path("/post")
>    @POST
>    public String sayHello(String xyz) {...}
>
>    I have deployed this webservice successfully in tomcat server.  I even
> invoked the service using jersey client API.
>
>    Now I want to invoke this webservice using camel framework in my client
> program.
>    I am really having hard time how to invoke this service through camel.
>    Can you please help me?
>    I don't want the entire program.
>    I just need the camel configuration to interact with the webservice.
>    Please.
>
> Thanks,
> Syed.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5734395.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

SyedBhai
In reply to this post by SyedBhai
Hi Everyone.
  Atlast I have figured out how to invoke a RESTFUL webservice using Camel Framework.
  It is very easy.  No need of any CXF/CXFRS/RESTLET components.
  Just HTTP component of Camel is enough.
 
Thanks,
Syed.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

Sergey Beryozkin-3
On 21/06/13 08:31, SyedBhai wrote:
> Hi Everyone.
>    Atlast I have figured out how to invoke a RESTFUL webservice using Camel
> Framework.
>    It is very easy.  No need of any CXF/CXFRS/RESTLET components.
>    Just HTTP component of Camel is enough.
Sure that works too. Your original question had a JAX-RS code snippet
hence my suggestion to use JAX-RS aware components

Cheers, Sergey

>
> Thanks,
> Syed.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/RestFul-service-using-camel-tp5726656p5734509.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: RestFul service using camel

vjboston
Hi All,

I am trying to achieve the same thing.Invoking a remote restful service.But the response of the service is Null.

SO the body keeps comign as null.
Can somebody please help me with sample code ?
Loading...