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/03/06 16:25:09 UTC
(camel) branch camel-4.8.x updated (c7a6e4fb05e -> 08f8d059858)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git
from c7a6e4fb05e CAMEL-19731 Implemented try-with-resources for MinioClient (#17364)
new f5eec10b833 CAMEL-21840: camel-http producer fix issue with HTTP_QUERY and non ascii chars
new 08f8d059858 CAMEL-21840: Regen
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/camel/component/http/HttpProducer.java | 2 +-
.../apache/camel/component/http/HttpQueryTest.java | 46 ++++++++++++++++++++++
.../http/handler/BasicValidationHandler.java | 16 ++++++++
3 files changed, 63 insertions(+), 1 deletion(-)
(camel) 01/02: CAMEL-21840: camel-http producer fix issue with HTTP_QUERY and non ascii chars
Posted by da...@apache.org.
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
commit f5eec10b83390e4b61a7af673f5126bed548e22c
Author: Dennis Bohnstedt <mi...@gmail.com>
AuthorDate: Thu Mar 6 17:21:29 2025 +0100
CAMEL-21840: camel-http producer fix issue with HTTP_QUERY and non ascii chars
* Added unit-test, showing problem in camel-http path encoding, when using Exchange.HTTP_QUERY
* Fixed problem in camel-http path encoding, by using Ascii encoded url instead of uri when creating HttpUriRequest
* Changed testcase representation of danish characters to unicode encoded hex
---
.../apache/camel/component/http/HttpProducer.java | 2 +-
.../apache/camel/component/http/HttpQueryTest.java | 43 ++++++++++++++++++++++
.../http/handler/BasicValidationHandler.java | 16 ++++++++
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
index 34faa6b1cc6..532a2249da3 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
@@ -638,7 +638,7 @@ public class HttpProducer extends DefaultProducer {
// create http holder objects for the request
HttpMethods methodToUse = HttpMethodHelper.createMethod(exchange, getEndpoint());
- HttpUriRequest method = methodToUse.createMethod(uri);
+ HttpUriRequest method = methodToUse.createMethod(url);
// special for HTTP DELETE/GET if the message body should be included
if (getEndpoint().isDeleteWithBody() && "DELETE".equals(method.getMethod())
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
index 502238dce17..6973983d87e 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
@@ -29,6 +29,8 @@ public class HttpQueryTest extends BaseHttpTest {
private HttpServer localServer;
private String baseUrl;
+
+ private final String DANISH_CHARACTERS_UNICODE = "\u00e6\u00f8\u00e5\u00C6\u00D8\u00C5";
@Override
public void setupResources() throws Exception {
@@ -39,6 +41,12 @@ public class HttpQueryTest extends BaseHttpTest {
.register("/test/", new BasicValidationHandler(GET.name(), "my=@+camel", null, getExpectedContent()))
.register("/user/pass",
new BasicValidationHandler(GET.name(), "password=baa&username=foo", null, getExpectedContent()))
+ .register("/user/passwd",
+ new BasicValidationHandler(
+ GET.name(), "password='PasswordWithCharsThatNeedEscaping!≥≤!'&username=NotFromTheUSofA", null,
+ getExpectedContent()))
+ .register("/danish-accepted",
+ new BasicValidationHandler(GET.name(), "characters='"+ DANISH_CHARACTERS_UNICODE +"'", null, getExpectedContent()))
.create();
localServer.start();
@@ -84,4 +92,39 @@ public class HttpQueryTest extends BaseHttpTest {
assertExchange(exchange);
}
+
+ @Test
+ public void httpQueryWithPasswordContainingNonAsciiCharacter() {
+ Exchange exchange = template.request(
+ baseUrl + "/user/passwd?password='PasswordWithCharsThatNeedEscaping!≥≤!'&username=NotFromTheUSofA",
+ exchange1 -> {
+ });
+
+ assertExchange(exchange);
+ }
+
+ @Test
+ public void httpQueryWithPasswordContainingNonAsciiCharacterAsQueryParams() {
+ Exchange exchange = template.request(baseUrl + "/user/passwd",
+ exchange1 -> exchange1.getIn().setHeader(Exchange.HTTP_QUERY,
+ "password='PasswordWithCharsThatNeedEscaping!≥≤!'&username=NotFromTheUSofA"));
+
+ assertExchange(exchange);
+ }
+
+ @Test
+ public void httpDanishCharactersAcceptedInBaseURL() {
+ Exchange exchange = template.request(baseUrl + "/danish-accepted?characters='"+ DANISH_CHARACTERS_UNICODE +"'", exchange1 -> {
+ });
+
+ assertExchange(exchange);
+ }
+
+ @Test
+ public void httpDanishCharactersAcceptedAsQueryParams() {
+ Exchange exchange = template.request(baseUrl + "/danish-accepted",
+ exchange1 -> exchange1.getIn().setHeader(Exchange.HTTP_QUERY, "characters='"+ DANISH_CHARACTERS_UNICODE +"'"));
+
+ assertExchange(exchange);
+ }
}
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java b/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
index 680cffa7d5f..2974f793f47 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/handler/BasicValidationHandler.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.http.handler;
import java.io.IOException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@@ -76,6 +77,12 @@ public class BasicValidationHandler implements HttpRequestHandler {
return;
}
+ if (!validateRequestEncoding(request)) {
+ response.setCode(HttpStatus.SC_BAD_REQUEST);
+ response.setReasonPhrase("Request URI not encoded correctly!");
+ return;
+ }
+
if (expectedContent != null) {
HttpEntity entity = request.getEntity();
String content = EntityUtils.toString(entity);
@@ -105,6 +112,15 @@ public class BasicValidationHandler implements HttpRequestHandler {
return true;
}
+ protected boolean validateRequestEncoding(ClassicHttpRequest request) throws IOException {
+ try {
+ String encodedRequestPath = new URI(request.getPath()).toASCIIString();
+ return request.getPath().equals(encodedRequestPath); // Did request.path contain un-encoded characters?
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+ }
+
protected String buildResponse(ClassicHttpRequest request) {
return responseContent;
}
(camel) 02/02: CAMEL-21840: Regen
Posted by da...@apache.org.
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
commit 08f8d0598589407a1a485f21cd1ff650fcb8e5cd
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 6 17:23:11 2025 +0100
CAMEL-21840: Regen
---
.../java/org/apache/camel/component/http/HttpQueryTest.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
index 6973983d87e..d63cebb8f4f 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryTest.java
@@ -29,7 +29,7 @@ public class HttpQueryTest extends BaseHttpTest {
private HttpServer localServer;
private String baseUrl;
-
+
private final String DANISH_CHARACTERS_UNICODE = "\u00e6\u00f8\u00e5\u00C6\u00D8\u00C5";
@Override
@@ -46,7 +46,8 @@ public class HttpQueryTest extends BaseHttpTest {
GET.name(), "password='PasswordWithCharsThatNeedEscaping!≥≤!'&username=NotFromTheUSofA", null,
getExpectedContent()))
.register("/danish-accepted",
- new BasicValidationHandler(GET.name(), "characters='"+ DANISH_CHARACTERS_UNICODE +"'", null, getExpectedContent()))
+ new BasicValidationHandler(
+ GET.name(), "characters='" + DANISH_CHARACTERS_UNICODE + "'", null, getExpectedContent()))
.create();
localServer.start();
@@ -114,8 +115,9 @@ public class HttpQueryTest extends BaseHttpTest {
@Test
public void httpDanishCharactersAcceptedInBaseURL() {
- Exchange exchange = template.request(baseUrl + "/danish-accepted?characters='"+ DANISH_CHARACTERS_UNICODE +"'", exchange1 -> {
- });
+ Exchange exchange
+ = template.request(baseUrl + "/danish-accepted?characters='" + DANISH_CHARACTERS_UNICODE + "'", exchange1 -> {
+ });
assertExchange(exchange);
}
@@ -123,7 +125,8 @@ public class HttpQueryTest extends BaseHttpTest {
@Test
public void httpDanishCharactersAcceptedAsQueryParams() {
Exchange exchange = template.request(baseUrl + "/danish-accepted",
- exchange1 -> exchange1.getIn().setHeader(Exchange.HTTP_QUERY, "characters='"+ DANISH_CHARACTERS_UNICODE +"'"));
+ exchange1 -> exchange1.getIn().setHeader(Exchange.HTTP_QUERY,
+ "characters='" + DANISH_CHARACTERS_UNICODE + "'"));
assertExchange(exchange);
}