You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Robert Thullner <rt...@gmx.at> on 2007/12/27 15:45:18 UTC

Call Web Services from Camel

Hi
 
Is it possible to invoke Web Services within my CamelContext? Especially I
want to invoke a REST service and a service implemented in CXF or Axis.
 
My scenario is the following: When a jms message is received on a queue, the
REST service and the Axis service shall be invoked and the results of the
two services shall be passed back on some other queue? 
Can this be done by using the Camel HTTP component or is it advisable to
just implement the Webservice calling in some Java class? 
For me it would be a nice architecture if I could do the web service calling
in my camel context, so I could get it out of my Java classes. So my
question is if that can be done when using Camel?
 
Thanks for any suggestions
Robert

Re: AW: Call Web Services from Camel

Posted by James Strachan <ja...@gmail.com>.
On 28/12/2007, Robert Thullner <rt...@gmx.at> wrote:
> Thanks for your reply.
>
> I still have one more question. How do I get the result of the webservice
> call into some variable, so that I can pass it to the resultqueue? Does this
> happen implicitly?

By default the output of each request is sent to the next request in
the pipeline.

Using Hadrian's example...

from(...)
.to(webservice 1)
.to(webservice 2)
.to(resultQueue);

The output from webservice1 is sent to webservice2; that output is
sent to the resultQueue etc.

If you want to capture different results in variables, your best bet
is to write custom Processors or beans to perform custom invocations
and logic.
http://activemq.apache.org/camel/bean-integration.html

Currently each invocation of a service uses its own Exchange; we could
consider adding the ability to look up (say in a transformer after the
call to webservice 2), the exchange for webservice1 or webservice2 to
be able to refer to previous results.

Each flow (a from() then multiple to()) uses a single UnitOfWork which
we could consider expanding to be able to access related Exchanges?

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

AW: AW: Call Web Services from Camel

Posted by Robert Thullner <rt...@gmx.at>.
Thanks for your reply. 

I still have one more question. How do I get the result of the webservice
call into some variable, so that I can pass it to the resultqueue? Does this
happen implicitly?

Thanks
Robert 

-----Ursprüngliche Nachricht-----
Von: Hadrian Zbarcea [mailto:hzbarcea@gmail.com] 
Gesendet: Donnerstag, 27. Dezember 2007 22:09
An: camel-user@activemq.apache.org
Betreff: Re: AW: Call Web Services from Camel

Hi Robert,

 From what you describe, it looks like you just need to call your web
services normally

from(...)
.to(webservice 1)
.to(webservice 2)
.to(resultQueue);

You must have the cxf component and your urls have to point to cxf web
services.  Taking a look at camel-example-cxf may help.

Hadrian

Robert Thullner wrote:
> Thanks for the reply.
>
> I looked at both components, but I still have some understanding problems.
> My problem is that I do not know how to trigger the webservice call 
> from camel.
> Usually I have a rule:
>
> from(...)
> .to(...);
>
> So I wait for an event and write the event to somewhere else.
>
> My scenario is something like that.
> from(...)
> .call(webservice 1)
> .call(webservice 2)
> .to(resultQueue);
>
> Do you have any tutorials for calling a service within a route? Or 
> should it be implemented somehow else?
>
>
>
> I also tried to get request from a REST webservice and write it the 
> result to a queue, as the service is called from the browser window. I 
> used the jetty component for this, as the HttpComponent cannot be used 
> as input component.
>
> My route looks like this:
> from("jetty:http:localhost:8080/restapp-1.0.0/helloworld")
> .to("activemq:queue:rest.queue");
>
> But when I start the CamelContext I always get an exception (see 
> below). I have put the camel-http, camel-jetty, jetty, jetty-util and 
> jetty-xbean jars on my classpath, but there are still some classes 
> missing. But I could not find any jar file that includes the 
> HttpClient class. What other jar files do I need to get the JettyComponent
working?
>
>
> The exception is:
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/mortbay/jetty/client/HttpClient
> at
> org.apache.camel.component.jetty.JettyHttpComponent.createHttpClient(J
> ettyHt
> tpComponent.java:193)
> at
> org.apache.camel.component.jetty.JettyHttpComponent.doStart(JettyHttpC
> ompone
> nt.java:187)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
> at 
> org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:42
> ) at 
> org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:5
> 3)
> at
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelCon
> text.j
> ava:149)
> at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelCont
> ext.ja
> va:256)
> at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelCon
> textHe
> lper.java:48)
> at org.apache.camel.model.RouteType.resolveEndpoint(RouteType.java:89)
> at 
> org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:8
> 1) at 
> org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:9
> 0) at 
> org.apache.camel.model.FromType.resolveEndpoint(FromType.java:66)
> at 
> org.apache.camel.impl.RouteContext.getEndpoint(RouteContext.java:59)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:179)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:80)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:71)
> at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(Defaul
> tCamel
> Context.java:449)
> at
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.
> java:4
> 41)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
> at eip.status.camel.routes.MessageBroker.main(MessageBroker.java:93)
>  
>
> Thanks for help
> Robert
>
> -----Ursprüngliche Nachricht-----
> Von: Guillaume Nodet [mailto:gnodet@gmail.com]
> Gesendet: Donnerstag, 27. Dezember 2007 17:04
> An: camel-user@activemq.apache.org
> Betreff: Re: Call Web Services from Camel
>
> There is a CXF based component that you should be able to use it 
> provided that you configure it correctly for REST.  Else, if you have 
> problems to do that using the HTTP component, let us know, as it 
> should be able to work too.
>
> On Dec 27, 2007 3:45 PM, Robert Thullner <rt...@gmx.at> wrote:
>
>   
>> Hi
>>
>> Is it possible to invoke Web Services within my CamelContext? 
>> Especially I want to invoke a REST service and a service implemented 
>> in
>>     
> CXF or Axis.
>   
>> My scenario is the following: When a jms message is received on a 
>> queue, the REST service and the Axis service shall be invoked and the 
>> results of the two services shall be passed back on some other queue?
>> Can this be done by using the Camel HTTP component or is it advisable 
>> to just implement the Webservice calling in some Java class?
>> For me it would be a nice architecture if I could do the web service 
>> calling in my camel context, so I could get it out of my Java classes.
>> So my question is if that can be done when using Camel?
>>
>> Thanks for any suggestions
>> Robert
>>
>>     
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>
>
>   


Re: AW: Call Web Services from Camel

Posted by Hadrian Zbarcea <hz...@gmail.com>.
Hi Robert,

 From what you describe, it looks like you just need to call your web 
services normally

from(...)
.to(webservice 1)
.to(webservice 2)
.to(resultQueue);

You must have the cxf component and your urls have to point to cxf web 
services.  Taking a look at camel-example-cxf may help.

Hadrian

Robert Thullner wrote:
> Thanks for the reply.
>
> I looked at both components, but I still have some understanding problems.
> My problem is that I do not know how to trigger the webservice call from
> camel.
> Usually I have a rule:
>
> from(...)
> .to(...); 
>
> So I wait for an event and write the event to somewhere else.
>
> My scenario is something like that.
> from(...)
> .call(webservice 1)
> .call(webservice 2)
> .to(resultQueue);
>
> Do you have any tutorials for calling a service within a route? Or should it
> be implemented somehow else?
>
>
>
> I also tried to get request from a REST webservice and write it the result
> to a queue, as the service is called from the browser window. I used the
> jetty component for this, as the HttpComponent cannot be used as input
> component.
>
> My route looks like this:
> from("jetty:http:localhost:8080/restapp-1.0.0/helloworld")
> .to("activemq:queue:rest.queue");
>
> But when I start the CamelContext I always get an exception (see below). I
> have put the camel-http, camel-jetty, jetty, jetty-util and jetty-xbean jars
> on my classpath, but there are still some classes missing. But I could not
> find any jar file that includes the HttpClient class. What other jar files
> do I need to get the JettyComponent working?
>
>
> The exception is:
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/mortbay/jetty/client/HttpClient
> at
> org.apache.camel.component.jetty.JettyHttpComponent.createHttpClient(JettyHt
> tpComponent.java:193)
> at
> org.apache.camel.component.jetty.JettyHttpComponent.doStart(JettyHttpCompone
> nt.java:187)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
> at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:42)
> at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:53)
> at
> org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.j
> ava:149)
> at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.ja
> va:256)
> at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHe
> lper.java:48)
> at org.apache.camel.model.RouteType.resolveEndpoint(RouteType.java:89)
> at org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:81)
> at org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:90)
> at org.apache.camel.model.FromType.resolveEndpoint(FromType.java:66)
> at org.apache.camel.impl.RouteContext.getEndpoint(RouteContext.java:59)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:179)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:80)
> at org.apache.camel.model.RouteType.addRoutes(RouteType.java:71)
> at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamel
> Context.java:449)
> at
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:4
> 41)
> at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
> at eip.status.camel.routes.MessageBroker.main(MessageBroker.java:93)
>  
>
> Thanks for help
> Robert
>
> -----Ursprüngliche Nachricht-----
> Von: Guillaume Nodet [mailto:gnodet@gmail.com] 
> Gesendet: Donnerstag, 27. Dezember 2007 17:04
> An: camel-user@activemq.apache.org
> Betreff: Re: Call Web Services from Camel
>
> There is a CXF based component that you should be able to use it provided
> that you configure it correctly for REST.  Else, if you have problems to do
> that using the HTTP component, let us know, as it should be able to work
> too.
>
> On Dec 27, 2007 3:45 PM, Robert Thullner <rt...@gmx.at> wrote:
>
>   
>> Hi
>>
>> Is it possible to invoke Web Services within my CamelContext? 
>> Especially I want to invoke a REST service and a service implemented in
>>     
> CXF or Axis.
>   
>> My scenario is the following: When a jms message is received on a 
>> queue, the REST service and the Axis service shall be invoked and the 
>> results of the two services shall be passed back on some other queue?
>> Can this be done by using the Camel HTTP component or is it advisable 
>> to just implement the Webservice calling in some Java class?
>> For me it would be a nice architecture if I could do the web service 
>> calling in my camel context, so I could get it out of my Java classes. 
>> So my question is if that can be done when using Camel?
>>
>> Thanks for any suggestions
>> Robert
>>
>>     
>
>
>
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
>
>
>   

AW: Call Web Services from Camel

Posted by Robert Thullner <rt...@gmx.at>.
Thanks for the reply.

I looked at both components, but I still have some understanding problems.
My problem is that I do not know how to trigger the webservice call from
camel.
Usually I have a rule:

from(...)
.to(...); 

So I wait for an event and write the event to somewhere else.

My scenario is something like that.
from(...)
.call(webservice 1)
.call(webservice 2)
.to(resultQueue);

Do you have any tutorials for calling a service within a route? Or should it
be implemented somehow else?



I also tried to get request from a REST webservice and write it the result
to a queue, as the service is called from the browser window. I used the
jetty component for this, as the HttpComponent cannot be used as input
component.

My route looks like this:
from("jetty:http:localhost:8080/restapp-1.0.0/helloworld")
.to("activemq:queue:rest.queue");

But when I start the CamelContext I always get an exception (see below). I
have put the camel-http, camel-jetty, jetty, jetty-util and jetty-xbean jars
on my classpath, but there are still some classes missing. But I could not
find any jar file that includes the HttpClient class. What other jar files
do I need to get the JettyComponent working?


The exception is:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/mortbay/jetty/client/HttpClient
at
org.apache.camel.component.jetty.JettyHttpComponent.createHttpClient(JettyHt
tpComponent.java:193)
at
org.apache.camel.component.jetty.JettyHttpComponent.doStart(JettyHttpCompone
nt.java:187)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:42)
at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:53)
at
org.apache.camel.impl.DefaultCamelContext.getComponent(DefaultCamelContext.j
ava:149)
at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.ja
va:256)
at
org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHe
lper.java:48)
at org.apache.camel.model.RouteType.resolveEndpoint(RouteType.java:89)
at org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:81)
at org.apache.camel.impl.RouteContext.resolveEndpoint(RouteContext.java:90)
at org.apache.camel.model.FromType.resolveEndpoint(FromType.java:66)
at org.apache.camel.impl.RouteContext.getEndpoint(RouteContext.java:59)
at org.apache.camel.model.RouteType.addRoutes(RouteType.java:179)
at org.apache.camel.model.RouteType.addRoutes(RouteType.java:80)
at org.apache.camel.model.RouteType.addRoutes(RouteType.java:71)
at
org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamel
Context.java:449)
at
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:4
41)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:51)
at eip.status.camel.routes.MessageBroker.main(MessageBroker.java:93)
 

Thanks for help
Robert

-----Ursprüngliche Nachricht-----
Von: Guillaume Nodet [mailto:gnodet@gmail.com] 
Gesendet: Donnerstag, 27. Dezember 2007 17:04
An: camel-user@activemq.apache.org
Betreff: Re: Call Web Services from Camel

There is a CXF based component that you should be able to use it provided
that you configure it correctly for REST.  Else, if you have problems to do
that using the HTTP component, let us know, as it should be able to work
too.

On Dec 27, 2007 3:45 PM, Robert Thullner <rt...@gmx.at> wrote:

> Hi
>
> Is it possible to invoke Web Services within my CamelContext? 
> Especially I want to invoke a REST service and a service implemented in
CXF or Axis.
>
> My scenario is the following: When a jms message is received on a 
> queue, the REST service and the Axis service shall be invoked and the 
> results of the two services shall be passed back on some other queue?
> Can this be done by using the Camel HTTP component or is it advisable 
> to just implement the Webservice calling in some Java class?
> For me it would be a nice architecture if I could do the web service 
> calling in my camel context, so I could get it out of my Java classes. 
> So my question is if that can be done when using Camel?
>
> Thanks for any suggestions
> Robert
>



--
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/


Re: Call Web Services from Camel

Posted by Guillaume Nodet <gn...@gmail.com>.
There is a CXF based component that you should be able to use it provided
that you configure it correctly for REST.  Else, if you have problems to do
that using the HTTP component, let us know, as it should be able to work
too.

On Dec 27, 2007 3:45 PM, Robert Thullner <rt...@gmx.at> wrote:

> Hi
>
> Is it possible to invoke Web Services within my CamelContext? Especially I
> want to invoke a REST service and a service implemented in CXF or Axis.
>
> My scenario is the following: When a jms message is received on a queue,
> the
> REST service and the Axis service shall be invoked and the results of the
> two services shall be passed back on some other queue?
> Can this be done by using the Camel HTTP component or is it advisable to
> just implement the Webservice calling in some Java class?
> For me it would be a nice architecture if I could do the web service
> calling
> in my camel context, so I could get it out of my Java classes. So my
> question is if that can be done when using Camel?
>
> Thanks for any suggestions
> Robert
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/