You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "mpaetzold (via GitHub)" <gi...@apache.org> on 2023/08/21 14:56:36 UTC

[GitHub] [camel] mpaetzold opened a new pull request, #11160: CAMEL-19768: Ensure content is encoded with expected charset

mpaetzold opened a new pull request, #11160:
URL: https://github.com/apache/camel/pull/11160

   **The problem**
   
   In Apache HttpComponents  5 StringEntity class became immutable and now requires different utilization than before. Earlier on, it was possible to instantiate an instance with charset only and updating the content type afterwards. Doing so, a temporary TEXT_PLAIN content type with given charset was used during String-to-byte-array conversion.
   
   Now that StringEntity became immutable, the content type must be provided right at the instantiation. In order to ensure the correct encoding, the charset of the content type instance has to be already set correctly at this point. This is the point at which false treatment can currently take place. In case the provided content type has no charset information, the StringEntity constructor falls back to ISO 8859-1 format, no matter what the separately provided charset states.
   
   **Attempted solution**
   
   Since ContentType is immutable, too, and furthermore does not provide direct accessors to all its fields, the content type gets reparsed (including the previously detected charset) in case the expected encoding is not already available.
   
   **Testing**
   
   In addition to unit tests that are targeting the exact method (HttpProducerContentTypeWithCharsetTest) I added a test class similar to HttpProducerContentTypeWithSemiColonTest, I fell over during testing.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #11160: CAMEL-19768: Ensure content is encoded with expected charset

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11160:
URL: https://github.com/apache/camel/pull/11160#issuecomment-1686491216

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :camel: Maintainers, please note that first-time contributors *require manual approval* for the GitHub Actions to run.
   
   :warning: Please note that the changes on this PR may be **tested automatically** if they change components.
   
   :robot: Use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus merged pull request #11160: CAMEL-19768: Ensure content is encoded with expected charset

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #11160:
URL: https://github.com/apache/camel/pull/11160


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #11160: CAMEL-19768: Ensure content is encoded with expected charset

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #11160:
URL: https://github.com/apache/camel/pull/11160#discussion_r1300906344


##########
components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+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.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class HttpProducerWithSpecialCharsBodyTest {
+
+    private static final String TEST_MESSAGE_WITH_SPECIAL_CHARACTERS = """
+            {
+                "description": "Example with special characters",

Review Comment:
   Thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #11160: CAMEL-19768: Ensure content is encoded with expected charset

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #11160:
URL: https://github.com/apache/camel/pull/11160#discussion_r1300323230


##########
components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+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.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class HttpProducerWithSpecialCharsBodyTest {
+
+    private static final String TEST_MESSAGE_WITH_SPECIAL_CHARACTERS = """
+            {
+                "description": "Example with special characters",

Review Comment:
   We need this code to be ascii, and therefore need to use their uni-code representation \uNNNN. I am not sure if there is a online tool that can do this so its faster than manually finding their unicode numbers.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] mpaetzold commented on a diff in pull request #11160: CAMEL-19768: Ensure content is encoded with expected charset

Posted by "mpaetzold (via GitHub)" <gi...@apache.org>.
mpaetzold commented on code in PR #11160:
URL: https://github.com/apache/camel/pull/11160#discussion_r1300890788


##########
components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerWithSpecialCharsBodyTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.http;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.CamelExchangeException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+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.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class HttpProducerWithSpecialCharsBodyTest {
+
+    private static final String TEST_MESSAGE_WITH_SPECIAL_CHARACTERS = """
+            {
+                "description": "Example with special characters",

Review Comment:
   Sure. AI tools became quite handy for such tasks. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org