null DataSource bean with Oracle in Camel Blueprint

Posted on

I have a simple Camel script that creates a datasource bean and then uses it with the JDBC component. I'm using JBoss Fuse 6.3.0 Karaf.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd     http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
        <property name="URL" value="jdbc:oracle:thin:@localhost:1521:SID"/>
        <property name="user" value="user"/>
        <property name="password" value="password"/>
    </bean>

    <camelContext id="myContext" xmlns="http://camel.apache.org/schema/blueprint">
        <route id="myRoute">
            <from uri="vm:myRoute"/>
            <setBody>
                <constant>SELECT 1 from my_table where rownum = 1</constant>
            </setBody>
            <to uri="jdbc:myDataSource"/>
        </route>
</camelContext>
</blueprint>

More often than not, when the script is deployed, myDataSource ends up being "null".

I've tried various tricks to see what's going on such as:

<setHeader headerName="fake_header">
                <groovy>                
                    println "myDataSource = " + camelContext.registry.lookup("myDataSource")

And I get an error that "myDataSource" is not in the registry - when it is null; on the times the data source is actually created, the object's address gets printed.

The behavior is entirely inconsistent. I just undeploy and redeploy the XML over and over and eventually the datasource has a value and things work.

I've even tried creating a data source in a Groovy block and I always seem to get one.

Is there a better, more stable & reliable, way to create the datasource? Is there a way to recover from the datasource not being initialized (e.g. Do a null check and add it to the registry if needed)?

Responses