You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/04/28 08:31:37 UTC

(camel) 01/01: CAMEL-22020: camel-platform-http/camel-rest: Plus sign in consumes/producers option should keep plus sign after URL encoded.

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

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

commit 91bb84bfb0d909f9fcecf85c965cd64252924aeb
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 28 10:31:14 2025 +0200

    CAMEL-22020: camel-platform-http/camel-rest: Plus sign in consumes/producers option should keep plus sign after URL encoded.
---
 .../platform/http/PlatformHttpEndpoint.java        |  8 +++
 .../http/PlatformHttpConsumesPlusSignTest.java     | 58 ++++++++++++++++++++++
 .../apache/camel/component/rest/RestEndpoint.java  |  8 +++
 3 files changed, 74 insertions(+)

diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
index 3c26d688132..84b067f650a 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpEndpoint.java
@@ -248,6 +248,10 @@ public class PlatformHttpEndpoint extends DefaultEndpoint
     }
 
     public void setConsumes(String consumes) {
+        // url encoding turns + into space
+        if (consumes != null) {
+            consumes = consumes.replace(' ', '+');
+        }
         this.consumes = consumes;
     }
 
@@ -256,6 +260,10 @@ public class PlatformHttpEndpoint extends DefaultEndpoint
     }
 
     public void setProduces(String produces) {
+        // url encoding turns + into space
+        if (produces != null) {
+            produces = produces.replace(' ', '+');
+        }
         this.produces = produces;
     }
 
diff --git a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpConsumesPlusSignTest.java b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpConsumesPlusSignTest.java
new file mode 100644
index 00000000000..3f64af08f7a
--- /dev/null
+++ b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/PlatformHttpConsumesPlusSignTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.platform.http;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+
+public class PlatformHttpConsumesPlusSignTest extends AbstractPlatformHttpTest {
+
+    @Test
+    void testConsumesPlusSign() {
+        given()
+                .header("Accept", "application/fhir+json")
+                .header("User-Agent", "User-Agent-Camel")
+                .port(port)
+                .expect()
+                .statusCode(200)
+                .header("Accept", (String) null)
+                .header("User-Agent", (String) null)
+                .when()
+                .get("/get");
+    }
+
+    @Override
+    protected RouteBuilder routes() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("platform-http:/get?consumes=application/fhir+json")
+                        .process(e -> {
+                            Assertions.assertEquals("application/fhir+json", e.getMessage().getHeader("Accept"));
+                            Assertions.assertEquals("User-Agent-Camel", e.getMessage().getHeader("User-Agent"));
+                            Assertions.assertNull(e.getMessage().getHeader(Exchange.HTTP_RESPONSE_CODE));
+                        })
+                        .setBody().constant("");
+            }
+        };
+    }
+
+}
diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index 85dd209db94..9e20cc05924 100644
--- a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -160,6 +160,10 @@ public class RestEndpoint extends DefaultEndpoint {
      * of types.
      */
     public void setConsumes(String consumes) {
+        // url encoding turns + into space
+        if (consumes != null) {
+            consumes = consumes.replace(' ', '+');
+        }
         this.consumes = consumes;
     }
 
@@ -171,6 +175,10 @@ public class RestEndpoint extends DefaultEndpoint {
      * Media type such as: 'text/xml', or 'application/json' this REST service returns.
      */
     public void setProduces(String produces) {
+        // url encoding turns + into space
+        if (produces != null) {
+            produces = produces.replace(' ', '+');
+        }
         this.produces = produces;
     }