Skip to content

Commit 26e697b

Browse files
committed
Silently swallow IllegalStateException on commit if the JMS transaction is based on a JDBC transaction
This fine-tuned change restores the original Spring 3.0 behavior for Oracle AQ, and also allows for other ConnectionFactory types to comply with the "getDataSource()" pattern. Issue: SPR-10829 (cherry picked from commit 11d20e3)
1 parent ef66708 commit 26e697b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.jms.connection;
1818

19+
import java.lang.reflect.Method;
1920
import java.util.HashMap;
2021
import java.util.LinkedList;
2122
import java.util.List;
@@ -30,8 +31,10 @@
3031
import org.apache.commons.logging.LogFactory;
3132

3233
import org.springframework.transaction.support.ResourceHolderSupport;
34+
import org.springframework.transaction.support.TransactionSynchronizationManager;
3335
import org.springframework.util.Assert;
3436
import org.springframework.util.CollectionUtils;
37+
import org.springframework.util.ReflectionUtils;
3538

3639
/**
3740
* JMS resource holder, wrapping a JMS Connection and a JMS Session.
@@ -183,7 +186,26 @@ public void commitAll() throws JMSException {
183186
catch (TransactionInProgressException ex) {
184187
// Ignore -> can only happen in case of a JTA transaction.
185188
}
186-
// Let IllegalStateException through: It might point out an unexpectedly closed session.
189+
catch (javax.jms.IllegalStateException ex) {
190+
if (this.connectionFactory != null) {
191+
try {
192+
Method getDataSourceMethod = this.connectionFactory.getClass().getMethod("getDataSource");
193+
Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory);
194+
if (ds != null && TransactionSynchronizationManager.hasResource(ds)) {
195+
// IllegalStateException from sharing the underlying JDBC Connection
196+
// which typically gets committed first, e.g. with Oracle AQ --> ignore
197+
return;
198+
}
199+
}
200+
catch (Throwable ex2) {
201+
if (logger.isDebugEnabled()) {
202+
logger.debug("No working getDataSource method found on ConnectionFactory: " + ex2);
203+
}
204+
// No working getDataSource method - cannot perform DataSource transaction check
205+
}
206+
}
207+
throw ex;
208+
}
187209
}
188210
}
189211

0 commit comments

Comments
 (0)