diff --git a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNarayanaConnectionFactory.java b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNarayanaConnectionFactory.java index ddd913e0..ba3c9a9b 100644 --- a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNarayanaConnectionFactory.java +++ b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNarayanaConnectionFactory.java @@ -20,7 +20,9 @@ import jakarta.jms.Connection; +import org.messaginghub.pooled.jms.JmsPoolConnection; import org.messaginghub.pooled.jms.JmsPoolXAConnectionFactory; +import org.messaginghub.pooled.jms.JmsPoolXAJMSContext; public class JmsPoolNarayanaConnectionFactory extends JmsPoolXAConnectionFactory { @@ -41,4 +43,9 @@ public void setName(String name) { protected PooledNarayanaConnection createPooledConnection(Connection connection) { return new PooledNarayanaConnection(connection, getTransactionManager(), getName()); } + + @Override + protected JmsPoolXAJMSContext newPooledConnectionContext(JmsPoolConnection connection, int sessionMode) { + return new JmsPoolNaryanaJmsContext(connection, sessionMode, getName()); + } } diff --git a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNaryanaJmsContext.java b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNaryanaJmsContext.java new file mode 100644 index 00000000..cb0a5392 --- /dev/null +++ b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/JmsPoolNaryanaJmsContext.java @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Red Hat, Inc, and individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dev.snowdrop.boot.narayana.core.jms.pool; + +import javax.transaction.xa.XAResource; + +import org.messaginghub.pooled.jms.JmsPoolConnection; +import org.messaginghub.pooled.jms.JmsPoolXAJMSContext; + +public class JmsPoolNaryanaJmsContext extends JmsPoolXAJMSContext { + + private final String name; + + public JmsPoolNaryanaJmsContext(JmsPoolConnection connection, int sessionMode, String name) { + super(connection, sessionMode); + this.name = name; + } + + @Override + public XAResource getXAResource() { + XAResource xares = super.getXAResource(); + if (this.name != null) { + xares = new NamedXAResource(xares, this.name); + } + return xares; + } +} diff --git a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/PooledNarayanaConnection.java b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/PooledNarayanaConnection.java index ff34de95..b85e17e7 100644 --- a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/PooledNarayanaConnection.java +++ b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/jms/pool/PooledNarayanaConnection.java @@ -20,7 +20,6 @@ import jakarta.jms.Connection; import jakarta.jms.JMSException; -import jakarta.jms.XASession; import jakarta.transaction.TransactionManager; import org.messaginghub.pooled.jms.JmsPoolSession; @@ -37,7 +36,7 @@ public PooledNarayanaConnection(Connection connection, TransactionManager transa @Override protected XAResource createXaResource(JmsPoolSession session) throws JMSException { - XAResource xares = ((XASession) session.getInternalSession()).getXAResource(); + XAResource xares = super.createXaResource(session); if (this.name != null) { xares = new NamedXAResource(xares, this.name); }