Search code examples
springjbossapache-cameloracle-aq

jboss eap error org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to oracle.jdbc.internal.OracleConnection


I'm developing camel route to connect to Oracle AQ on Jboss EAP Fuse. I managed to do it using the connection factory as follows:

<bean class="org.apache.camel.component.jms.JmsComponent" id="oracleAQQueue">
    <property name="connectionFactory" ref="oracleQueueAQCredentials"/>
</bean>
<bean
    class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"
    id="oracleQueueAQCredentials" primary="true">
    <property name="targetConnectionFactory">
        <ref bean="connectionFactoryOracleAQAQQueue"/>
    </property>
</bean>
<bean class="oracle.jms.AQjmsFactory"
    factory-method="getQueueConnectionFactory" id="connectionFactoryOracleAQAQQueue">
    <constructor-arg index="0">            
        <value>jdbc:oracle:thin:xx/xx@localhost:1521/orclpdb</value>            
    </constructor-arg>
    <constructor-arg index="1" type="java.util.Properties">
        <value/>
    </constructor-arg>
</bean>

What I'm trying to do next is to use the JNDI Datasource on the Jboss EAP instead of the connection string. So I configured the datasource on jboss

<datasource jta="true" jndi-name="java:/AQ_DB" pool-name="AQ_DB_DataSource" enabled="true" use-java-context="true">
    <connection-url>jdbc:oracle:thin:@localhost:1521/orclpdb</connection-url>
    <driver>oracle</driver>
    <security>
        <user-name>xx</user-name>
        <password>xx</password>
    </security>
</datasource>

<driver name="oracle" module="com.oracle">
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>                     
</driver>

then I change my code to use the connection as follows:

<jee:jndi-lookup id="jndiConnectionFactory" jndi-name="java:/AQ_DB" />
        
    <bean class="oracle.jms.AQjmsFactory"
        factory-method="getQueueConnectionFactory" id="connectionFactoryOracleAQAQQueue">
        <constructor-arg index="0">
            <ref bean="jndiConnectionFactory"/> 
        </constructor-arg>        
    </bean>

however, upon starting the Jboss EAP, the following error shown.

Cause: Error creating the db_connection; nested exception is java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to oracle.jdbc.internal.OracleConnection: oracle.jms.AQjmsException: Error creating the db_connection
        at oracle.jms.AQjmsDBConnMgr.getConnection(AQjmsDBConnMgr.java:625)
        at oracle.jms.AQjmsDBConnMgr.<init>(AQjmsDBConnMgr.java:399)
        at oracle.jms.AQjmsConnection.<init>(AQjmsConnection.java:259)
        at oracle.jms.AQjmsConnectionFactory.createConnection(AQjmsConnectionFactory.java:529)
        at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.doCreateConnection(UserCredentialsConnectionFactoryAdapter.java:181)
        at org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter.createConnection(UserCredentialsConnectionFactoryAdapter.java:152)
        at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
        at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:411)
        at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:396)
        at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:927)
        at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:901)
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1079)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to oracle.jdbc.internal.OracleConnection
        at oracle.jms.AQjmsGeneralDBConnection.getProviderKey(AQjmsGeneralDBConnection.java:99)
        at oracle.jms.AQjmsGeneralDBConnection.<init>(AQjmsGeneralDBConnection.java:68)
        at oracle.jms.AQjmsDBConnMgr.getConnection(AQjmsDBConnMgr.java:566)

Anyone can help?


Solution

  • You need to unwrap your connection as it comes from an ironjacamar pool.