From d4df533f5ddbef4bef10ef156b05552bf9c709b9 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Fri, 29 Sep 2023 17:07:45 -0500 Subject: [PATCH] Make charsetForEntityi a method, rather than hard-code UTF-8. --- .../module/api/actions/BaseAPIActionUtil.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java index 4da99413..bdcb5fe6 100644 --- a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java +++ b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java @@ -27,6 +27,7 @@ import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; @@ -786,7 +787,7 @@ public class BaseAPIActionUtil try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build()) { HttpPost request = new HttpPost(fullURL); - request.setEntity(new StringEntity(postBody, StandardCharsets.UTF_8)); + request.setEntity(new StringEntity(postBody, getCharsetForEntity())); if(setCredentialsInHeader) { @@ -829,6 +830,16 @@ public class BaseAPIActionUtil + /******************************************************************************* + ** Let a subclass change what charset to use for entities (bodies) being posted/put/etc. + *******************************************************************************/ + protected static Charset getCharsetForEntity() + { + return StandardCharsets.UTF_8; + } + + + /******************************************************************************* ** one-line method, factored out so mock/tests can override *******************************************************************************/ @@ -914,7 +925,7 @@ public class BaseAPIActionUtil body.put(wrapperObjectName, new JSONObject(json)); json = body.toString(); } - return (new StringEntity(json, StandardCharsets.UTF_8)); + return (new StringEntity(json, getCharsetForEntity())); } @@ -943,7 +954,7 @@ public class BaseAPIActionUtil body.put(wrapperObjectName, new JSONArray(json)); json = body.toString(); } - return (new StringEntity(json, StandardCharsets.UTF_8)); + return (new StringEntity(json, getCharsetForEntity())); } catch(Exception e) {