You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by nehachauhan1029 <ne...@gmail.com> on 2015/03/06 21:37:42 UTC

Calling restful webservice from Camel

hi,

I am following example on 
(how to invoke rest service through camel cxfrs producer)
http://camel.apache.org/cxfrs.html  


My question is how do i call webservice
http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=RHT

from below sample


Exchange exchange = template.send("direct://proxy", new Processor() {
    public void process(Exchange exchange) throws Exception {
        exchange.setPattern(ExchangePattern.InOut);
        Message inMessage = exchange.getIn();
        setupDestinationURL(inMessage);
        // set the operation name 
        inMessage.setHeader(CxfConstants.OPERATION_NAME, "getCustomer");
        // using the proxy client API
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API,
Boolean.FALSE);
        // set a customer header
        inMessage.setHeader("key", "value");
        // set the parameters , if you just have one parameter 
        // camel will put this object into an Object[] itself
        inMessage.setBody("123");
    }
});
      
// get the response message 
Customer response = (Customer) exchange.getOut().getBody();

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Calling-restful-webservice-from-Camel-tp5763765.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Servlet and REST component integration is not complete

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,

On 21/09/15 14:50, Claus Ibsen wrote:
> btw are the other questions about REST I may have missed?

All is clear so far, thanks, though I will likely have more questions.
FYI, +1 to your comments about not doing all the work in the rest 
endpoint, I was really referring to a camel-servlet endpoint/consumer - 
similarly in case of CXF, it would be the responsibility of CXF itself 
or CXFRS to do some enforcements - exactly as you suggested.

> Its great to hear that works on supporting it from CXF is in the works.
>
I'm still experimenting with how this can be completed :-), but I think 
I have the main flows working with CXF, though indeed some more 
experiments needs to be done

Thanks, Sergey


> On Mon, Sep 21, 2015 at 3:43 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> Hi
>>
>> Yes there is no rest content negoation and whatnot in camel-core. That
>> said if we find in the future a need for this we can surely add
>> something. But the goal of the rest-dsl was to be that syntax sugar so
>> ppl could do "route like" rest services, and then leave the bulk work
>> to the existing rest capable Camel components.
>>
>> If we start adding rest logic in camel-core (or optional a camel-rest
>> add-on module) then we may reinvent the wheel, or step on the toes of
>> some of these components. But then on the other side if we have that
>> logic then its consistent.
>>
>> The rest-dsl do have the json/xml binding included as those are the
>> most common types to work with and they are generic and jackson and
>> jaxb can work with those. And then more plain http components can do
>> rest like services.
>>
>>
>>
>>
>> On Mon, Sep 21, 2015 at 3:28 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>>> Hi Claus - thanks for getting back to this thread. That what I meant, that
>>> after the camel-servlet based RESt-DSL consumer is up it does not enforce
>>> Accept vs Produces intersection.
>>>
>>> Cheers, Sergey
>>>
>>> On 21/09/15 12:02, Claus Ibsen wrote:
>>>>
>>>> The rest-dsl is syntax sugar, and passes on the request to the actual
>>>> transport, which then does what it care to do.
>>>>
>>>>
>>>> On Tue, Aug 25, 2015 at 7:10 PM, Sergey Beryozkin <sb...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>> Experimenting a bit with a camel-example-servlet-rest-tomcat,
>>>>> ServletComponent creates a Consumer for RESTComponent, and unless I'm
>>>>> missing something, it ignores the consumes and produces initialization
>>>>> properties - so
>>>>>
>>>>> curl -X GET -H "Accept: application/bar"
>>>>> http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123
>>>>>
>>>>> still returns JSON instead of HTTP error...
>>>>> Don't mind creating a patch but perhaps someone who is more did this
>>>>> integration can fix it given that I'm only starting looking at how REST
>>>>> component is supported...
>>>>>
>>>>> Cheers, Sergey
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2nd edition:
>> https://www.manning.com/books/camel-in-action-second-edition
>
>
>


-- 
Sergey Beryozkin

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

Re: Servlet and REST component integration is not complete

Posted by Claus Ibsen <cl...@gmail.com>.
btw are the other questions about REST I may have missed?

Its great to hear that works on supporting it from CXF is in the works.

On Mon, Sep 21, 2015 at 3:43 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> Yes there is no rest content negoation and whatnot in camel-core. That
> said if we find in the future a need for this we can surely add
> something. But the goal of the rest-dsl was to be that syntax sugar so
> ppl could do "route like" rest services, and then leave the bulk work
> to the existing rest capable Camel components.
>
> If we start adding rest logic in camel-core (or optional a camel-rest
> add-on module) then we may reinvent the wheel, or step on the toes of
> some of these components. But then on the other side if we have that
> logic then its consistent.
>
> The rest-dsl do have the json/xml binding included as those are the
> most common types to work with and they are generic and jackson and
> jaxb can work with those. And then more plain http components can do
> rest like services.
>
>
>
>
> On Mon, Sep 21, 2015 at 3:28 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>> Hi Claus - thanks for getting back to this thread. That what I meant, that
>> after the camel-servlet based RESt-DSL consumer is up it does not enforce
>> Accept vs Produces intersection.
>>
>> Cheers, Sergey
>>
>> On 21/09/15 12:02, Claus Ibsen wrote:
>>>
>>> The rest-dsl is syntax sugar, and passes on the request to the actual
>>> transport, which then does what it care to do.
>>>
>>>
>>> On Tue, Aug 25, 2015 at 7:10 PM, Sergey Beryozkin <sb...@gmail.com>
>>> wrote:
>>>>
>>>> Hi,
>>>> Experimenting a bit with a camel-example-servlet-rest-tomcat,
>>>> ServletComponent creates a Consumer for RESTComponent, and unless I'm
>>>> missing something, it ignores the consumes and produces initialization
>>>> properties - so
>>>>
>>>> curl -X GET -H "Accept: application/bar"
>>>> http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123
>>>>
>>>> still returns JSON instead of HTTP error...
>>>> Don't mind creating a patch but perhaps someone who is more did this
>>>> integration can fix it given that I'm only starting looking at how REST
>>>> component is supported...
>>>>
>>>> Cheers, Sergey
>>>
>>>
>>>
>>>
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2nd edition:
> https://www.manning.com/books/camel-in-action-second-edition



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Re: Servlet and REST component integration is not complete

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

Yes there is no rest content negoation and whatnot in camel-core. That
said if we find in the future a need for this we can surely add
something. But the goal of the rest-dsl was to be that syntax sugar so
ppl could do "route like" rest services, and then leave the bulk work
to the existing rest capable Camel components.

If we start adding rest logic in camel-core (or optional a camel-rest
add-on module) then we may reinvent the wheel, or step on the toes of
some of these components. But then on the other side if we have that
logic then its consistent.

The rest-dsl do have the json/xml binding included as those are the
most common types to work with and they are generic and jackson and
jaxb can work with those. And then more plain http components can do
rest like services.




On Mon, Sep 21, 2015 at 3:28 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi Claus - thanks for getting back to this thread. That what I meant, that
> after the camel-servlet based RESt-DSL consumer is up it does not enforce
> Accept vs Produces intersection.
>
> Cheers, Sergey
>
> On 21/09/15 12:02, Claus Ibsen wrote:
>>
>> The rest-dsl is syntax sugar, and passes on the request to the actual
>> transport, which then does what it care to do.
>>
>>
>> On Tue, Aug 25, 2015 at 7:10 PM, Sergey Beryozkin <sb...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>> Experimenting a bit with a camel-example-servlet-rest-tomcat,
>>> ServletComponent creates a Consumer for RESTComponent, and unless I'm
>>> missing something, it ignores the consumes and produces initialization
>>> properties - so
>>>
>>> curl -X GET -H "Accept: application/bar"
>>> http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123
>>>
>>> still returns JSON instead of HTTP error...
>>> Don't mind creating a patch but perhaps someone who is more did this
>>> integration can fix it given that I'm only starting looking at how REST
>>> component is supported...
>>>
>>> Cheers, Sergey
>>
>>
>>
>>
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Re: Servlet and REST component integration is not complete

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Claus - thanks for getting back to this thread. That what I meant, 
that after the camel-servlet based RESt-DSL consumer is up it does not 
enforce Accept vs Produces intersection.

Cheers, Sergey
On 21/09/15 12:02, Claus Ibsen wrote:
> The rest-dsl is syntax sugar, and passes on the request to the actual
> transport, which then does what it care to do.
>
>
> On Tue, Aug 25, 2015 at 7:10 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
>> Hi,
>> Experimenting a bit with a camel-example-servlet-rest-tomcat,
>> ServletComponent creates a Consumer for RESTComponent, and unless I'm
>> missing something, it ignores the consumes and produces initialization
>> properties - so
>>
>> curl -X GET -H "Accept: application/bar"
>> http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123
>>
>> still returns JSON instead of HTTP error...
>> Don't mind creating a patch but perhaps someone who is more did this
>> integration can fix it given that I'm only starting looking at how REST
>> component is supported...
>>
>> Cheers, Sergey
>
>
>


Re: Servlet and REST component integration is not complete

Posted by Claus Ibsen <cl...@gmail.com>.
The rest-dsl is syntax sugar, and passes on the request to the actual
transport, which then does what it care to do.


On Tue, Aug 25, 2015 at 7:10 PM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi,
> Experimenting a bit with a camel-example-servlet-rest-tomcat,
> ServletComponent creates a Consumer for RESTComponent, and unless I'm
> missing something, it ignores the consumes and produces initialization
> properties - so
>
> curl -X GET -H "Accept: application/bar"
> http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123
>
> still returns JSON instead of HTTP error...
> Don't mind creating a patch but perhaps someone who is more did this
> integration can fix it given that I'm only starting looking at how REST
> component is supported...
>
> Cheers, Sergey



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Servlet and REST component integration is not complete

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi,
Experimenting a bit with a camel-example-servlet-rest-tomcat, 
ServletComponent creates a Consumer for RESTComponent, and unless I'm 
missing something, it ignores the consumes and produces initialization 
properties - so

curl -X GET -H "Accept: application/bar" 
http://localhost:8080/camel-example-servlet-rest-tomcat/rest/user/123

still returns JSON instead of HTTP error...
Don't mind creating a patch but perhaps someone who is more did this 
integration can fix it given that I'm only starting looking at how REST 
component is supported...

Cheers, Sergey