gnodet-bot commented on code in PR #27173:
URL: https://github.com/apache/camel/pull/27173#discussion_r4316758352


##########
components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java:
##########
@@ -382,6 +423,12 @@ public void 
configureMessageListener(EndpointMessageListener listener) {
         listener.setAsync(isAsyncConsumer());
     }
 
+    public void configureBatchMesageListener(BatchEndpointMessageListener 
listener) {

Review Comment:
   🔤 **Typo:** `configureBatchMesageListener` is missing the `s` in "Message" → 
should be `configureBatchMessageListener`. This is a public method — the 
misspelling becomes permanent API.
   
   ```suggestion
       public void configureBatchMessageListener(BatchEndpointMessageListener 
listener) {
   ```



##########
components/camel-sjms/src/main/java/org/apache/camel/component/sjms/SjmsEndpoint.java:
##########
@@ -361,6 +388,20 @@ public Consumer createConsumer(Processor processor) throws 
Exception {
         return consumer;
     }
 
+    protected Consumer createBatchConsumer(Processor processor) throws 
Exception {
+        validateBatchingOptions();
+
+        BatchMessageListenerContainer container = 
createBatchMessageListenerContainer(this);
+        SjmsConsumer consumer = new SjmsConsumer(this, processor, container);
+
+        BatchEndpointMessageListener listener = new 
BatchEndpointMessageListener(consumer, this, processor);
+        configureBatchMesageListener(listener);

Review Comment:
   🔤 **Typo:** matching call site — `configureBatchMesageListener` → 
`configureBatchMessageListener`.
   
   ```suggestion
           configureBatchMessageListener(listener);
   ```



##########
components/camel-sjms/src/main/java/org/apache/camel/component/sjms/consumer/BatchEndpointMessageListener.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import jakarta.jms.Message;
+import jakarta.jms.Session;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RollbackExchangeException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.sjms.SjmsConstants;
+import org.apache.camel.component.sjms.SjmsConsumer;
+import org.apache.camel.component.sjms.SjmsEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException;
+
+public class BatchEndpointMessageListener {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(BatchEndpointMessageListener.class);
+
+    private final SjmsConsumer consumer;
+    private final SjmsEndpoint endpoint;
+    private final Processor processor;
+    private String poisonBody;
+
+    public BatchEndpointMessageListener(SjmsConsumer consumer, SjmsEndpoint 
endpoint, Processor processor) {
+        this.consumer = consumer;
+        this.endpoint = endpoint;
+        this.processor = processor;
+    }
+
+    public void setPoisonBody(String poisonBody) {
+        this.poisonBody = poisonBody;
+    }
+
+    private Exchange aggregate(List<Message> rawMessages, Session session) {
+        List<Exchange> exchanges = new ArrayList<>(rawMessages.size());
+        for (Message m : rawMessages) {
+            Exchange exchange = endpoint.createExchange(m, session);
+            try {
+                // Force eager materialization of JMS message headers and body 
into the
+                // Camel Exchange, before the session is committed/closed 
after dispatch.
+                exchange.getIn().getHeaders();
+                exchange.getIn().getBody();
+            } catch (Exception e) {
+                exchange.setException(e);
+                String text = poisonBody;
+                try {
+                    text = endpoint.getCamelContext().resolveLanguage("simple")
+                            .createExpression(poisonBody).evaluate(exchange, 
String.class);

Review Comment:
   ⚠️ **Null safety:** When `eagerPoisonBody=false`, `setPoisonBody()` is never 
called and `poisonBody` remains `null`. `createExpression(null)` then throws 
(caught by the inner `catch`, leaving body as `null`). The existing 
`EndpointMessageListener` guards this with 
`ObjectHelper.isNotEmpty(eagerPoisonBody)` before entering the block. Add a 
null guard here for consistency:
   
   ```suggestion
                       text = poisonBody != null ? 
endpoint.getCamelContext().resolveLanguage("simple")
                               .createExpression(poisonBody).evaluate(exchange, 
String.class) : null;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to