Mulesoft DB2 Connection - db2

I am trying to connect to a DB2 database on a Mainframe. I am using the db2jcc.jar driver. My config looks like this:
<spring:beans>
<spring:bean id="db2DataSource" name="db2DataSource" class="com.ibm.db2.jcc.DB2DataSource" destroy-method="finalize" scope="singleton">
<spring:property name="serverName" value="mycompany.com"/>
<spring:property name="portNumber" value="7803"/>
<spring:property name="databaseName" value="DBNAME"/>
<spring:property name="driverType" value="4"/>
<spring:property name="user" value="username"/>
<spring:property name="password" value="password"/>
</spring:bean>
</spring:beans>
<db:generic-config name="DB2_Database"
driverClassName="com.ibm.db2.jcc.DB2Driver"
doc:name="Generic Database Configuration" dataSource-ref="db2DataSource"/>
<flow name="databaseexampleFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<db:select config-ref="DB2_Database" doc:name="Select from Table">
<db:dynamic-query><![CDATA[SELECT * FROM DB2.EA_SALEFRC_PRCSPOC;]]></db:dynamic-query>
</db:select>
<logger message="Selection: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
I am getting an error complaining about the DB2DataSource class.
Caused by: java.lang.ClassNotFoundException: Cannot load class 'com.ibm.db2.jcc.DB2DataSource'
I can Test the connection and it works fine. Any ideas?

Please check when you build your project for deploying the jar's for DB2 driver are exported with your project.
you can go to
{mule home}/apps/{your application}/lib
and check if jar's are available or not.

Related

connecting to Oracle XE with myBatis using JDBC in Eclipse

I'm using Eclipse with Maven, in myBatis-config.xml I have the following codes. The H2 part of the code works as I can connect to H2 with my program and access the database. The Oracle part of my code doesn't work. I'm using ORACLE DATABASE XE 11.2, application express with a workspace: test, username: name, password: 123. When I run a testing class in Eclipse, I could pass the H2 tests, but when I run the same test using oracle instead, it gets an error. "Error selecting key or setting result to parameter object. Case: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist.
<environment id="H2">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:tcp://localhost:9096/sample/testDB" />
<property name="username" value="sa" />
<property name="password" value="123" />
</dataSource>
</environment>
<environment id="ORACLE">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#localhost:1521:xe" />
<property name="username" value="system" />
<property name="password" value="123" />
</dataSource>
</environment>
Hello reading the documentation from the official site of MyBatis I could obtain the following information:
In case of using the multi-db feature you will need to inform the databaseIdProvider property in the following way:
In case of using the multi-db feature you will need to inform the databaseIdProvider property in the following way:
<bean id="vendorProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="SQL Server">sqlserver</prop>
<prop key="DB2">db2</prop>
<prop key="Oracle">oracle</prop>
<prop key="MySQL">mysql</prop>
</props>
</property>
</bean>
<bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider">
<property name="properties" ref="vendorProperties"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:sample/config/mappers/**/*.xml" />
<property name="databaseIdProvider" ref="databaseIdProvider"/>
</bean>
Hope it has been helpful.
Greetings.
NOTE Since 1.3.0, configuration property has been added. It can be specified a Configuration instance directly without MyBatis XML configuration file. For example:
mybatis.org/spring/es/factorybean.html

Fetching data from PostgreSQL database in Mule flow using JDBC transport

I have a Mule flow to fetch data from a table in a PostgreSQL database and convert the data into XML format and write to a file:
<mule ...>
<spring:bean id="Postgres-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.postgresql.Driver" />
<spring:property name="url"
value="jdbc:postgresql://host:port/schema?user=username&password=password" />
</spring:bean>
<jdbc:connector name="Postgres-jdbcConnector"
dataSource-ref="Postgres-jdbcDataSource" pollingFrequency="60000"
transactionPerMessage="false">
<jdbc:query key="read" value="SELECT * FROM tablename" />
</jdbc:connector>
<file:connector name="file_connector" fileAge="500"
streaming="false" pollingFrequency="60000" />
<flow name="Postgres-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="Postgres-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN" />
<property key="receiveMessageInTransaction" value="true" />
</jdbc:inbound-endpoint>
<custom-transformer name="Postgres-transformer"
class="com.example.transformer.DbToXmlTransformer" ignoreBadInput="false"
encoding="UTF-8" />
<file:outbound-endpoint connector-ref="file_connector"
path="/home/path" outputPattern="file.xml" responseTimeout="10000"
encoding="UTF-8" />
</flow>
</mule>
When I run this flow, the flow does not fetch data from DB and write to file. It does not throw any errors or exceptions either. But when I run the same flow for MySQL or SQLServer database, changing driverName and url properties accordingly, the flow works fine.
Any idea why the Postgres database does not work? Probably it requires different DataSource class?
There is also a Postgre data source for mule and you can use it instead of spring beans :
<jdbc:postgresql-data-source name="PostgreSQL_Data_Source" user="your user name" password="your pwd" url="jdbc:postgresql://localhost:5432/TestDB" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
Anyways... , with your existing config you can just check by keeping the JDBC inbound endpoint in a poll component and place a logger before File outbound to check the payload value.. If it gets payload value in logger ..that means it is fetching the value ..Let me know if it works ... you can try the following :-
<mule ...>
<spring:bean id="Postgres-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.postgresql.Driver" />
<spring:property name="url"
value="jdbc:postgresql://host:port/schema?user=username&password=password" />
</spring:bean>
<jdbc:connector name="Postgres-jdbcConnector"
dataSource-ref="Postgres-jdbcDataSource" pollingFrequency="60000"
transactionPerMessage="false">
<jdbc:query key="read" value="SELECT * FROM tablename" />
</jdbc:connector>
<file:connector name="file_connector" fileAge="500"
streaming="false" pollingFrequency="60000" />
<flow name="Postgres-flow">
<poll frequency="1000" doc:name="Poll">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="Postgres-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN" />
<property key="receiveMessageInTransaction" value="true" />
</jdbc:inbound-endpoint>
</poll>
<!-- You can also use object to xml transformer if you are not using any custom transformer -->
<!--<mulexml:object-to-xml-transformer doc:name="Object to XML"/> -->
<custom-transformer name="Postgres-transformer"
class="com.example.transformer.DbToXmlTransformer" ignoreBadInput="false"
encoding="UTF-8" />
<logger message="Payload :- #[message.payload]" level="INFO" doc:name="Logger"/>
<file:outbound-endpoint connector-ref="file_connector"
path="/home/path" outputPattern="file.xml" responseTimeout="10000"
encoding="UTF-8" />
</flow>
</mule>
For more find the reference here for Postgre Database with Mule :- http://www.dotnetfunda.com/articles/show/2068/using-mule-studio-to-read-data-from-postgresqlinbound-and-write-it-to

Read operation exception MongoDB in EC2, but local is ok

My web app and mongo built in different ec2.
I run web app in localhost and connect mongo in ec2.
It's OK.
but I deploy web app in ec2.
It have exception
com.mongodb.MongoException$Network: Read operation to server /172.XX.XX.XX:27017 failed on database
com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:253)
com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
com.mongodb.DBCursor._check(DBCursor.java:368)
com.mongodb.DBCursor._hasNext(DBCursor.java:459)
com.mongodb.DBCursor.hasNext(DBCursor.java:484)
com.google.code.morphia.query.MorphiaIterator.hasNext(MorphiaIterator.java:43)
com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:286)
my monogo congig
<bean id="mongoOptions" class="com.mongodb.MongoOptions">
<property name="autoConnectRetry" value="false" />
<property name="maxAutoConnectRetryTime" value="0" />
<property name="connectionsPerHost" value="10" />
<property name="connectTimeout" value="10000" />
<property name="cursorFinalizerEnabled" value="true" />
<property name="maxWaitTime" value="120000" />
<property name="threadsAllowedToBlockForConnectionMultiplier" value="5" />
<property name="socketTimeout" value="0" />
<property name="socketKeepAlive" value="false" />
<property name="safe" value="true" />
<property name="w" value="0" />
<property name="wtimeout" value="0" />
<property name="fsync" value="false" />
<property name="j" value="false" />
</bean>
Set the network security in the EC2 configuration to allow MongoDb traffic through to your DB box, the default is 27017.
In case anyone comes by (because I did) I was stuck on this same problem of mongodb connecting on local but not on my ec2 server.. for hours.. here is the solution and it's very simple.
When you created the MongoDB cluster, you added your computer's IP address to the white list. You need to grab EC2 Instance's 'IPv4 Public IP' and add that to to the white list as well.

JBoss ESB XML MEP Behviour

I am using JBoss AS 5.1.0 and Jboss ESB 4.10
I am trying to Invoke a Service which has a single action. I have Set MEP = oneWay for the Service.
When I Invoke the Service Using the Below Method I do not get a reply but an Exception.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverSync(esbMessage, 10000);
WHen I change mep=RequestResponse : I am able to get the Reply
As per my understanding ESB Message has a ReplyTo field (Since I am invkoing a Sync Request) the Message should be returned back by the last Action which is not happening in my case. Please find below the ESB XML:
<?xml version="1.0"?>
<jbossesb parameterReloadSecs="5"
xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
<providers>
<jms-provider connection-factory="ConnectionFactory" name="JBossMQ">
<jms-bus busid="chapter3GwChannel">
<jms-message-filter dest-name="queue/chapter3_Request_gw" dest-type="QUEUE"/>
</jms-bus>
<jms-bus busid="chapter3EsbChannel">
<jms-message-filter dest-name="queue/chapter3_Request_esb" dest-type="QUEUE"/>
</jms-bus>
</jms-provider>
</providers>
<services>
<service category="Chapter3Sample"
description="A template for Chapter3" name="Chapter3Service">
<listeners>
<jms-listener busidref="chapter3GwChannel" is-gateway="true" name="Chapter3GwListener"/>
<jms-listener busidref="chapter3EsbChannel" name="Chapter3Listener"/>
</listeners>
<actions mep="OneWay">
<action class="org.jboss.soa.esb.samples.chapter3.MyAction"
name="BodyPrinter">
<property name="process" value="displayMessage"/>
<property name="symbol" value="*"/>
<property name="count" value="50"/>
<property name="propertyName">
<hierarchicalProperty attr="value">
<inner name="myName" random="randomValue"/>
</hierarchicalProperty>
</property>
<property name="exceptionMethod" value="processException"/>
<property name="okMethod" value="processSuccess"/>
</action>
</actions>
</service>
</services>
</jbossesb>
When your are invoking call as synchronus.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverSync(esbMessage, 10000).
set mep=RequestResponse.
when your are invoking call asynchronus.
new ServiceInvoker("Chapter3Sample", "Chapter3Service").deliverASync(esbMessage, 10000).
set mep=oneWay .

Deploying on remote JBoss 6.x with Cargo

I'm trying to setup an Ant Target to perform a remote deploy on a JBoss 6.x server, using Cargo.
Here is my target description:
<target name="deploy" depends="install-cargo,make-war">
<input message="Enter username for deployment..."
addproperty="deploy.username" />
<input message="Enter password for ${deploy.username}..."
addproperty="deploy.password" >
<handler type="secure" />
</input>
<cargo containerId="jboss6x" action="redeploy" type="remote">
<configuration type="runtime">
<property name="cargo.hostname" value="${deploy.host}" />
<property name="cargo.servlet.port" value="${deploy.host}" />
<property name="cargo.remote.username" value="${deploy.username}" />
<property name="cargo.remote.password" value="${deploy.password}" />
<deployable type="war" file="${dist.dir}/${ant.project.name}.war">
<property name="context" value="${ant.project.name}" />
</deployable>
</configuration>
</cargo>
Every jar inside [jboss.home]/client and [jboss.home]/lib is inside cargo.tasks classpath but when i try to execute the Target I get this error:
javax.security.auth.login.LoginException: impossibile trovare la classe LoginModule: org.jboss.security.ClientLoginModule
That is Java cannot find class org.jboss.security.ClientLoginModule (by the way: this class is located inside jbosssx.jar in [jboss.home]/lib).
Am I missing some jar? Do I need to configure something for jaas? Thanks for your help.