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 dee40ef3b300 CAMEL-25634: camel-jetty - a multipart text field that 
occurs several times keeps only its first value (#27852)
dee40ef3b300 is described below

commit dee40ef3b300f7f83edff224bcfc01c7e88f65a0
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Oct 15 17:31:54 2026 +0530

    CAMEL-25634: camel-jetty - a multipart text field that occurs several times 
keeps only its first value (#27852)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../component/jetty12/AttachmentHttpBinding.java   | 15 +++--
 .../jetty/MultiPartFormRepeatedFieldTest.java      | 70 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  8 +++
 3 files changed, 88 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty12/AttachmentHttpBinding.java
 
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty12/AttachmentHttpBinding.java
index 15d0afc084f4..608479ed8489 100644
--- 
a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty12/AttachmentHttpBinding.java
+++ 
b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty12/AttachmentHttpBinding.java
@@ -125,14 +125,19 @@ final class AttachmentHttpBinding extends 
DefaultHttpBinding {
                 String name = (String) names.nextElement();
                 if (am.getAttachment(name) != null) {
                     DataHandler dh = am.getAttachment(name);
-                    Object value = dh;
+                    Object[] values = { dh };
                     if (dh.getContentType() == null || 
dh.getContentType().startsWith("text/plain")) {
+                        // a text field can occur several times, so map each 
of its values
+                        String[] texts = request.getParameterValues(name);
                         // prevent potential injections
-                        value = 
HttpHelper.sanitizeLog(request.getParameter(name));
+                        values = texts != null ? HttpHelper.sanitizeLog(texts) 
: new Object[] { null };
                     }
-                    if (getHeaderFilterStrategy() != null
-                            && 
!getHeaderFilterStrategy().applyFilterToExternalHeaders(name, value, 
message.getExchange())) {
-                        HttpHelper.appendHeader(headers, name, value);
+                    for (Object value : values) {
+                        if (getHeaderFilterStrategy() != null
+                                && 
!getHeaderFilterStrategy().applyFilterToExternalHeaders(name, value,
+                                        message.getExchange())) {
+                            HttpHelper.appendHeader(headers, name, value);
+                        }
                     }
                     continue;
                 }
diff --git 
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormRepeatedFieldTest.java
 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormRepeatedFieldTest.java
new file mode 100644
index 000000000000..65ca17d87307
--- /dev/null
+++ 
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormRepeatedFieldTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.jetty;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * A text field of a multipart form that occurs several times (for example a 
group of checkboxes) is mapped to a header
+ * with all its values, as a repeated query or form-urlencoded parameter is.
+ */
+class MultiPartFormRepeatedFieldTest extends BaseJettyTest {
+
+    @Test
+    void testRepeatedTextFieldKeepsEveryValue() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:form");
+        mock.expectedMessageCount(1);
+
+        HttpPost post = new HttpPost("http://localhost:"; + getPort() + 
"/form");
+        post.setEntity(MultipartEntityBuilder.create()
+                .addTextBody("tag", "integration")
+                .addTextBody("project", "Camel")
+                .addTextBody("tag", "routing")
+                .build());
+        try (CloseableHttpClient client = HttpClients.createDefault();
+             CloseableHttpResponse response = client.execute(post)) {
+            assertEquals(200, response.getCode());
+        }
+
+        MockEndpoint.assertIsSatisfied(context);
+        assertEquals(List.of("integration", "routing"), 
mock.getExchanges().get(0).getIn().getHeader("tag"));
+        assertEquals("Camel", 
mock.getExchanges().get(0).getIn().getHeader("project"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("jetty://http://localhost:{{port}}/form";)
+                        .to("mock:form")
+                        .setBody(constant("OK"));
+            }
+        };
+    }
+}
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 cfe3340e54d4..45283da3e7cd 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
@@ -588,6 +588,14 @@ camel-http control headers of the message. It did so since 
Camel 4.19, when the
 request now always goes to `httpUri`, as it did before. For the same reason 
the `CamelHttpMethod` and
 `CamelHttpProtocolVersion` headers no longer apply, and the request is always 
a POST.
 
+=== camel-jetty - a multipart text field that occurs several times
+
+A text field of a `multipart/form-data` request that occurs several times (for 
example a group of checkboxes) is now
+mapped to a header whose value is the list of all its values, as a repeated 
query or form-urlencoded parameter already
+is. Before, the header had only the first value and the others were lost. 
Jetty also returns the query string values
+of the same name, so a name that is in both the query string and a multipart 
text field is mapped to a list of all
+these values too, as it already is for a form-urlencoded request.
+
 === camel-servlet and camel-jetty - gzip request body that arrives after the 
headers
 
 The servlet and Jetty consumers uncompressed a request body with 
`Content-Encoding: gzip` only when some of its bytes

Reply via email to