Apache camel blueprint MS SQL datasource on karaf - java

I am trying to access a MS SQL database with apache camel. I am building it with maven as a bundle and deploy it on apache karaf.To do this I got the following in my blueprint.xml
<bean id="dataSource" class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<property name="url" value="" />
<property name="user" value="paygate" />
<property name="password" value="" />
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/mssqlDatasource" />
</service-properties>
</service>
But now I am getting the following in my karaf logs
missing requirement [1374.6] osgi.wiring.package; (osgi.wiring.package=net.sourceforge.jtds.jdbcx)
This is the class that also was generated when creating the datasource in karaf with 'jdbc:create'.
Why doesn't karaf find that class?

Install the jtds jar as a bundle , using the command :
install -s wrap:mvn: net.sourceforge.jtds /jtds/1.3.0
Change version number to match your jar version, that will resolve the problem.

It is the MSSQL datasource,
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="jdbc:jtds:sqlserver://localhost:1433;databaseName=testdb"/>
<property name="username" value="sa"/>
<property name="password" value="root"/>
</bean>
Then you should install dbcp and jtds dependency in karaf container. It is working fine.

Related

SSl over Informix JDBC doesn't work under JBOSS 7

I want to use my Informix JDBC application over SSL. The DBMS is Informix IBM 11.70.
I'm using a spring-config.xml file in which I declare the datasource bean:
<!-- Data source -->
<bean id="dataSource" class="com.sopra.datasource.CustomDataSource" init-method="init"
destroy-method="close">
<property name="url" value="${url}" />
<property name="driverClassName" value="${driverClassName}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="removeAbandoned" value="true" />
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
</bean>
The problem is that when I deploy my application in Tomcat 7 everything goes well (both TCP and SSL mode), however, when I deploy it in JBOSS 7.1 the SSL connexion mode to the Informix database doesn't work!
When it comes to debugging, the only information that I have is the following :
Application side:
Caused by: com.informix.asf.IfxASFException: Attempt to connect to database server (my_server_ssl) failed.
at com.informix.util.IfxErrMsg.getLocIfxASFException(IfxErrMsg.java:751) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.openSocket(Connection.java:1864) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.<init>(Connection.java:427) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.jdbc.IfxSqliConnect.<init>(IfxSqliConnect.java:1416) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
... 47 more
Caused by: java.lang.NullPointerException
at com.informix.asf.Connection.getEnabledSSLProtocols(Connection.java:2242) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
at com.informix.asf.Connection.openSocket(Connection.java:1805) [jdbc-4.10.7.20160517.jar:4.1.0.SNAPSHOT]
... 49 more
Thanks in Advance.
This was due to a defect in the 4.10.7 version of the driver. Try upgrading to either 4.10.8 or 4.10.9 versions. They can be found via maven or through your IBM download site.
Gradle
compile group: 'com.ibm.informix', name: 'jdbc', version: '4.10.9'
Maven
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.10.9</version>
</dependency>

Configuring Spring to useMultiple Data Sources

I am trying to connect 2 different schemas within my spring boot application.
To do this I have got 2 different data sources. How should I configure this within my properties files?
I seen this answer which gave me an idea of how to do so. I currently have the following 3 property files in my application:
1. application.properties
2. hibernate.properties
3. multiple-db.properties
application.properties is currently empty. Below are the other 2 files:
hibernate.properties:
# Connection configuration
hibernate.connection.username= my_uname1
hibernate.connection.password= my_pword1
multiple-db.properties:
# Schema 1-Data source configuration
oracle.db.username1= my_uname1
oracle.db.password1= my_pword1
oracle.db.url1= my_url1
# Schema 2-Data source configuration
oracle.db.username2= my_uname2
oracle.db.password1= my_pword2
oracle.db.url2= my_url2
# JPA configuration
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
# Hibernate configuration
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=my_url
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
Is this the correct approach? Do I need 3 properties files, or could I do this all in one?
The Spring documentation suggests a way to create primary and secondary data sources:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-two-datasources
Each data source can be configured as described here:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-configure-a-datasource
You can access them by using #Autowire from other beans. You can associate a prefix to each data source so you can configure it in your application.properties or application.yml file.
You can also set one as primary.
With Spring you can do this easily.
It would be something like this:
<bean id="dataSource_1" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/northwind" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="dataSource_2" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/northwind_dup" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
You could also use your properties files and do something like this:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="jdbc.properties"/>
And you could use only one file, or three. It is really up to you.

Apache Camel - Read JDBC dataSource properties from file

i'm using Apache Camel and i try to load datasource properties from this file
config.properties:
url = my_url
user = user_name
password = user_pass
this is dataSource (blueprint.xml):
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="my_url"/>
<property name="user" value="user_name"/>
<property name="password" value="user_pass"/>
</bean>
How can i read values from config.properties and insert them into dataSource properties ?
You talk about blueprint.xml, and camel, so I assume you are in an osgi container like Karaf/ServiceMix, and you are using Aries Blueprint.
Then you can use the cm namespace and a property-placeholder. If you use camel and want your properties to be dynamically reloaded, then you can use too an update strategy reload, which start/stop the blueprint container when the configuration change. This will load the configuration with pid "datasource" (ie, in karaf, the file etc/datasource.cfg) :
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0">
<cm:cm-properties id="myProps" persistent-id="datasource" update-strategy="reload"/>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
</blueprint>
If you want to use your configuration file without using ConfigurationAdmin or dynamically reload your bundle, then you can use the ext namespace :
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0">
<ext:property-placeholder>
<ext:location>file:config.properties</ext:location>
</ext:property-placeholder>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${url}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
</blueprint>
According to code I assume you use probably spring as container. General solution in spring is to use PropertyPlaceHolder, your configuration will look like this:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>config.properties</value>
</property>
</bean>
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="${jdbc.myUrl}"/>
<property name="user" value="${jdbc.user_name}"/>
<property name="password" value="${jdbc.user_pass}"/>
</bean>
Please check the example for details.

How to integrate/call teradata db in Apache Camel?

I am fairly new to ApacheCamel and I am trying to integrate a TeraData DB call to our database and I cannot figure out the below error message. In addition, I am running this in fuse.
2016-01-22 16:17:36,725 [Blueprint Extender: 1] ERROR org.apache.aries.blueprint.container.BlueprintContainerImpl - Unable to start blueprint container for bundle fuse-maria-bundle
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to find property descriptor URL on class com.teradata.jdbc.TeraDriver
What I have done so far is added the below in my blueprint.xml
<bean id="teradata" class="com.teradata.jdbc.TeraDriver">
<property name="URL" value="jdbc:teradata://[inser database connection]" />
<property name="user" value="myuser" />
<property name="password" value="mypassword" />
</bean>
I have this in my pom.xml
<dependency>
<groupId>com.teradata.jdbc</groupId>
<artifactId>terajdbc4</artifactId>
<version>15.10.00.14</version>
</dependency>
<dependency>
<groupId>com.teradata.jdbc</groupId>
<artifactId>tdgssconfig</artifactId>
<version>15.10.00.14</version>
</dependency>
...and followed the instruction from this link where I downloaded the driver from teradata.com.
In my route, I have the below code.
#Override
public void configure() throws Exception {
from("timer://testtimer?period=1000000")
.enrich("sql:select count(*) from table1?dataSource=#teradata")
.log("Processing ${body}");
}
Any ideas would help. Thanks in advance!
You have to download database drivers (terajdbc4.jar). I think, you
already have it...
Now you have to install drivers to your container (Karaf, because you wrote "Fuse").
Installing from file, windows example (if drivers not OSGi ready), Karaf console:
install -s wrap:file:///c:/install/terajdbc4.jar
or installing from Maven repository:
install -s wrap:mvn:com.teradata.jdbc/terajdbc4/15.10.00.14
Mission complete.
About converting jars:
https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.0/html/Deploying_into_the_Container/files/DeployJar-Wrap.html
UPDATED:
The problem is that class com.teradata.jdbc.TeraDriver has no properties url, URL, and so on...
I recomend you to try org.apache.commons.dbcp.BasicDataSource like this:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.teradata.jdbc.TeraDriver" />
<property name="url" value="jdbc:teradata://[inser database connection]" />
<property name="username" value="myuser" />
<property name="password" value="mypassword" />
</bean>
Second option is org.springframework.jdbc.datasource.DriverManagerDataSource:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.ncr.teradata.TeraDriver" />
<property name="url" value="jdbc:teradata://[inser database connection]" />
<property name="username" value="myuser" />
<property name="password" value="mypassword" />
</bean>
The error is specific to the property URL you set on the TeraDriver bean , doesnt look like that property is avaialble on the class , can you try using "url" in small case

Creating a Spring DataSource for connecting to Google Cloud SQL

I'm trying to find the best way to create a dataSource in Spring for connecting to a Google Cloud SQL instance.
I'm currently using:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.GoogleDriver" />
<property name="url" value="jdbc:google:mysql://myappid:instanceId/mydb?user=myuser" />
<property name="username" value="myuser" />
<property name="password" value="mypassword" />
</bean>
However, I'm a little concerned about using the DriverManagerDataSource provided by Spring as it's documentation says it creates a new connection for every call.
Before migrating over to App Engine I was using a connection pool called BoneCP - however it uses classes that are restricted by App Engine. Is there a connection pool or some other data source class that is recommended to be used with Google Cloud SQL?
Try c3p0 or commons-dbcp. They both implement javax.sql.Datasource which is whitelisted by app-engine.
Example on commons-dbcp:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.GoogleDriver" />
<property name="url" value="jdbc:google:mysql://myappid:instanceId/mydb?user=myuser" />
<property name="username" value="myuser" />
<property name="password" value="mypassword" />
<property name="validationQuery" value="SELECT 1"/>
</bean>

Categories