Skip to content

Commit 902303b

Browse files
committed
AbstractMessageListenerContainer calls "Session.recover()" in case of rollback attempt on non-transacted Session
Issue: SPR-12015 (cherry picked from commit c082220)
1 parent b56c8f4 commit 902303b

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

spring-jms/src/main/java/org/springframework/jms/listener/AbstractMessageListenerContainer.java

Lines changed: 19 additions & 9 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-2014 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.
@@ -588,9 +588,14 @@ else if (message != null && isClientAcknowledge(session)) {
588588
* @throws javax.jms.JMSException in case of a rollback error
589589
*/
590590
protected void rollbackIfNecessary(Session session) throws JMSException {
591-
if (session.getTransacted() && isSessionLocallyTransacted(session)) {
592-
// Transacted session created by this container -> rollback.
593-
JmsUtils.rollbackIfNecessary(session);
591+
if (session.getTransacted()) {
592+
if (isSessionLocallyTransacted(session)) {
593+
// Transacted session created by this container -> rollback.
594+
JmsUtils.rollbackIfNecessary(session);
595+
}
596+
}
597+
else {
598+
session.recover();
594599
}
595600
}
596601

@@ -602,12 +607,17 @@ protected void rollbackIfNecessary(Session session) throws JMSException {
602607
*/
603608
protected void rollbackOnExceptionIfNecessary(Session session, Throwable ex) throws JMSException {
604609
try {
605-
if (session.getTransacted() && isSessionLocallyTransacted(session)) {
606-
// Transacted session created by this container -> rollback.
607-
if (logger.isDebugEnabled()) {
608-
logger.debug("Initiating transaction rollback on application exception", ex);
610+
if (session.getTransacted()) {
611+
if (isSessionLocallyTransacted(session)) {
612+
// Transacted session created by this container -> rollback.
613+
if (logger.isDebugEnabled()) {
614+
logger.debug("Initiating transaction rollback on application exception", ex);
615+
}
616+
JmsUtils.rollbackIfNecessary(session);
609617
}
610-
JmsUtils.rollbackIfNecessary(session);
618+
}
619+
else {
620+
session.recover();
611621
}
612622
}
613623
catch (IllegalStateException ex2) {

0 commit comments

Comments
 (0)