camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bengt Rodehav <be...@rodehav.com>
Subject Re: Problems triggering a camel route in OSGi
Date Mon, 30 May 2011 13:34:25 GMT
Thanks for your reply Freeman.

I'll try to explain although I found even the explaining is pretty hard...

My iPOJO object publishes an OSGi service which has a trigger() method that
is implemented as I wrote in my first post. This OSGi service is then used
by another iPOJO object that has the service injected by iPOJO using
"@Requires".

The latter iPOJO object instantiates a camel route of its own using
camel-cxf to publish a web service that I test from outside the container
using soapUI.

I did have problems getting camel-cxf to work. In order for Camel to find my
webservice interface, I had to set the TCCL to the class loader that owns
that interface. I have now checked what TCCL is active when my trigger()
method is called from the webservice and it seems to be that interface's
classloader. I suspect that this might be problematic but I'm not exactly
sure why or how I can fix it.

I hope I answered your question. Of your two alternate answers I think I'm
doing what you describe in the second answer (my camel router bundle
publishes an OSGi service that is being called from the bundle implementing
the web service using CXF).

/Bengt

2011/5/30 Freeman Fang <freeman.fang@gmail.com>

> Hi,
>
> Could you elaborate how you invoke trigger method from webservice call?
>
> Do you mean your customer bundle which contain camel router also exposed as
> webservice, and in this webservice impl class you invoke trigger method?
>
> Or your camel router bundle also published as a OSGi service, from which
> other code can invoke trigger method?
>
> Freeman
>
> On 2011-5-30, at 下午8:22, Bengt Rodehav wrote:
>
>  I have a very strange problem that is probably related to classloading. I
>> use Camel 2.7.1 in Karaf 2.2.0 together with iPOJO.
>>
>> I create my camel context like this:
>>
>>  @Validate
>>  public void start() {
>>   CamelContextFactory factory = new CamelContextFactory();
>>   factory.setBundleContext(getBundleContext());
>>   mCamelContext = factory.createContext();
>>   RouteBuilder builder = createRouteBuilder();
>>   try {
>>     mCamelContext.addRoutes(builder);
>>   } catch (Exception e) {
>>     e.printStackTrace();
>>   }
>>   try {
>>     mCamelContext.start();
>>   } catch (Exception e) {
>>     e.printStackTrace();
>>   }
>>   System.out.println("start, mCamelContext: " + mCamelContext);
>>  }
>>
>>
>> It is created when the iPOJO component becomes valid. I get the bundle
>> context in my constructor from iPOJO. The actual routes are created like
>> this:
>>
>>  private RouteBuilder createRouteBuilder() {
>>   RouteBuilder builder = new RouteBuilder() {
>>
>>     from("file:localdir").process(new Processor() {
>>       public void process(Exchange theExchange) throws Exception {
>>         trigger();
>>       }
>>     });
>>
>>     from("direct:start").process()....to("ftp:....);
>>   }
>>  }
>>
>> Both routes works fine. When dropping a file in the "localdir", the
>> trigger() method is called that in turn will send an exchange to the
>> "direct:start" endpoint that will do the real work. The trigger method
>> looks
>> like this:
>>
>> *  public void trigger() {    *
>> *
>>   System.out.println("trigger, mCamelContext: " + mCamelContext);
>>   ProducerTemplate producer = mCamelContext.createProducerTemplate();*
>> *    Map<String, Object> headers = new HashMap<String, Object>();*
>> *    // ...populate headers*
>> *    String body;*
>> *    // ... initialize body*
>> *    producer.sendBodyAndHeaders("direct:start", body, headers);*
>> *  }*
>> *
>> *
>> Dropping the file in "localdir" is just for testing purposes. In real
>> life,
>> the "direct:start" route is meant to be triggered via a published  OSGi
>> service (actually through a web service call). However, this does not work
>> at all.
>>
>> Whenever I try to call the trigger() method from somewhere else, the
>> mCamelContext member is null and I get a NPE when trying to create the
>> producer template. Why is that?
>>
>> I realize that this might not be a Camel problem but a OSGi/iPOJO problem
>> but it's definitely related to Camel. I checked what class loader is being
>> used to for the mCamelContext instance and it turns out to be the
>> camel-spring bundle's class loader. Could that be related to my problems?
>>
>> I am very confused about this and would appreciate any help,
>>
>> /Bengt
>>
>
> ---------------------------------------------
> Freeman Fang
>
> FuseSource
> Email:ffang@fusesource.com
> Web: fusesource.com
> Twitter: freemanfang
> Blog: http://freemanfang.blogspot.com
> Connect at CamelOne May 24-26
> The Open Source Integration Conference
>
>
>
>
>
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message