You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marek Kasztelnik <ym...@cyfronet.pl> on 2011/01/12 14:14:18 UTC

xpath problem when creating own camelcontex inside osgi

Hej,

I have a problem with xpath when creating own camel context (e.g. in 
activator) inside osgi container (karaf). Following code:

public void start( BundleContext bc ) throws Exception {
         ccontext = new DefaultCamelContext();
         ccontext.addComponent("jms", 
getActiveMqJmsComponent("username", "pass", "failover://tcp://url"));
         try {
             ccontext.addRoutes(new RouteBuilder() {

                 @Override
                 public void configure() throws Exception {
                     Namespaces ns = new Namespaces("", "");
                     final XPathExpression testXpathExpression = ns
                             .xpath("/result/sensor_id/text()");

                     from("jms://topic:myTopic").process(new Processor() {

                         public void process(Exchange exchange) throws 
Exception {
                             System.out.println("test1: >" + 
testXpathExpression.evaluate(exchange)+ "<");
                             System.out.println("test2: >" + 
testXpathExpression.evaluate(exchange, Integer.class)+ "<");
                         }
                     });
                 }
             });
             ccontext.start();
         } catch (Exception e) {
             e.printStackTrace();
         }
         System.out.println("started");
     }

returns:

test: >com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList@1b993d6<
test: >null<

instead of 12 when sending:

<?xml version="1.0" encoding="UTF-8"?>
<result>
<sensor_id>12</sensor_id>
</result>

to myTopic topic.

12 is returned, when I create standalone application or create camel 
context using spring inside osgi budnel. Anyone know why creating own 
camel context inside osgi causes  so strange behaviour?


I'm using following configuration:

karaf@root> version
Major                2
Micro                1
Minor                1
Qualifier


[installed  ] [2.5.0        ] camel                    repo-0
[installed  ] [2.5.0        ] camel-core               repo-0
[installed  ] [2.5.0        ] camel-spring             repo-0
[installed  ] [2.5.0        ] camel-jms                repo-0


Re: xpath problem when creating own camelcontex inside osgi

Posted by Marek Kasztelnik <ym...@cyfronet.pl>.
W dniu 12.01.2011 14:18, davsclaus pisze:
> You have to create an OsgiCamelContext instead of the DefaultCamelContext.
Thanx, that was fast :)  After fast googling I found this piece of code:

protected CamelContext getCamelContext(ComponentContext componentContext) {
         CamelContextFactory contextFactory = new CamelContextFactory();
         
contextFactory.setBundleContext(componentContext.getBundleContext());
         return contextFactory.createContext();
}

it solves all my problems. Once again many thanx :)

greetings,
Marek

Re: xpath problem when creating own camelcontex inside osgi

Posted by davsclaus <ci...@yahoo.dk>.
You have to create an OsgiCamelContext instead of the DefaultCamelContext.
-- 
View this message in context: http://camel.465427.n5.nabble.com/xpath-problem-when-creating-own-camelcontex-inside-osgi-tp3338091p3338103.html
Sent from the Camel - Users mailing list archive at Nabble.com.