This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.8.x by this push:
new 7c8c326e382 CAMEL-21418: restl-dsl - Fix client request validation and
multiple values in Accept header (#16421)
7c8c326e382 is described below
commit 7c8c326e382515074b15ecc81b0363d3dad128bc
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Dec 2 16:29:27 2024 +0100
CAMEL-21418: restl-dsl - Fix client request validation and multiple values
in Accept header (#16421)
---
.../apache/camel/support/http/RestUtilTest.java | 50 ++++++++++++++++++++++
.../org/apache/camel/support/http/RestUtil.java | 14 +++---
2 files changed, 56 insertions(+), 8 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/support/http/RestUtilTest.java
b/core/camel-core/src/test/java/org/apache/camel/support/http/RestUtilTest.java
new file mode 100644
index 00000000000..250dab69374
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/support/http/RestUtilTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.support.http;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class RestUtilTest {
+
+ @Test
+ public void testRestUtil() {
+ Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType(null,
null));
+ Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType(null,
"*/*"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"*/*"));
+
+
Assertions.assertFalse(RestUtil.isValidOrAcceptedContentType("application/json",
"application/xml"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/json,application/xml"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/json, application/xml"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/xml,application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/xml, application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/xml,application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json",
"application/xml, application/json"));
+
+
Assertions.assertFalse(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/json,application/xml"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/json, application/xml"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/xml,application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/xml, application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/xml,application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/xml",
"application/xml, application/json"));
+
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json,application/xml",
"application/json"));
+
Assertions.assertTrue(RestUtil.isValidOrAcceptedContentType("application/json,application/xml",
"application/xml"));
+ }
+}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/http/RestUtil.java
b/core/camel-support/src/main/java/org/apache/camel/support/http/RestUtil.java
index e256770c9f2..efc00beaf0a 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/http/RestUtil.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/http/RestUtil.java
@@ -47,14 +47,12 @@ public final class RestUtil {
return true;
}
- boolean isXml = valid.contains("xml");
- if (isXml && !target.contains("xml")) {
- return false;
- }
-
- boolean isJson = valid.contains("json");
- if (isJson && !target.contains("json")) {
- return false;
+ // try each part of the target
+ for (String part : target.split(",")) {
+ part = part.trim();
+ if (valid.contains(part)) {
+ return true;
+ }
}
return false;