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 668bb1eb472 CAMEL-22168: file/ftp: poll/pollEnrich should not allow 
configuring maxMessagesPerPoll
668bb1eb472 is described below

commit 668bb1eb4720e909b609c544dd1cc43c2955bcb3
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jun 19 09:03:01 2025 +0200

    CAMEL-22168: file/ftp: poll/pollEnrich should not allow configuring 
maxMessagesPerPoll
---
 .../apache/camel/component/file/FileEndpoint.java  |  5 +++
 .../component/file/remote/RemoteFileEndpoint.java  |  5 +++
 .../apache/camel/component/smb/SmbEndpoint.java    |  5 +++
 .../PollEnricherFileMaxMessagesPerPollTest.java    | 49 ++++++++++++++++++++++
 4 files changed, 64 insertions(+)

diff --git 
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
 
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
index 8efebcf1b50..0769ca715f2 100644
--- 
a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
+++ 
b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
@@ -145,6 +145,11 @@ public class FileEndpoint extends 
GenericFileEndpoint<File> {
         ObjectHelper.notNull(operations, PARAM_OPERATIONS);
         ObjectHelper.notNull(file, PARAM_FILE);
 
+        if (maxMessagesPerPoll > 1) {
+            throw new IllegalArgumentException(
+                    "The option maxMessagesPerPoll is not supported for 
polling consumer (such as when using poll or pollEnrich EIP)");
+        }
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("Creating GenericFilePollingConsumer with queueSize: {} 
blockWhenFull: {} blockTimeout: {}",
                     getPollingConsumerQueueSize(), 
isPollingConsumerBlockWhenFull(),
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
index b2c095a1075..2bc60da26ad 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
@@ -186,6 +186,11 @@ public abstract class RemoteFileEndpoint<T> extends 
GenericFileEndpoint<T> imple
 
     @Override
     public PollingConsumer createPollingConsumer() throws Exception {
+        if (maxMessagesPerPoll > 1) {
+            throw new IllegalArgumentException(
+                    "The option maxMessagesPerPoll is not supported for 
polling consumer (such as when using poll or pollEnrich EIP)");
+        }
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("Creating GenericFilePollingConsumer with queueSize: {} 
blockWhenFull: {} blockTimeout: {}",
                     getPollingConsumerQueueSize(), 
isPollingConsumerBlockWhenFull(),
diff --git 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
index aa645b24f49..75d8a809cbb 100644
--- 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
+++ 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
@@ -184,6 +184,11 @@ public class SmbEndpoint extends 
GenericFileEndpoint<FileIdBothDirectoryInformat
 
     @Override
     public PollingConsumer createPollingConsumer() throws Exception {
+        if (maxMessagesPerPoll > 1) {
+            throw new IllegalArgumentException(
+                    "The option maxMessagesPerPoll is not supported for 
polling consumer (such as when using poll or pollEnrich EIP)");
+        }
+
         if (LOG.isDebugEnabled()) {
             LOG.debug("Creating GenericFilePollingConsumer with queueSize: {} 
blockWhenFull: {} blockTimeout: {}",
                     getPollingConsumerQueueSize(), 
isPollingConsumerBlockWhenFull(),
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileMaxMessagesPerPollTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileMaxMessagesPerPollTest.java
new file mode 100644
index 00000000000..e5cb60319b9
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnricherFileMaxMessagesPerPollTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.processor.enricher;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class PollEnricherFileMaxMessagesPerPollTest extends ContextTestSupport 
{
+
+    @Test
+    public void testPollEnrichMaxMessagesPerPollInvalid() throws Exception {
+        getMockEndpoint("mock:dead").expectedBodiesReceived(
+                "The option maxMessagesPerPoll is not supported for polling 
consumer (such as when using poll or pollEnrich EIP)");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(Exception.class)
+                        .handled(true)
+                        
.transform(simple("${exception.getCause().getMessage()}"))
+                        .to("mock:dead");
+
+                from("timer:hello?repeatCount=1&delay=10")
+                        
.pollEnrich("file:target/temp?maxMessagesPerPoll=3&noop=true&fileName=doesnotexist.csv",
 1000);
+            }
+        };
+    }
+}

Reply via email to