我正在尝试使用Oracle AQ支持XA事务,因为我有其他数据源,如Active MQ和DB参与事务。当我试图发布到oracle aq queue1。从数据源获取XAconnection时失败并出现NullPointerException。
我使用的是oracle ojdbc6,11.2版本的aqapi.jar 我的骆驼蓝图与我的豆类定义的片段在下面给出
<reference id="transactionManager" interface="javax.transaction.TransactionManager" />
<reference id="recoverableTxManager" interface="org.apache.geronimo.transaction.manager.RecoverableTransactionManager" availability="mandatory" />
<reference id="platformTxManager" interface="org.springframework.transaction.PlatformTransactionManager" availability="mandatory"/>
<bean id="oracleXaDataSource" class="oracle.jdbc.xa.client.OracleXADataSource" destroy-method="close">
<property name="user" value="dbuser" />
<property name="password" value="dbpassword" />
<property name="URL" value="dburl" />
</bean>
<bean id="connectionFactoryOracleAQ" class="oracle.jms.AQjmsFactory" factory-method="getXAQueueConnectionFactory">
<argument value="oracleXaDataSource" />
</bean>
<bean id="oracleaqJcaPooledConnectionFactory" class="org.apache.activemq.jms.pool.JcaPooledConnectionFactory" init-method="start"
destroy-method="stop">
<property name="idleTimeout" value="0"/>
<property name="name" value="aq.default"/>
<property name="maxConnections" value="1"/>
<property name="connectionFactory" ref="connectionFactoryOracleAQ"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="resourceManager-AQ" class="org.apache.activemq.jms.pool.GenericResourceManager"
init-method="recoverResource">
<property name="connectionFactory" ref="connectionFactoryOracleAQ"/>
<property name="transactionManager" ref="recoverableTxManager"/>
<property name="resourceName" value="aq.default"/>
<property name="userName" value="${primary.datasource.user}"/>
<property name="password" value="${primary.datasource.password}"/>
</bean>
<bean id="oracleaqJmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="oracleaqJcaPooledConnectionFactory"/>
<property name="transactionManager" ref="platformTxManager"/>
<property name="transacted" value="false"/>
</bean>
<bean id="oracleaq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="oracleaqJmsConfig" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="route1">
<from uri="vm:route1" />
<log message="Message to the oracle Aq:queue1-- ${body}" />
<to uri="oracleaq:queue:queue1?jmsMessageType=Text" pattern="InOnly"/>
</route>
</camelContext>
您能否帮我确定问题所在。例外是l
2017-02-27 12:14:11,613 | WARN | loyer-4-thread-1 | PooledConnectionFactory | 9037 - org.apache.activemq.activemq-osgi - 5.11.0.redhat-621084 | Create pooled connection during start failed. This exception will be ignored.
javax.jms.JMSException: Error while attempting to add new Connection to the pool
at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:267)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:226)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:205)
at org.apache.activemq.jms.pool.PooledConnectionFactory.start(PooledConnectionFactory.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_25]
at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_25]
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:956)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:824)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.4]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:247)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[15:org.apache.aries.blueprint.core:1.4.4]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[9:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[9:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[9:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[9:org.apache.aries.util:1.1.0]
at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[9:org.apache.aries.util:1.1.0]
at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)[org.apache.felix.framework-4.4.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:963)[org.apache.felix.framework-4.4.1.jar:]
at io.fabric8.agent.service.Agent$BaseDeployCallback.startBundle(Agent.java:482)[86:io.fabric8.fabric-agent:1.2.0.redhat-621084]
at io.fabric8.agent.service.Deployer$3.call(Deployer.java:935)[86:io.fabric8.fabric-agent:1.2.0.redhat-621084]
at io.fabric8.agent.service.Deployer$3.call(Deployer.java:930)[86:io.fabric8.fabric-agent:1.2.0.redhat-621084]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_25]
at java.lang.Thread.run(Thread.java:724)[:1.7.0_25]
Caused by: oracle.jms.AQjmsException: Error creating the db_connection
at oracle.jms.AQjmsDBConnMgr.getConnection(AQjmsDBConnMgr.java:625)
at oracle.jms.AQjmsDBConnMgr.<init>(AQjmsDBConnMgr.java:458)
at oracle.jms.AQjmsXAConnection.<init>(AQjmsXAConnection.java:129)
at oracle.jms.AQjmsXAConnectionFactory.createXAConnection(AQjmsXAConnectionFactory.java:212)
at org.apache.activemq.jms.pool.XaPooledConnectionFactory.createConnection(XaPooledConnectionFactory.java:79)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:108)
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:88)
at org.apache.commons.pool.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1748)
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:222)
... 43 more
Caused by: java.lang.NullPointerException
at oracle.jms.AQjmsGeneralDBConnection.getProviderKey(AQjmsGeneralDBConnection.java:99)
at oracle.jms.AQjmsGeneralDBConnection.<init>(AQjmsGeneralDBConnection.java:77)
at oracle.jms.AQjmsDBConnMgr.getConnection(AQjmsDBConnMgr.java:541)
... 51 more
答案 0 :(得分:0)
我想我得到了问题所在。我从oracle 11.2客户端使用的aqapi.jar有bug。类AqjmsGeneralDBConnection没有为QAConnection初始化m_dbConn对象(使用XAConnection作为参数的构造函数)并尝试访问m_dbConn对象上的getURL(),该对象为null。我尝试使用10.2.0版本的aqapi13.jar,它可以正常工作
AQjmsGeneralDBConnection(AQjmsDBConnMgr paramAQjmsDBConnMgr, Connection paramConnection, boolean paramBoolean1, boolean paramBoolean2)
throws JMSException
{
this.m_connMgr = paramAQjmsDBConnMgr;
this.m_dbConn = paramConnection;
this.m_isExternal = paramBoolean1;
this.m_force = paramBoolean2;
this.providerKey = getProviderKey();
}
AQjmsGeneralDBConnection(AQjmsDBConnMgr paramAQjmsDBConnMgr, XAConnection paramXAConnection, boolean paramBoolean1, boolean paramBoolean2)
throws JMSException
{
this.m_connMgr = paramAQjmsDBConnMgr;
this.m_xaConn = paramXAConnection;
this.m_isExternal = paramBoolean1;
this.m_force = paramBoolean2;
this.providerKey = getProviderKey();
}
private String getProviderKey()
throws JMSException
{
try
{
OracleConnection localOracleConnection = (OracleConnection)this.m_dbConn;
**String str1 = localOracleConnection.getURL();**
int i = str1.indexOf('@');
String str2;
if (i < 0)
{
if ((!"jdbc:oracle:kprb:".equals(str1)) && (!"jdbc:default:connection:".equals(str1))) {
AQjmsError.throwEx(112);
}
str2 = "jdbc:oracle:kprb:";
}
else
{
str2 = str1.substring(i);
}
return str2.toUpperCase();
}
catch (SQLException localSQLException)
{
throw new AQjmsException(localSQLException);
}
}