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 2023/10/25 09:02:39 UTC
[camel] branch main updated: [CAMEL-20037] camel-http builds StringEntity with wrong contentEncoding (#11828)
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 59ee8f30c61 [CAMEL-20037] camel-http builds StringEntity with wrong contentEncoding (#11828)
59ee8f30c61 is described below
commit 59ee8f30c618718a5943773031c236b5a7ecbe70
Author: Simo Kivimäki <85...@users.noreply.github.com>
AuthorDate: Wed Oct 25 12:02:33 2023 +0300
[CAMEL-20037] camel-http builds StringEntity with wrong contentEncoding (#11828)
* CAMEL-20037: camel-http must not create StringEntity having charset as content encoding
* camel-http autoformatted code
---
.../main/java/org/apache/camel/component/http/HttpProducer.java | 2 +-
.../org/apache/camel/component/http/OAuth2ClientConfigurer.java | 3 ++-
.../component/http/HttpProducerContentTypeWithCharsetTest.java | 1 +
.../camel/component/http/HttpProducerWithSpecialCharsBodyTest.java | 7 +++----
4 files changed, 7 insertions(+), 6 deletions(-)
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 da9c7e0d034..b4974b1c5e7 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
@@ -778,7 +778,7 @@ public class HttpProducer extends DefaultProducer {
contentType = ContentType.parse(contentType + ";charset=" + charset);
}
- answer = new StringEntity(content, contentType, charset, false);
+ answer = new StringEntity(content, contentType, false);
}
// fallback as input stream
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java b/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
index 23b633f631c..ab4005cfd68 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/OAuth2ClientConfigurer.java
@@ -63,7 +63,8 @@ public class OAuth2ClientConfigurer implements HttpClientConfigurer {
String accessToken = ((JsonObject) Jsoner.deserialize(responseString)).getString("access_token");
request.addHeader(HttpHeaders.AUTHORIZATION, accessToken);
} else {
- throw new HttpException("Received error response from token request with Status Code: " + response.getCode());
+ throw new HttpException(
+ "Received error response from token request with Status Code: " + response.getCode());
}
} catch (DeserializationException e) {
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerContentTypeWithCharsetTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerContentTypeWithCharsetTest.java
index eef598225ef..7e2f05a2745 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerContentTypeWithCharsetTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerContentTypeWithCharsetTest.java
@@ -51,6 +51,7 @@ public class HttpProducerContentTypeWithCharsetTest extends BaseHttpTest {
String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
assertEquals(CONTENT_TYPE_WITH_CHARSET.replace(";", "; "), contentType);
+ assertFalse(request.containsHeader(Exchange.CONTENT_ENCODING));
response.setEntity(new StringEntity(contentType, StandardCharsets.US_ASCII));
response.setCode(HttpStatus.SC_OK);
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java
index b651f7ff1a0..3a0cfb9ef2c 100644
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java
+++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java
@@ -28,8 +28,7 @@ import org.junit.jupiter.api.Test;
import static org.apache.camel.Exchange.CHARSET_NAME;
import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -71,7 +70,7 @@ class HttpProducerWithSpecialCharsBodyTest {
assertTrue(requestEntity instanceof StringEntity);
StringEntity entity = (StringEntity) requestEntity;
assertEquals(APPLICATION_JSON_UTF8, entity.getContentType(), "Content type should be given content type and charset");
- assertEquals(StandardCharsets.UTF_8.name(), entity.getContentEncoding(), "Content encoding should be given charset");
+ assertNull(entity.getContentEncoding(), "Content encoding should not be given");
assertEquals(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS,
new String(entity.getContent().readAllBytes(), StandardCharsets.UTF_8),
"Reading entity content with intended charset should result in the original (readable) message");
@@ -95,7 +94,7 @@ class HttpProducerWithSpecialCharsBodyTest {
assertTrue(requestEntity instanceof StringEntity);
StringEntity entity = (StringEntity) requestEntity;
assertEquals(APPLICATION_JSON_UTF8, entity.getContentType(), "Content type should be given content type and charset");
- assertEquals(StandardCharsets.UTF_8.name(), entity.getContentEncoding(), "Content encoding should be given charset");
+ assertNull(entity.getContentEncoding(), "Content encoding should not be given");
assertEquals(TEST_MESSAGE_WITH_SPECIAL_CHARACTERS,
new String(entity.getContent().readAllBytes(), StandardCharsets.UTF_8),
"Reading entity content with intended charset should result in the original (readable) message");