How to use pax-jdbc configuration outside Karaf

1,013 views
Skip to first unread message

Matteo Rulli

unread,
Jun 29, 2015, 10:50:22 AM6/29/15
to op...@googlegroups.com
Hello,
I'm trying to switch to pax-jdbc coming from a hand-crafted blueprint approach. At the time being, my blueprint for datasource bundle is the following:

<?xml version="1.0" encoding="UTF-8"?>

<cm:property-placeholder persistent-id="com.mycompany.ddauth.config" update-strategy="reload">
<cm:default-properties>
<cm:property name="url" value="" />
<cm:property name="user" value="" />
<cm:property name="password" value="" />
</cm:default-properties>
</cm:property-placeholder>
<bean id="mysqlDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="url" value="${url}"/>
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<property name="databaseName" value="testDBBlueprint" /> 
<property name="createDatabaseIfNotExist" value="true" />
</bean>
<bean id="mysqlXADataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<property name="url" value="${url}"/>
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<property name="databaseName" value="testDBBlueprint" /> <property 
name="createDatabaseIfNotExist" value="true" />
</bean>
<service ref="mysqlDataSource" interface="javax.sql.DataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/ddauthdb" />
</service-properties>
</service>
<service ref="mysqlXADataSource" interface="javax.sql.XADataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/xaddauthdb" />
</service-properties>
</service>
</blueprint>


and I would like to substitute this with the following configuration file (./load/org.ops4j.datasource-testDBBlueprint.cfg), as explained here:

osgi.jdbc.driver.name=MySql
databaseName
=testDBBlueprint
user
=myuser
password
=supersecret
dataSourceName
=ddauthdb
pool
.maxTotal=8

Is it possible to do that outside Karaf? I tried creating a ./load/org.ops4j.datasource-testDBBlueprint.cfg file for Felix FileInstall but it does not seem to work.

Thank you very much,
matteo

By the way, my runtime is the following: 

aQute.xray.plugin;version='[1.7.0,1.7.1)',\
com.mycompany.jpa.auth.entities;version='[0.0.0,0.0.1)',\
com.mycompany.users.api;version='[1.0.0,1.0.1)',\
com.mysql.jdbc;version='[5.1.35,5.1.36)',\
com.springsource.org.apache.commons.collections;version='[3.2.1,3.2.2)',\
log4j;version='[1.2.17,1.2.18)',\
org.apache.aries.blueprint;version='[1.1.0,1.1.1)',\
org.apache.aries.blueprint.api;version='[1.0.1,1.0.2)',\
org.apache.aries.blueprint.cm;version='[1.0.6,1.0.7)',\
org.apache.aries.blueprint.core;version='[1.4.3,1.4.4)',\
org.apache.aries.jndi;version='[1.0.0,1.0.1)',\
org.apache.aries.jpa.api;version='[1.0.2,1.0.3)',\
org.apache.aries.jpa.blueprint.aries;version='[1.0.4,1.0.5)',\
org.apache.aries.jpa.container;version='[1.0.2,1.0.3)',\
org.apache.aries.jpa.container.context;version='[1.0.4,1.0.5)',\
org.apache.aries.proxy.api;version='[1.0.1,1.0.2)',\
org.apache.aries.proxy.impl;version='[1.0.4,1.0.5)',\
org.apache.aries.transaction.blueprint;version='[1.0.2,1.0.3)',\
org.apache.aries.transaction.wrappers;version='[1.0.0,1.0.1)',\
org.apache.aries.util;version='[1.1.0,1.1.1)',\
org.apache.commons.dbcp2;version='[2.0.1,2.0.2)',\
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
org.apache.commons.pool;version='[1.6.0,1.6.1)',\
org.apache.commons.pool2;version='[2.2.0,2.2.1)',\
org.apache.felix.configadmin;version='[1.8.4,1.8.5)',\
org.apache.felix.eventadmin;version='[1.3.2,1.3.3)',\
org.apache.felix.fileinstall;version='[3.5.0,3.5.1)',\
org.apache.felix.gogo.command;version='[0.14.0,0.14.1)',\
org.apache.felix.gogo.runtime;version='[0.12.1,0.12.2)',\
org.apache.felix.gogo.shell;version='[0.10.0,0.10.1)',\
org.apache.felix.http.bundle;version='[2.3.0,2.3.1)',\
org.apache.felix.log;version='[1.0.0,1.0.1)',\
org.apache.felix.log;version='[1.0.1,1.0.2)',\
org.apache.felix.webconsole;version='[3.1.8,3.1.9)',\
org.apache.geronimo.specs.geronimo-j2ee-connector_1.5_spec;version='[2.0.0,2.0.1)',\
org.apache.geronimo.specs.geronimo-jpa_2.0_spec;version='[1.1.0,1.1.1)',\
org.apache.geronimo.specs.geronimo-jta_1.1_spec;version='[1.1.1,1.1.2)',\
org.apache.openjpa;version='[2.2.2,2.2.3)',\
org.apache.servicemix.bundles.asm;version='[3.3.0,3.3.1)',\
org.apache.servicemix.bundles.cglib;version='[3.0.0,3.0.1)',\
org.apache.servicemix.bundles.commons-dbcp;version='[1.4.0,1.4.1)',\
org.apache.servicemix.bundles.serp;version='[1.14.1,1.14.2)',\
org.objectweb.asm.all;version='[5.0.3,5.0.4)',\
org.ops4j.base.lang;version='[1.5.0,1.5.1)',\
org.ops4j.base.spi;version='[1.5.0,1.5.1)',\
org.ops4j.pax.configmanager;version='[0.2.3,0.2.4)',\
org.ops4j.pax.jdbc;version='[0.6.0,0.6.1)',\
org.ops4j.pax.jdbc.config;version='[0.6.0,0.6.1)',\
org.ops4j.pax.jdbc.mysql;version='[0.6.0,0.6.1)',\
org.ops4j.pax.jdbc.pool.common;version='[0.6.0,0.6.1)',\
org.ops4j.pax.jdbc.pool.dbcp2;version='[0.5.0,0.5.1)',\
org.ops4j.pax.logging.pax-logging-api;version='[1.8.3,1.8.4)',\
org.ops4j.pax.logging.pax-logging-service;version='[1.8.3,1.8.4)',\
org.ops4j.pax.swissbox.core;version='[1.8.1,1.8.2)',\
org.ops4j.pax.swissbox.extender;version='[1.8.1,1.8.2)',\
org.ops4j.pax.swissbox.lifecycle;version='[1.8.1,1.8.2)',\
org.osgi.service.jdbc;version='[0.6.0,0.6.1)'

Christian Schneider

unread,
Jun 29, 2015, 11:04:58 AM6/29/15
to op...@googlegroups.com
Hi Matteo,

the first thing you should do is to validate your config is working inside of karaf so you know it is correct.
The trick about making the configs work is to use a combination of felix config admin and felix file install and configure them like karaf does.

So for example this is set in config.properties in karaf:
felix.fileinstall.enableConfigSave = true
felix.fileinstall.dir    = ${karaf.etc}
felix.fileinstall.filter = .*\\.cfg
felix.fileinstall.poll   = 1000
felix.fileinstall.noInitialDelay = true
felix.fileinstall.log.level = 3
felix.fileinstall.log.default = jul


Not sure if this is enough but it might be a starting point.

Christian
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

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

Matteo Rulli

unread,
Jun 29, 2015, 4:31:37 PM6/29/15
to op...@googlegroups.com
Hi Christian,
Thank you very much for the hint. I followed you suggestion and I came up with the following cnf file (indeed the original one I used had few typos):

osgi.jdbc.driver.name=mysql-pool-xa
osgi.jdbc.driver.class=com.mysql.jdbc.Driver
databaseName=testDBBlueprint
url=jdbc:mysql://localhost:3306/testDBBlueprint
user=testuser
password=supersecret
dataSourceName=ddauthdb


If I deploy this file in karaf I get the expected datasource:

[javax.sql.DataSource]

----------------------

 databaseName = testDBBlueprint

 dataSourceName = ddauthdb

 felix.fileinstall.filename = file:/.../apache-karaf-3.0.3/etc/org.ops4j.datasource-testDBBlueprint.cfg

 osgi.jdbc.driver.class = com.mysql.jdbc.Driver

 osgi.jdbc.driver.name = mysql-pool-xa

 osgi.jndi.service.name = ddauthdb

 password = supersecret

 service.factoryPid = org.ops4j.datasource

 service.id = 706

 service.pid = org.ops4j.datasource.32633d90-dfcf-4aec-b6b3-e9366a30cabc

 url = jdbc:mysql://localhost:3306/testDBBlueprint

 user = testuser

Provided by : 

 OPS4J Pax JDBC Config (78)


After that I switched again to my development env and I specified the FileInstall props as you suggested. Unfortunately, I get the following exception:

[org.ops4j.pax.jdbc.pool.dbcp2.impl.ds.PooledDataSourceFactory] : Error creating pooled datasourcecannot set properties [dataSourceName]

java.sql.SQLException: cannot set properties [dataSourceName]

at org.ops4j.pax.jdbc.mysql.impl.MysqlDataSourceFactory.setProperties(MysqlDataSourceFactory.java:71)

at org.ops4j.pax.jdbc.mysql.impl.MysqlDataSourceFactory.createXADataSource(MysqlDataSourceFactory.java:86)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.ds.XAPooledDataSourceFactory.createDataSourceInternal(XAPooledDataSourceFactory.java:54)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.ds.PooledDataSourceFactory.createDataSource(PooledDataSourceFactory.java:66)

at org.ops4j.pax.jdbc.config.impl.DataSourcePublisher.createDs(DataSourcePublisher.java:121)

at org.ops4j.pax.jdbc.config.impl.DataSourcePublisher.publish(DataSourcePublisher.java:82)

at org.ops4j.pax.jdbc.config.impl.DataSourceManager$DataSourceFactoryTracker.addingService(DataSourceManager.java:166)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)

at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)

at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)

at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)

at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)

at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:914)

at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)

at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)

at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)

at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:464)

at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:482)

at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:998)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.DataSourceFactoryTracker.createAndRegisterPooledFactory(DataSourceFactoryTracker.java:65)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.DataSourceFactoryTracker.addingService(DataSourceFactoryTracker.java:56)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.DataSourceFactoryTracker.addingService(DataSourceFactoryTracker.java:36)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)

at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)

at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)

at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)

at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.TransactionManagerTracker.addingService(TransactionManagerTracker.java:36)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.TransactionManagerTracker.addingService(TransactionManagerTracker.java:11)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)

at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)

at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)

at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)

at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)

at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)

at org.ops4j.pax.jdbc.pool.dbcp2.impl.Activator.start(Activator.java:35)

at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)

at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)

at java.security.AccessController.doPrivileged(Native Method)

at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)

at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:721)

at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:936)

at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:319)

at org.eclipse.osgi.container.Module.doStart(Module.java:571)

at org.eclipse.osgi.container.Module.start(Module.java:439)

at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:393)

at aQute.launcher.Launcher.update(Launcher.java:457)

at aQute.launcher.Launcher.activate(Launcher.java:354)

at aQute.launcher.Launcher.run(Launcher.java:238)

at aQute.launcher.Launcher.main(Launcher.java:87)


Thank you again for your help,
matteo

Matteo Rulli

unread,
Jun 29, 2015, 7:19:30 PM6/29/15
to op...@googlegroups.com
Just an update. If I use the osgi.jdbc.driver.name=mysql I can get my data source up and running. The exception is triggered as soon as I specify the osgi.jdbc.driver.name=mysql-pool-xa property.

This is strange because I can see all the three DataSourceFactory services up and running in the felix http console:


The following is the datasource generated by my org.ops4j.datasource-testDBBlueprint.cfg config file:

[javax.sql.DataSource]
databaseNametestDBBlueprint
dataSourceNameddauthdb
felix.fileinstall.filenamefile:/.../load/org.ops4j.datasource-testDBBlueprint.cfg
osgi.jdbc.driver.classcom.mysql.jdbc.Driver
osgi.jdbc.driver.namemysql
osgi.jndi.service.nameddauthdb
passwordsupersecret
service.factoryPidorg.ops4j.datasource
Service PIDorg.ops4j.datasource.6c5836c1-4b31-4e3d-a972-8de047e1999f
urljdbc:mysql://localhost:3306/testDBBlueprint
usertestuser
service.bundleid51
service.scopesingleton
Using Bundlescom.deltador.jpa.auth.entities (2)

So apparently the last step I'm missing is how to avoid the exception in my previous post and get my pooled xa datasource.

Thank you,
matteo

Christian Schneider

unread,
Jun 30, 2015, 3:01:07 AM6/30/15
to op...@googlegroups.com
If you look at your first mail in the bundles you see that you mixed up two versions of pax-jdbc. Make sure you take all bundles from the most current 0.6.0 version.

This is the wrong one:
org.ops4j.pax.jdbc.pool.dbcp2;version='[0.5.0,0.5.1)',\

The dataSourceName property is only used to announce the data source in the OSGi service. It may not go through to the original DataSourceFactory. The 0.5.0 version did not yet correctly filter it.

Christian

Matteo Rulli

unread,
Jun 30, 2015, 4:15:24 AM6/30/15
to op...@googlegroups.com
Christian,
I really don't know how much time I would have needed to spot this error. Probably a month! I really thank you: if you like beer, I would definitely be glad to offer you one as soon as I get the chance to meet you :o)

Thank you!

By the way, everything works perfect now and I can also get a reference of the datasource in my persistence.xml. Splendid! 

matteo
...
Reply all
Reply to author
Forward
0 new messages