Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ABC2468D9 for ; Mon, 30 May 2011 13:34:53 +0000 (UTC) Received: (qmail 97053 invoked by uid 500); 30 May 2011 13:34:53 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 97005 invoked by uid 500); 30 May 2011 13:34:53 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 96997 invoked by uid 99); 30 May 2011 13:34:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 May 2011 13:34:53 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bengt.rodehav@gmail.com designates 209.85.214.45 as permitted sender) Received: from [209.85.214.45] (HELO mail-bw0-f45.google.com) (209.85.214.45) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 May 2011 13:34:46 +0000 Received: by bwz16 with SMTP id 16so3781448bwz.32 for ; Mon, 30 May 2011 06:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=dHpIXH/kSe9BSYihuB6m2V0hkH+d9cJWggeecy0k/mc=; b=Mt/hFO0KCHbMF/zfb/H11NUHu4KfOO7a/ajk+JfIft6r3Q+kReeCshKqUY4yVzTuTs EOT3U0VEpsgWaiRNtkcndfJnkIEL735Gm3ung4DpIf04C99BwcwG+TYKcS3Y/88GqHNa JFbzKIohp73UI3l0/e63mIewiI+lJ4w2qEbwQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=U/SCfkpaVqmab1mT9NvN7sEJRIFv6006RyC6DggVUpZzwqKn+hET27jBMnXF+JqGKQ Z65K/CKBJzV9W550w1tkwrDbPzZmxtFRJkbraCT2tAsm9f7hpHzzgYcVOACT/rN7XQRO QccoGDLqeH1QTdWhKUihPdrWnsQkL6LuJZGQY= MIME-Version: 1.0 Received: by 10.204.19.18 with SMTP id y18mr4368875bka.179.1306762465781; Mon, 30 May 2011 06:34:25 -0700 (PDT) Sender: bengt.rodehav@gmail.com Received: by 10.204.112.146 with HTTP; Mon, 30 May 2011 06:34:25 -0700 (PDT) In-Reply-To: <738F71DC-0756-44D1-80C4-F2349E780D81@gmail.com> References: <738F71DC-0756-44D1-80C4-F2349E780D81@gmail.com> Date: Mon, 30 May 2011 15:34:25 +0200 X-Google-Sender-Auth: UqMt8ce6NFm9EXrHpI6Vo8q70tw Message-ID: Subject: Re: Problems triggering a camel route in OSGi From: Bengt Rodehav To: users@camel.apache.org Content-Type: multipart/alternative; boundary=00032555aefe94287604a47e5809 X-Virus-Checked: Checked by ClamAV on apache.org --00032555aefe94287604a47e5809 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 m= y 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 > 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 =E4=B8=8B=E5=8D=888: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 =3D new CamelContextFactory(); >> factory.setBundleContext(getBundleContext()); >> mCamelContext =3D factory.createContext(); >> RouteBuilder builder =3D 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 =3D 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 =3D mCamelContext.createProducerTemplate();* >> * Map headers =3D new HashMap();* >> * // ...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 wo= rk >> 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 proble= m >> but it's definitely related to Camel. I checked what class loader is bei= ng >> 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 > > > > > > > > > --00032555aefe94287604a47e5809--