Friday, January 3, 2014

Resolving Apache ServiceMix JDBC JAR Classloading

This past year I've spent some time using Apache ServiceMix for service bus integration. One of the main issues I had was integration with database systems and using their provided JDBC drivers when defining the connection bean within Apache Camel. Many of the documented approached and user group threads did not work for me in environment. The main approaches being wrapping the JDBC JARs as OSGi bundles and / or installing the JDBC libraries as a maven repository so the dependencies are loaded properly in the ServiceMix container.

To resolve the issue in my case, I had to deploy the given JDBC JARs into the JRE library extensions (lib/ext) directory to allow the classloader to locate the libraries correctly. Once done however, I was not complete in the integration as the bean was not being detected as available within the routes in Camel as documented in the JDBC documentation. The connection was not available for passing data directly within the route. As a work around for this issue, I was forced to pass the JDBC bean reference in Camel into the depending bean as a reference. For example, if JDBC bean "model" was defined, and my logic bean as "controller", the "controller" bean definition in Camel looks like:

<bean class="com.controller.Service" id="controller">
<property name="dataSource" ref="model">

Within the "Service" object, would be getters and setters for the dataSource field as type "org.springframework.jdbc.datasource.DriverManagerDataSource".

Oh, and one more thing. The deployed JDBC libraries in the lib/ext directory would not be loaded given security trust exceptions, similar to this thread reports. As mentioned in the linked article, the fix was to deploy sunjce_provider.jar into the lib/ext as well. One implemented, the container was able properly load the third party JAR files.

All mentioned was done with Microsoft SQL Server and IBM DB2.

See Also:

No comments:

Share on Twitter