You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by vi...@wipro.com on 2014/01/15 12:45:55 UTC

Using JDBC data source from another OSGi service

Started working on an application development with Apache Karaf as run time recently. Have a problem with respect to accessing a JDBC data source deployed as OSGi service from another OSGi service, both using blueprint containers. I am following the tutorial https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejdbc using apache karaf 3.0.0 and postgres 9.1 as database

Created the data source as below and deployed in deploy folder.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
  
   <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
      <property name="serverName" value="localhost:5432/masterdb"/>
      <property name="user" value="userid"/>
      <property name="password" value="password"/>
      <property name="dataSourceName" value=" masterdb "/>
      <property name="initialConnections" value="2"/>
      <property name="maxConnections" value="4" />
  </bean>
  
  <service interface="javax.sql.DataSource" ref="dataSource">
    <service-properties>
            <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
    </service-properties>
  </service>
</blueprint>

When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.

karaf@root()> jndi:names
JNDI Name                    | Class Name
-----------------------------------------------------------------------------
osgi:servicejdbc/masterDb | org.postgresql.ds.PGPoolingDataSource
osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl

karaf@root()> jdbc:datasources
Name             | Product    | Version | URL                                                                                                                           
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false

I am trying use this data source from another service which is invoked from an Apache Camel Route.  Code is as below

public class SvcMain implements ProcessingUnit {
	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
	private DataSource masterDb;

	public void setMasterDb(DataSource masterDb) {
		this.masterDb = masterDb;
		if(this.masterDb == null) {
			LOG.info("masterDb is null.");
		}
	}

	public void process(DataSet dataset) throws ProcessingUnitException {
		LOG.info(dataset.getRecords().toString());
		try {
			if(this.masterDb != null) {
				Connection c = this.masterDb.getConnection();
				DatabaseMetaData dbMeta = c.getMetaData();
				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
			}
			else {
				LOG.info("Data source masterDb is null.");
			}
		} catch (SQLException e) {
			LOG.info("Error getting database connection, "+e.getMessage());
		}
	}
}

Blueprint descriptor for the service is as below.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
	<bean id="SvcImpl" class="com.foo.SvcMain">
		<property name="masterDb" ref="masterDb"/>
	</bean>
	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
		<service-properties>
			<entry key="pu.svc.name" value="Svc" />
			<entry key="pu.svc.version" value="1.0.0" />
		</service-properties>
	</service>
</blueprint>


In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ? 

regards
Vinu

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

Re: Using JDBC data source from another OSGi service

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
By the way, did you try both eager and lazy in blueprint ?

On 01/15/2014 01:47 PM, vinuraj.maroli@wipro.com wrote:
> Yes. This is what I got.
>
> [javax.sql.DataSource]
> ----------------------
>   osgi.jndi.service.name = jdbc/masterdb
>   osgi.service.blueprint.compname = dataSource
>   service.id = 501
> Provided by :
>   Bundle 149
>
> regards
> Vinu
>
> -----Original Message-----
> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
> Sent: Wednesday, January 15, 2014 6:11 PM
> To: user@karaf.apache.org
> Subject: Re: Using JDBC data source from another OSGi service
>
> Are you able to see the datasource service using the ls command ?
>
> Regards
> JB
>
> On 01/15/2014 01:35 PM, vinuraj.maroli@wipro.com wrote:
>> Hi,
>>
>> Yes I tried without filter. Got the same result.
>>
>> regrds
>> Vinu
>>
>> -----Original Message-----
>> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
>> Sent: Wednesday, January 15, 2014 5:53 PM
>> To: user@karaf.apache.org
>> Subject: Re: Using JDBC data source from another OSGi service
>>
>> Hi,
>>
>> did you try to remove the filter ? If you have only one datasource it should work. It's just to check if the problem is not the filter.
>>
>> Regards
>> JB
>>
>> On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
>>> Started working on an application development with Apache Karaf as
>>> run time recently. Have a problem with respect to accessing a JDBC
>>> data source deployed as OSGi service from another OSGi service, both
>>> using blueprint containers. I am following the tutorial
>>> https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejd
>>> b c using apache karaf 3.0.0 and postgres 9.1 as database
>>>
>>> Created the data source as below and deployed in deploy folder.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>>
>>>       <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>>>          <property name="serverName" value="localhost:5432/masterdb"/>
>>>          <property name="user" value="userid"/>
>>>          <property name="password" value="password"/>
>>>          <property name="dataSourceName" value=" masterdb "/>
>>>          <property name="initialConnections" value="2"/>
>>>          <property name="maxConnections" value="4" />
>>>      </bean>
>>>
>>>      <service interface="javax.sql.DataSource" ref="dataSource">
>>>        <service-properties>
>>>                <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>>>        </service-properties>
>>>      </service>
>>> </blueprint>
>>>
>>> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>>>
>>> karaf@root()> jndi:names
>>> JNDI Name                    | Class Name
>>> ---------------------------------------------------------------------
>>> -
>>> ------- osgi:servicejdbc/masterDb |
>>> org.postgresql.ds.PGPoolingDataSource
>>> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>>>
>>> karaf@root()> jdbc:datasources
>>> Name             | Product    | Version | URL
>>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>>>
>>> I am trying use this data source from another service which is
>>> invoked from an Apache Camel Route.  Code is as below
>>>
>>> public class SvcMain implements ProcessingUnit {
>>> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
>>> 	private DataSource masterDb;
>>>
>>> 	public void setMasterDb(DataSource masterDb) {
>>> 		this.masterDb = masterDb;
>>> 		if(this.masterDb == null) {
>>> 			LOG.info("masterDb is null.");
>>> 		}
>>> 	}
>>>
>>> 	public void process(DataSet dataset) throws ProcessingUnitException {
>>> 		LOG.info(dataset.getRecords().toString());
>>> 		try {
>>> 			if(this.masterDb != null) {
>>> 				Connection c = this.masterDb.getConnection();
>>> 				DatabaseMetaData dbMeta = c.getMetaData();
>>> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
>>> 			}
>>> 			else {
>>> 				LOG.info("Data source masterDb is null.");
>>> 			}
>>> 		} catch (SQLException e) {
>>> 			LOG.info("Error getting database connection, "+e.getMessage());
>>> 		}
>>> 	}
>>> }
>>>
>>> Blueprint descriptor for the service is as below.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
>>> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
>>> 	<bean id="SvcImpl" class="com.foo.SvcMain">
>>> 		<property name="masterDb" ref="masterDb"/>
>>> 	</bean>
>>> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
>>> 		<service-properties>
>>> 			<entry key="pu.svc.name" value="Svc" />
>>> 			<entry key="pu.svc.version" value="1.0.0" />
>>> 		</service-properties>
>>> 	</service>
>>> </blueprint>
>>>
>>>
>>> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>>>
>>> regards
>>> Vinu
>>>
>>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>>
>>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>>
>>> www.wipro.com
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>
>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>
>> www.wipro.com
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Using JDBC data source from another OSGi service

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
It looks good.

Can you create another simple bundle with blueprint to see if the 
reference is correctly injected (I'm pretty sure it is) ? In that case, 
it's something in your application.

Regards
JB

On 01/15/2014 01:47 PM, vinuraj.maroli@wipro.com wrote:
> Yes. This is what I got.
>
> [javax.sql.DataSource]
> ----------------------
>   osgi.jndi.service.name = jdbc/masterdb
>   osgi.service.blueprint.compname = dataSource
>   service.id = 501
> Provided by :
>   Bundle 149
>
> regards
> Vinu
>
> -----Original Message-----
> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
> Sent: Wednesday, January 15, 2014 6:11 PM
> To: user@karaf.apache.org
> Subject: Re: Using JDBC data source from another OSGi service
>
> Are you able to see the datasource service using the ls command ?
>
> Regards
> JB
>
> On 01/15/2014 01:35 PM, vinuraj.maroli@wipro.com wrote:
>> Hi,
>>
>> Yes I tried without filter. Got the same result.
>>
>> regrds
>> Vinu
>>
>> -----Original Message-----
>> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
>> Sent: Wednesday, January 15, 2014 5:53 PM
>> To: user@karaf.apache.org
>> Subject: Re: Using JDBC data source from another OSGi service
>>
>> Hi,
>>
>> did you try to remove the filter ? If you have only one datasource it should work. It's just to check if the problem is not the filter.
>>
>> Regards
>> JB
>>
>> On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
>>> Started working on an application development with Apache Karaf as
>>> run time recently. Have a problem with respect to accessing a JDBC
>>> data source deployed as OSGi service from another OSGi service, both
>>> using blueprint containers. I am following the tutorial
>>> https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejd
>>> b c using apache karaf 3.0.0 and postgres 9.1 as database
>>>
>>> Created the data source as below and deployed in deploy folder.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>>
>>>       <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>>>          <property name="serverName" value="localhost:5432/masterdb"/>
>>>          <property name="user" value="userid"/>
>>>          <property name="password" value="password"/>
>>>          <property name="dataSourceName" value=" masterdb "/>
>>>          <property name="initialConnections" value="2"/>
>>>          <property name="maxConnections" value="4" />
>>>      </bean>
>>>
>>>      <service interface="javax.sql.DataSource" ref="dataSource">
>>>        <service-properties>
>>>                <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>>>        </service-properties>
>>>      </service>
>>> </blueprint>
>>>
>>> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>>>
>>> karaf@root()> jndi:names
>>> JNDI Name                    | Class Name
>>> ---------------------------------------------------------------------
>>> -
>>> ------- osgi:servicejdbc/masterDb |
>>> org.postgresql.ds.PGPoolingDataSource
>>> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>>>
>>> karaf@root()> jdbc:datasources
>>> Name             | Product    | Version | URL
>>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>>>
>>> I am trying use this data source from another service which is
>>> invoked from an Apache Camel Route.  Code is as below
>>>
>>> public class SvcMain implements ProcessingUnit {
>>> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
>>> 	private DataSource masterDb;
>>>
>>> 	public void setMasterDb(DataSource masterDb) {
>>> 		this.masterDb = masterDb;
>>> 		if(this.masterDb == null) {
>>> 			LOG.info("masterDb is null.");
>>> 		}
>>> 	}
>>>
>>> 	public void process(DataSet dataset) throws ProcessingUnitException {
>>> 		LOG.info(dataset.getRecords().toString());
>>> 		try {
>>> 			if(this.masterDb != null) {
>>> 				Connection c = this.masterDb.getConnection();
>>> 				DatabaseMetaData dbMeta = c.getMetaData();
>>> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
>>> 			}
>>> 			else {
>>> 				LOG.info("Data source masterDb is null.");
>>> 			}
>>> 		} catch (SQLException e) {
>>> 			LOG.info("Error getting database connection, "+e.getMessage());
>>> 		}
>>> 	}
>>> }
>>>
>>> Blueprint descriptor for the service is as below.
>>>
>>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
>>> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
>>> 	<bean id="SvcImpl" class="com.foo.SvcMain">
>>> 		<property name="masterDb" ref="masterDb"/>
>>> 	</bean>
>>> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
>>> 		<service-properties>
>>> 			<entry key="pu.svc.name" value="Svc" />
>>> 			<entry key="pu.svc.version" value="1.0.0" />
>>> 		</service-properties>
>>> 	</service>
>>> </blueprint>
>>>
>>>
>>> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>>>
>>> regards
>>> Vinu
>>>
>>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>>
>>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>>
>>> www.wipro.com
>>>
>>
>> --
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com
>>
>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>
>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>
>> www.wipro.com
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

RE: Using JDBC data source from another OSGi service

Posted by vi...@wipro.com.
Yes. This is what I got.

[javax.sql.DataSource]
----------------------
 osgi.jndi.service.name = jdbc/masterdb
 osgi.service.blueprint.compname = dataSource
 service.id = 501
Provided by :
 Bundle 149

regards
Vinu

-----Original Message-----
From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net] 
Sent: Wednesday, January 15, 2014 6:11 PM
To: user@karaf.apache.org
Subject: Re: Using JDBC data source from another OSGi service

Are you able to see the datasource service using the ls command ?

Regards
JB

On 01/15/2014 01:35 PM, vinuraj.maroli@wipro.com wrote:
> Hi,
>
> Yes I tried without filter. Got the same result.
>
> regrds
> Vinu
>
> -----Original Message-----
> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
> Sent: Wednesday, January 15, 2014 5:53 PM
> To: user@karaf.apache.org
> Subject: Re: Using JDBC data source from another OSGi service
>
> Hi,
>
> did you try to remove the filter ? If you have only one datasource it should work. It's just to check if the problem is not the filter.
>
> Regards
> JB
>
> On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
>> Started working on an application development with Apache Karaf as 
>> run time recently. Have a problem with respect to accessing a JDBC 
>> data source deployed as OSGi service from another OSGi service, both 
>> using blueprint containers. I am following the tutorial 
>> https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejd
>> b c using apache karaf 3.0.0 and postgres 9.1 as database
>>
>> Created the data source as below and deployed in deploy folder.
>>
>> <?xml version="1.0" encoding="UTF-8"?> <blueprint 
>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>
>>      <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>>         <property name="serverName" value="localhost:5432/masterdb"/>
>>         <property name="user" value="userid"/>
>>         <property name="password" value="password"/>
>>         <property name="dataSourceName" value=" masterdb "/>
>>         <property name="initialConnections" value="2"/>
>>         <property name="maxConnections" value="4" />
>>     </bean>
>>
>>     <service interface="javax.sql.DataSource" ref="dataSource">
>>       <service-properties>
>>               <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>>       </service-properties>
>>     </service>
>> </blueprint>
>>
>> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>>
>> karaf@root()> jndi:names
>> JNDI Name                    | Class Name
>> ---------------------------------------------------------------------
>> -
>> ------- osgi:servicejdbc/masterDb |
>> org.postgresql.ds.PGPoolingDataSource
>> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>>
>> karaf@root()> jdbc:datasources
>> Name             | Product    | Version | URL
>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>>
>> I am trying use this data source from another service which is 
>> invoked from an Apache Camel Route.  Code is as below
>>
>> public class SvcMain implements ProcessingUnit {
>> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
>> 	private DataSource masterDb;
>>
>> 	public void setMasterDb(DataSource masterDb) {
>> 		this.masterDb = masterDb;
>> 		if(this.masterDb == null) {
>> 			LOG.info("masterDb is null.");
>> 		}
>> 	}
>>
>> 	public void process(DataSet dataset) throws ProcessingUnitException {
>> 		LOG.info(dataset.getRecords().toString());
>> 		try {
>> 			if(this.masterDb != null) {
>> 				Connection c = this.masterDb.getConnection();
>> 				DatabaseMetaData dbMeta = c.getMetaData();
>> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
>> 			}
>> 			else {
>> 				LOG.info("Data source masterDb is null.");
>> 			}
>> 		} catch (SQLException e) {
>> 			LOG.info("Error getting database connection, "+e.getMessage());
>> 		}
>> 	}
>> }
>>
>> Blueprint descriptor for the service is as below.
>>
>> <?xml version="1.0" encoding="UTF-8"?> <blueprint 
>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
>> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
>> 	<bean id="SvcImpl" class="com.foo.SvcMain">
>> 		<property name="masterDb" ref="masterDb"/>
>> 	</bean>
>> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
>> 		<service-properties>
>> 			<entry key="pu.svc.name" value="Svc" />
>> 			<entry key="pu.svc.version" value="1.0.0" />
>> 		</service-properties>
>> 	</service>
>> </blueprint>
>>
>>
>> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>>
>> regards
>> Vinu
>>
>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>
>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>
>> www.wipro.com
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

Re: Using JDBC data source from another OSGi service

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Are you able to see the datasource service using the ls command ?

Regards
JB

On 01/15/2014 01:35 PM, vinuraj.maroli@wipro.com wrote:
> Hi,
>
> Yes I tried without filter. Got the same result.
>
> regrds
> Vinu
>
> -----Original Message-----
> From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net]
> Sent: Wednesday, January 15, 2014 5:53 PM
> To: user@karaf.apache.org
> Subject: Re: Using JDBC data source from another OSGi service
>
> Hi,
>
> did you try to remove the filter ? If you have only one datasource it should work. It's just to check if the problem is not the filter.
>
> Regards
> JB
>
> On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
>> Started working on an application development with Apache Karaf as run
>> time recently. Have a problem with respect to accessing a JDBC data
>> source deployed as OSGi service from another OSGi service, both using
>> blueprint containers. I am following the tutorial
>> https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejdb
>> c using apache karaf 3.0.0 and postgres 9.1 as database
>>
>> Created the data source as below and deployed in deploy folder.
>>
>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>>
>>      <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>>         <property name="serverName" value="localhost:5432/masterdb"/>
>>         <property name="user" value="userid"/>
>>         <property name="password" value="password"/>
>>         <property name="dataSourceName" value=" masterdb "/>
>>         <property name="initialConnections" value="2"/>
>>         <property name="maxConnections" value="4" />
>>     </bean>
>>
>>     <service interface="javax.sql.DataSource" ref="dataSource">
>>       <service-properties>
>>               <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>>       </service-properties>
>>     </service>
>> </blueprint>
>>
>> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>>
>> karaf@root()> jndi:names
>> JNDI Name                    | Class Name
>> ----------------------------------------------------------------------
>> ------- osgi:servicejdbc/masterDb |
>> org.postgresql.ds.PGPoolingDataSource
>> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>>
>> karaf@root()> jdbc:datasources
>> Name             | Product    | Version | URL
>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>>
>> I am trying use this data source from another service which is invoked
>> from an Apache Camel Route.  Code is as below
>>
>> public class SvcMain implements ProcessingUnit {
>> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
>> 	private DataSource masterDb;
>>
>> 	public void setMasterDb(DataSource masterDb) {
>> 		this.masterDb = masterDb;
>> 		if(this.masterDb == null) {
>> 			LOG.info("masterDb is null.");
>> 		}
>> 	}
>>
>> 	public void process(DataSet dataset) throws ProcessingUnitException {
>> 		LOG.info(dataset.getRecords().toString());
>> 		try {
>> 			if(this.masterDb != null) {
>> 				Connection c = this.masterDb.getConnection();
>> 				DatabaseMetaData dbMeta = c.getMetaData();
>> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
>> 			}
>> 			else {
>> 				LOG.info("Data source masterDb is null.");
>> 			}
>> 		} catch (SQLException e) {
>> 			LOG.info("Error getting database connection, "+e.getMessage());
>> 		}
>> 	}
>> }
>>
>> Blueprint descriptor for the service is as below.
>>
>> <?xml version="1.0" encoding="UTF-8"?> <blueprint
>> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
>> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
>> 	<bean id="SvcImpl" class="com.foo.SvcMain">
>> 		<property name="masterDb" ref="masterDb"/>
>> 	</bean>
>> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
>> 		<service-properties>
>> 			<entry key="pu.svc.name" value="Svc" />
>> 			<entry key="pu.svc.version" value="1.0.0" />
>> 		</service-properties>
>> 	</service>
>> </blueprint>
>>
>>
>> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>>
>> regards
>> Vinu
>>
>> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>>
>> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>>
>> www.wipro.com
>>
>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

RE: Using JDBC data source from another OSGi service

Posted by vi...@wipro.com.
Hi,

Yes I tried without filter. Got the same result.

regrds
Vinu

-----Original Message-----
From: Jean-Baptiste Onofré [mailto:jb@nanthrax.net] 
Sent: Wednesday, January 15, 2014 5:53 PM
To: user@karaf.apache.org
Subject: Re: Using JDBC data source from another OSGi service

Hi,

did you try to remove the filter ? If you have only one datasource it should work. It's just to check if the problem is not the filter.

Regards
JB

On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
> Started working on an application development with Apache Karaf as run 
> time recently. Have a problem with respect to accessing a JDBC data 
> source deployed as OSGi service from another OSGi service, both using 
> blueprint containers. I am following the tutorial 
> https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejdb
> c using apache karaf 3.0.0 and postgres 9.1 as database
>
> Created the data source as below and deployed in deploy folder.
>
> <?xml version="1.0" encoding="UTF-8"?> <blueprint 
> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>
>     <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>        <property name="serverName" value="localhost:5432/masterdb"/>
>        <property name="user" value="userid"/>
>        <property name="password" value="password"/>
>        <property name="dataSourceName" value=" masterdb "/>
>        <property name="initialConnections" value="2"/>
>        <property name="maxConnections" value="4" />
>    </bean>
>
>    <service interface="javax.sql.DataSource" ref="dataSource">
>      <service-properties>
>              <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>      </service-properties>
>    </service>
> </blueprint>
>
> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>
> karaf@root()> jndi:names
> JNDI Name                    | Class Name
> ----------------------------------------------------------------------
> ------- osgi:servicejdbc/masterDb | 
> org.postgresql.ds.PGPoolingDataSource
> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>
> karaf@root()> jdbc:datasources
> Name             | Product    | Version | URL
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>
> I am trying use this data source from another service which is invoked 
> from an Apache Camel Route.  Code is as below
>
> public class SvcMain implements ProcessingUnit {
> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
> 	private DataSource masterDb;
>
> 	public void setMasterDb(DataSource masterDb) {
> 		this.masterDb = masterDb;
> 		if(this.masterDb == null) {
> 			LOG.info("masterDb is null.");
> 		}
> 	}
>
> 	public void process(DataSet dataset) throws ProcessingUnitException {
> 		LOG.info(dataset.getRecords().toString());
> 		try {
> 			if(this.masterDb != null) {
> 				Connection c = this.masterDb.getConnection();
> 				DatabaseMetaData dbMeta = c.getMetaData();
> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
> 			}
> 			else {
> 				LOG.info("Data source masterDb is null.");
> 			}
> 		} catch (SQLException e) {
> 			LOG.info("Error getting database connection, "+e.getMessage());
> 		}
> 	}
> }
>
> Blueprint descriptor for the service is as below.
>
> <?xml version="1.0" encoding="UTF-8"?> <blueprint 
> xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
> 	<bean id="SvcImpl" class="com.foo.SvcMain">
> 		<property name="masterDb" ref="masterDb"/>
> 	</bean>
> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
> 		<service-properties>
> 			<entry key="pu.svc.name" value="Svc" />
> 			<entry key="pu.svc.version" value="1.0.0" />
> 		</service-properties>
> 	</service>
> </blueprint>
>
>
> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>
> regards
> Vinu
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

Re: Using JDBC data source from another OSGi service

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

did you try to remove the filter ? If you have only one datasource it 
should work. It's just to check if the problem is not the filter.

Regards
JB

On 01/15/2014 12:45 PM, vinuraj.maroli@wipro.com wrote:
> Started working on an application development with Apache Karaf as run time recently. Have a problem with respect to accessing a JDBC data source deployed as OSGi service from another OSGi service, both using blueprint containers. I am following the tutorial https://github.com/cschneider/Karaf-Tutorial/tree/master/db/examplejdbc using apache karaf 3.0.0 and postgres 9.1 as database
>
> Created the data source as below and deployed in deploy folder.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
>
>     <bean id="dataSource" class="org.postgresql.ds.PGPoolingDataSource" destroy-method="close">
>        <property name="serverName" value="localhost:5432/masterdb"/>
>        <property name="user" value="userid"/>
>        <property name="password" value="password"/>
>        <property name="dataSourceName" value=" masterdb "/>
>        <property name="initialConnections" value="2"/>
>        <property name="maxConnections" value="4" />
>    </bean>
>
>    <service interface="javax.sql.DataSource" ref="dataSource">
>      <service-properties>
>              <entry key="osgi.jndi.service.name" value="jdbc/masterdb "/>
>      </service-properties>
>    </service>
> </blueprint>
>
> When I checked the JNDI names using the JNDI enterprise services its showing as below.  I am able to connect and query the database using jdbc enterprise features using the data source created.
>
> karaf@root()> jndi:names
> JNDI Name                    | Class Name
> -----------------------------------------------------------------------------
> osgi:servicejdbc/masterDb | org.postgresql.ds.PGPoolingDataSource
> osgi:service/jndi            | org.apache.karaf.jndi.internal.JndiServiceImpl
>
> karaf@root()> jdbc:datasources
> Name             | Product    | Version | URL
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> jdbc/masterDb| PostgreSQL | 9.1.1   | jdbc:postgresql://localhost:5432/masterDb/null?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false
>
> I am trying use this data source from another service which is invoked from an Apache Camel Route.  Code is as below
>
> public class SvcMain implements ProcessingUnit {
> 	static Logger LOG = LoggerFactory.getLogger(SvcMain.class);
> 	private DataSource masterDb;
>
> 	public void setMasterDb(DataSource masterDb) {
> 		this.masterDb = masterDb;
> 		if(this.masterDb == null) {
> 			LOG.info("masterDb is null.");
> 		}
> 	}
>
> 	public void process(DataSet dataset) throws ProcessingUnitException {
> 		LOG.info(dataset.getRecords().toString());
> 		try {
> 			if(this.masterDb != null) {
> 				Connection c = this.masterDb.getConnection();
> 				DatabaseMetaData dbMeta = c.getMetaData();
> 				LOG.info("Connected using datasource " + dbMeta.getDatabaseProductName() + ", URL " + dbMeta.getURL());
> 			}
> 			else {
> 				LOG.info("Data source masterDb is null.");
> 			}
> 		} catch (SQLException e) {
> 			LOG.info("Error getting database connection, "+e.getMessage());
> 		}
> 	}
> }
>
> Blueprint descriptor for the service is as below.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
> 	<reference id="masterDb" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdbc/masterDb)"/>
> 	<bean id="SvcImpl" class="com.foo.SvcMain">
> 		<property name="masterDb" ref="masterDb"/>
> 	</bean>
> 	<service id="Svc" interface="com.foo.ProcessingUnit" ref="SvcImpl">
> 		<service-properties>
> 			<entry key="pu.svc.name" value="Svc" />
> 			<entry key="pu.svc.version" value="1.0.0" />
> 		</service-properties>
> 	</service>
> </blueprint>
>
>
> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>
> regards
> Vinu
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

RE: Using JDBC data source from another OSGi service

Posted by vi...@wipro.com.
Yes found the problem. After JB said everything is fine with data source and may be problem is with application, I checked the way service was invoked from the camel route where I was using the service implementation class name directly rather than referring using a the OSGi service identifier. Corrected it to point to a bean referring the service and is fine now.

Thanks for the support !
Vinu

-----Original Message-----
From: Christian Schneider [mailto:cschneider111@gmail.com] On Behalf Of Christian Schneider
Sent: Wednesday, January 15, 2014 7:10 PM
To: user@karaf.apache.org
Subject: Re: Using JDBC data source from another OSGi service

Hi Vinu,

I am not familiar with how ProcessingUnit is used in your camel route but my guess is that you have two instances of the class.
One instance is created by blueprint and contains the correct datasource and one other instance is created by camel and so does not contains the correct settings.

I propose to use the camel bean component instead if it works for you. 
With the bean component you can refer to blueprint beans by their id. 
Then you are sure the same instance is used that got injected with the data source.

Christian


On 15.01.2014 12:45, vinuraj.maroli@wipro.com wrote:
> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>
> regards
> Vinu
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com


--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

Re: Using JDBC data source from another OSGi service

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Vinu,

I am not familiar with how ProcessingUnit is used in your camel route 
but my guess is that you have two instances of the class.
One instance is created by blueprint and contains the correct datasource 
and one other instance is created by camel and so does not contains the 
correct settings.

I propose to use the camel bean component instead if it works for you. 
With the bean component you can refer to blueprint beans by their id. 
Then you are sure the same instance is used that got injected with the 
data source.

Christian


On 15.01.2014 12:45, vinuraj.maroli@wipro.com wrote:
> In the service implementation, data source is getting injected properly. That is in the setMasterDb method masterDb is not null which is called when the service is getting deployed. But when it comes to process method which called from camel route,  masterDb is null. Anything else I need to do other than the above mentioned ?
>
> regards
> Vinu
>
> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>
> www.wipro.com


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com