This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new d76e8cb78af9 CAMEL-27051: camel-sjms - pollEnrich and ConsumerTemplate 
read the message before the JMS session is closed (#30206)
d76e8cb78af9 is described below

commit d76e8cb78af9c9af026470db670ac2c35f5053af
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Nov 16 16:09:56 2026 +0100

    CAMEL-27051: camel-sjms - pollEnrich and ConsumerTemplate read the message 
before the JMS session is closed (#30206)
    
    The camel-sjms counterpart of CAMEL-27014 (#30164), as suggested in the 
review of that PR.
    
    - `SjmsTemplate.receive` committed the session (or acknowledged the 
message) and closed the consumer, the session and the connection before it 
returned the message, and `SjmsMessage` reads the body lazily. So `pollEnrich` 
and a `ConsumerTemplate` read the body after the connection was closed: the 
body of an ActiveMQ Artemis large message failed with `AMQ219023`, and with 
`transacted=true` or `CLIENT_ACKNOWLEDGE` a message whose body could not be 
read (such as an `ObjectMessage` while  [...]
    - New `SjmsTemplate.receive(..., Function<Message, T>)` applies the 
function to the message before the commit or acknowledge, and before the close. 
If the function fails, a transacted session is rolled back and a client 
acknowledge session is recovered (a failure of that is added as suppressed), as 
in camel-jms. The existing `receive` delegates to it with the identity function.
    - `SjmsPollingConsumer` creates the exchange and reads the body and the 
headers in that function. camel-sjms2 uses the same polling consumer.
    - Docs: "Message Content" section of the sjms page (and its catalog copy), 
including that the body is not read at receive time with `mapJmsMessage=false` 
and for a `StreamMessage`.
    
    _Claude Code on behalf of Federico Mariani_
    
    Co-Authored-By: Claude <[email protected]>
---
 .../apache/camel/catalog/docs/sjms-component.adoc  |   8 +
 .../camel-sjms/src/main/docs/sjms-component.adoc   |   8 +
 .../camel/component/sjms/SjmsPollingConsumer.java  |  21 +-
 .../apache/camel/component/sjms/SjmsTemplate.java  |  55 ++++-
 .../SjmsPollingConsumerLargeMessageTest.java       | 227 +++++++++++++++++++++
 .../producer/SjmsObjectMessageEnabledTest.java     |  12 +-
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |   9 +
 7 files changed, 324 insertions(+), 16 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sjms-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sjms-component.adoc
index 318255a79d83..5ae73b0dc59f 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sjms-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/sjms-component.adoc
@@ -313,6 +313,14 @@ With `jmsMessageType=Stream` the body is converted to an 
`InputStream`, and its
 A received `StreamMessage` is mapped to an `InputStream` over its bytes, as in 
the JMS component.
 With `mapJmsMessage=false` the body is always the received 
`jakarta.jms.Message`.
 
+When `pollEnrich` or a `ConsumerTemplate` receives a message from an SJMS 
endpoint, Camel reads the body and the
+headers of the message before it commits the session (or acknowledges the 
message) and closes the JMS consumer, session
+and connection, as a JMS client may not read the message after that (the 
ActiveMQ Artemis client streams the body of a
+large message through the consumer). If the body cannot be read, the receive 
fails, and the message is rolled back with
+`transacted=true`, or recovered with `CLIENT_ACKNOWLEDGE`, so that it is 
delivered again. The body is not read at
+receive time with `mapJmsMessage=false` (the body is the `jakarta.jms.Message` 
itself), and for a `StreamMessage` (the
+body is an `InputStream` that reads the message when it is used).
+
 === Clustering
 
 When using _InOut_ with SJMS in a clustered environment, you must either
diff --git a/components/camel-sjms/src/main/docs/sjms-component.adoc 
b/components/camel-sjms/src/main/docs/sjms-component.adoc
index 318255a79d83..5ae73b0dc59f 100644
--- a/components/camel-sjms/src/main/docs/sjms-component.adoc
+++ b/components/camel-sjms/src/main/docs/sjms-component.adoc
@@ -313,6 +313,14 @@ With `jmsMessageType=Stream` the body is converted to an 
`InputStream`, and its
 A received `StreamMessage` is mapped to an `InputStream` over its bytes, as in 
the JMS component.
 With `mapJmsMessage=false` the body is always the received 
`jakarta.jms.Message`.
 
+When `pollEnrich` or a `ConsumerTemplate` receives a message from an SJMS 
endpoint, Camel reads the body and the
+headers of the message before it commits the session (or acknowledges the 
message) and closes the JMS consumer, session
+and connection, as a JMS client may not read the message after that (the 
ActiveMQ Artemis client streams the body of a
+large message through the consumer). If the body cannot be read, the receive 
fails, and the message is rolled back with
+`transacted=true`, or recovered with `CLIENT_ACKNOWLEDGE`, so that it is 
delivered again. The body is not read at
+receive time with `mapJmsMessage=false` (the body is the `jakarta.jms.Message` 
itself), and for a `StreamMessage` (the
+body is an `InputStream` that reads the message when it is used).
+
 === Clustering
 
 When using _InOut_ with SJMS in a clustered environment, you must either
diff --git 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsPollingConsumer.java
 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsPollingConsumer.java
index 736be3f81b23..796dc0a6a234 100644
--- 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsPollingConsumer.java
+++ 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsPollingConsumer.java
@@ -53,15 +53,24 @@ public class SjmsPollingConsumer extends 
PollingConsumerSupport {
     @Override
     public Exchange receive(long timeout) {
         try {
-            Message message = 
template.receive(jmsEndpoint.getDestinationName(), 
jmsEndpoint.getMessageSelector(),
-                    jmsEndpoint.isTopic(), timeout);
-            if (message != null) {
-                return getEndpoint().createExchange(message, null);
-            }
+            // read the message before the JMS consumer, session and 
connection are closed
+            return template.receive(jmsEndpoint.getDestinationName(), 
jmsEndpoint.getMessageSelector(),
+                    jmsEndpoint.isTopic(), timeout, this::createExchange);
         } catch (Exception e) {
             throw new RuntimeCamelException(e);
         }
-        return null;
+    }
+
+    /**
+     * Creates the exchange for the received message, and reads the body and 
the headers of the message. It is called
+     * before the JMS consumer, session and connection are closed, as a JMS 
client may not read the message after that:
+     * the ActiveMQ Artemis client streams the body of a large message through 
the consumer.
+     */
+    protected Exchange createExchange(Message message) {
+        Exchange exchange = getEndpoint().createExchange(message, null);
+        exchange.getIn().getBody();
+        exchange.getIn().getHeaders();
+        return exchange;
     }
 
     @Override
diff --git 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsTemplate.java
 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsTemplate.java
index 4d85e9838887..092cd3a0da04 100644
--- 
a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsTemplate.java
+++ 
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsTemplate.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.sjms;
 
+import java.util.function.Function;
+
 import jakarta.jms.Connection;
 import jakarta.jms.ConnectionFactory;
 import jakarta.jms.Destination;
@@ -38,6 +40,7 @@ import static 
org.apache.camel.component.sjms.SjmsHelper.closeProducer;
 import static org.apache.camel.component.sjms.SjmsHelper.closeSession;
 import static org.apache.camel.component.sjms.SjmsHelper.commitIfNeeded;
 import static 
org.apache.camel.component.sjms.SjmsHelper.isTransactionOrClientAcknowledgeMode;
+import static org.apache.camel.component.sjms.SjmsHelper.rollbackIfNeeded;
 
 public class SjmsTemplate {
 
@@ -239,6 +242,29 @@ public class SjmsTemplate {
     }
 
     public Message receive(String destinationName, String messageSelector, 
boolean isTopic, long timeout) throws Exception {
+        return receive(destinationName, messageSelector, isTopic, timeout, 
Function.identity());
+    }
+
+    /**
+     * Receives a message, and applies the function to it before the message 
is acknowledged (or the session committed),
+     * and before the consumer, the session and the connection are closed.
+     * <p/>
+     * {@link #receive(String, String, boolean, long)} returns the message 
after they are closed, when a JMS client may
+     * no longer read it: the ActiveMQ Artemis client streams the body of a 
large message through the consumer. If the
+     * function fails, the message is not acknowledged: a transacted session 
is rolled back, and a client acknowledge
+     * session is recovered, so the message is delivered again.
+     *
+     * @param  destinationName the name of the destination
+     * @param  messageSelector the message selector, or <tt>null</tt> for none
+     * @param  isTopic         whether the destination is a topic
+     * @param  timeout         the receive timeout in millis, 0 to wait 
without timeout, or a negative value to not wait
+     * @param  function        the function to apply to the received message
+     * @return                 the result of the function, or <tt>null</tt> if 
no message was received
+     */
+    @SuppressWarnings("unchecked")
+    public <T> T receive(
+            String destinationName, String messageSelector, boolean isTopic, 
long timeout, Function<Message, T> function)
+            throws Exception {
         Object obj = execute(sc -> {
             Destination dest = 
destinationCreationStrategy.createDestination(sc, destinationName, isTopic);
             MessageConsumer consumer;
@@ -249,8 +275,8 @@ public class SjmsTemplate {
                 consumer = sc.createConsumer(dest);
             }
 
-            Message message = null;
             try {
+                Message message;
                 if (timeout < 0) {
                     message = consumer.receiveNoWait();
                 } else if (timeout == 0) {
@@ -258,14 +284,35 @@ public class SjmsTemplate {
                 } else {
                     message = consumer.receive(timeout);
                 }
-            } finally {
+                T answer;
+                try {
+                    answer = message != null ? function.apply(message) : null;
+                } catch (RuntimeException | Error e) {
+                    rollbackOnException(sc, e);
+                    throw e;
+                }
                 // success then commit if we need to
                 commitIfNeeded(sc, message);
+                return answer;
+            } finally {
                 closeConsumer(consumer);
             }
-            return message;
         }, true);
-        return (Message) obj;
+        return (T) obj;
+    }
+
+    /**
+     * Rolls back a transacted session, or recovers a client acknowledge 
session, when the received message could not be
+     * read. A session of a pooled connection factory is not closed after the 
receive, so the message would otherwise
+     * stay unacknowledged on it, and the next acknowledge on that session 
would acknowledge it too. A failure of the
+     * rollback is added to the cause as a suppressed exception.
+     */
+    private static void rollbackOnException(Session session, Throwable cause) {
+        try {
+            rollbackIfNeeded(session);
+        } catch (JMSException | RuntimeException e) {
+            cause.addSuppressed(e);
+        }
     }
 
     public Connection createConnection() throws Exception {
diff --git 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/consumer/SjmsPollingConsumerLargeMessageTest.java
 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/consumer/SjmsPollingConsumerLargeMessageTest.java
new file mode 100644
index 000000000000..a841ce623fda
--- /dev/null
+++ 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/consumer/SjmsPollingConsumerLargeMessageTest.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.camel.component.sjms.consumer;
+
+import java.util.Arrays;
+
+import jakarta.jms.Connection;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Session;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.sjms.SjmsComponent;
+import org.apache.camel.component.sjms.support.JmsTestSupport;
+import org.junit.jupiter.api.Test;
+import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The polling consumer (pollEnrich and ConsumerTemplate) reads the message 
before the JMS consumer, session and
+ * connection are closed. The Artemis client streams the body of a large 
message through the consumer, so the body
+ * cannot be read after the consumer is closed.
+ */
+public class SjmsPollingConsumerLargeMessageTest extends JmsTestSupport {
+
+    private static final String QUEUE = "SjmsPollingConsumerLargeMessageTest";
+    private static final byte[] LARGE = payload(200_000);
+    private static final byte[] SMALL = payload(512);
+
+    @Override
+    protected String getBrokerUri() {
+        // every message above 1 KB is an Artemis large message
+        return super.getBrokerUri() + "?minLargeMessageSize=1024";
+    }
+
+    @Test
+    void consumerTemplateReceivesLargeBytesMessage() {
+        template.sendBody("sjms:queue:" + QUEUE + ".receive", LARGE);
+
+        Exchange exchange = consumer.receive("sjms:queue:" + QUEUE + 
".receive", 5000);
+
+        assertNotNull(exchange);
+        assertArrayEquals(LARGE, exchange.getIn().getBody(byte[].class));
+    }
+
+    @Test
+    void consumerTemplateReceivesLargeBytesMessageWithSelector() {
+        String uri = "sjms:queue:" + QUEUE + ".selector";
+        template.sendBodyAndHeader(uri, "other", "kind", "other");
+        template.sendBodyAndHeader(uri, LARGE, "kind", "large");
+
+        assertArrayEquals(LARGE, consumer.receiveBody(uri + 
"?messageSelector=kind='large'", 5000, byte[].class));
+        assertEquals("other", consumer.receiveBody(uri + 
"?messageSelector=kind='other'", 5000, String.class));
+    }
+
+    @Test
+    void pollEnrichReceivesLargeBytesMessage() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:" + QUEUE + ".result");
+        mock.expectedMessageCount(1);
+        template.sendBody("sjms:queue:" + QUEUE + ".pollEnrich", LARGE);
+
+        template.sendBody("direct:" + QUEUE + ".pollEnrich", "trigger");
+
+        MockEndpoint.assertIsSatisfied(context);
+        assertArrayEquals(LARGE, 
mock.getReceivedExchanges().get(0).getIn().getBody(byte[].class));
+    }
+
+    @Test
+    void transactedConsumerTemplateCommitsTheReceive() {
+        String uri = "sjms:queue:" + QUEUE + ".transacted?transacted=true";
+        template.sendBody(uri, LARGE);
+
+        assertArrayEquals(LARGE, consumer.receiveBody(uri, 5000, 
byte[].class));
+        // the message is not delivered again
+        assertNull(consumer.receive(uri, 1000));
+    }
+
+    @Test
+    void clientAcknowledgeConsumerTemplateAcknowledgesTheMessage() {
+        String uri = "sjms:queue:" + QUEUE + 
".clientAck?acknowledgementMode=CLIENT_ACKNOWLEDGE";
+        template.sendBody(uri, LARGE);
+
+        assertArrayEquals(LARGE, consumer.receiveBody(uri, 5000, 
byte[].class));
+        // the message is not delivered again
+        assertNull(consumer.receive(uri, 1000));
+    }
+
+    @Test
+    void transactedConsumerTemplateRollsBackMessageWhoseBodyCannotBeRead() 
throws Exception {
+        String queue = QUEUE + ".unreadable";
+        sendObjectMessage(queue, "not allowed");
+
+        // objectMessageEnabled is false, so the body cannot be read: the 
receive fails and is rolled back
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                () -> consumer.receive("sjms:queue:" + queue + 
"?transacted=true", 5000));
+        assertObjectMessageDisabled(e);
+
+        Message message = receiveMessage(queue);
+        assertEquals("not allowed", assertInstanceOf(ObjectMessage.class, 
message).getObject());
+    }
+
+    @Test
+    void 
clientAcknowledgeConsumerTemplateRecoversMessageWhoseBodyCannotBeRead() throws 
Exception {
+        String queue = QUEUE + ".unreadableClientAck";
+        String options = "?acknowledgementMode=CLIENT_ACKNOWLEDGE";
+        // a pooled session (as with a pooled connection factory) is not 
closed after the receive, but goes back to
+        // the pool
+        JmsPoolConnectionFactory pooledConnectionFactory = new 
JmsPoolConnectionFactory();
+        pooledConnectionFactory.setConnectionFactory(connectionFactory);
+        pooledConnectionFactory.setMaxConnections(1);
+        try {
+            SjmsComponent pooled = new SjmsComponent();
+            pooled.setConnectionFactory(pooledConnectionFactory);
+            context.addComponent("pooledsjms", pooled);
+            sendObjectMessage(queue, "not allowed");
+
+            // objectMessageEnabled is false, so the body cannot be read: the 
receive fails and the session is recovered
+            RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                    () -> consumer.receive("pooledsjms:queue:" + queue + 
options, 5000));
+            assertObjectMessageDisabled(e);
+
+            // the next receive on the pooled session acknowledges its own 
message only
+            template.sendBody("sjms:queue:" + queue + ".next", "next");
+            assertEquals("next",
+                    consumer.receiveBody("pooledsjms:queue:" + queue + ".next" 
+ options, 5000, String.class));
+
+            Message message = receiveMessage(queue);
+            assertEquals("not allowed", assertInstanceOf(ObjectMessage.class, 
message).getObject());
+            assertTrue(message.getJMSRedelivered());
+        } finally {
+            pooledConnectionFactory.stop();
+        }
+    }
+
+    @Test
+    void consumerTemplateReceivesSmallBytesMessage() {
+        template.sendBody("sjms:queue:" + QUEUE + ".small", SMALL);
+
+        assertArrayEquals(SMALL, consumer.receiveBody("sjms:queue:" + QUEUE + 
".small", 5000, byte[].class));
+    }
+
+    @Test
+    void routeReceivesLargeBytesMessage() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:" + QUEUE + ".route");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("sjms:queue:" + QUEUE + ".route", LARGE);
+
+        MockEndpoint.assertIsSatisfied(context);
+        assertArrayEquals(LARGE, 
mock.getReceivedExchanges().get(0).getIn().getBody(byte[].class));
+    }
+
+    private void sendObjectMessage(String queue, String body) throws Exception 
{
+        try (Connection connection = connectionFactory.createConnection();
+             Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+             MessageProducer producer = 
session.createProducer(session.createQueue(queue))) {
+            producer.send(session.createObjectMessage(body));
+        }
+    }
+
+    private Message receiveMessage(String queue) throws Exception {
+        try (Connection connection = connectionFactory.createConnection();
+             Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
+             MessageConsumer messageConsumer = 
session.createConsumer(session.createQueue(queue))) {
+            connection.start();
+            Message message = messageConsumer.receive(5000);
+            assertNotNull(message, "the message is still on the queue");
+            // read the body while the session is open
+            ((ObjectMessage) message).getObject();
+            return message;
+        }
+    }
+
+    private static void assertObjectMessageDisabled(RuntimeCamelException e) {
+        IllegalStateException cause = 
assertInstanceOf(IllegalStateException.class, e.getCause());
+        assertTrue(cause.getMessage().contains("objectMessageEnabled=true"), 
cause.getMessage());
+    }
+
+    private static byte[] payload(int size) {
+        byte[] answer = new byte[size];
+        Arrays.fill(answer, (byte) 'a');
+        for (int i = 0; i < size; i += 1000) {
+            answer[i] = (byte) ('0' + (i / 1000) % 10);
+        }
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("sjms:queue:" + QUEUE + ".route").to("mock:" + QUEUE + 
".route");
+
+                from("direct:" + QUEUE + ".pollEnrich")
+                        .pollEnrich("sjms:queue:" + QUEUE + ".pollEnrich", 
5000)
+                        .to("mock:" + QUEUE + ".result");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/SjmsObjectMessageEnabledTest.java
 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/SjmsObjectMessageEnabledTest.java
index bea3796a71f6..dab58cbbfecd 100644
--- 
a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/SjmsObjectMessageEnabledTest.java
+++ 
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/producer/SjmsObjectMessageEnabledTest.java
@@ -24,12 +24,13 @@ import jakarta.jms.MessageProducer;
 import jakarta.jms.ObjectMessage;
 
 import org.apache.camel.CamelExecutionException;
-import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.sjms.SjmsComponent;
 import org.apache.camel.component.sjms.support.JmsTestSupport;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -94,11 +95,10 @@ public class SjmsObjectMessageEnabledTest extends 
JmsTestSupport {
         producer.send(objectMessage);
         producer.close();
 
-        // Reading the body via Camel should fail because 
objectMessageEnabled=false (default)
-        Exchange exchange = consumer.receive("sjms:queue:" + CONSUMER_QUEUE, 
5000);
-        assertNotNull(exchange, "Should have received the exchange wrapper");
-        IllegalStateException ex = assertThrows(IllegalStateException.class,
-                () -> exchange.getIn().getBody());
+        // Receiving via Camel should fail because objectMessageEnabled=false 
(default), as the receive reads the body
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                () -> consumer.receive("sjms:queue:" + CONSUMER_QUEUE, 5000));
+        IllegalStateException ex = 
assertInstanceOf(IllegalStateException.class, e.getCause());
         assertTrue(ex.getMessage().contains("objectMessageEnabled=true"),
                 "Expected guidance to enable objectMessageEnabled=true, got: " 
+ ex.getMessage());
     }
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index cdb0e12d565e..9e397bf219ab 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -505,6 +505,15 @@ closed, so the body of an ActiveMQ Artemis large message 
failed with `AMQ219023`
 (such as an `ObjectMessage` while `objectMessageEnabled` is `false`) now fails 
the receive itself, and the message is
 rolled back with `transacted=true`, or recovered with `CLIENT_ACKNOWLEDGE`, 
instead of committed or acknowledged.
 
+=== camel-sjms, camel-sjms2 - pollEnrich and ConsumerTemplate read the message 
before they close the session
+
+`pollEnrich` and a `ConsumerTemplate` on an `sjms` or `sjms2` endpoint now 
read the body and the headers of the message
+before they commit the session (or acknowledge the message) and close the JMS 
consumer, session and connection. Before,
+the body was read when the exchange first used it, after the connection was 
closed, so the body of an ActiveMQ Artemis
+large message failed with `AMQ219023`. A message whose body cannot be read 
(such as an `ObjectMessage` while
+`objectMessageEnabled` is `false`) now fails the receive itself, and the 
message is rolled back with `transacted=true`,
+or recovered with `CLIENT_ACKNOWLEDGE`, instead of committed or acknowledged, 
and lost.
+
 === camel-keycloak - Keycloak 26.8.2 requires the kc-admin-api client scope
 
 This is a change in Keycloak, not in Camel: from Keycloak 26.8.2 the Admin 
REST API accepts only access tokens that

Reply via email to