From 1cb59ecd6bcea53a859f2972e8f7f1ba7898e805 Mon Sep 17 00:00:00 2001 From: Soufiane Aourinmouche <52406574+symphony-soufiane@users.noreply.github.com> Date: Tue, 19 Jul 2022 08:56:06 +0200 Subject: [PATCH] Bug fix #124: Unicode support for execute-request (#128) * #124: Unicode support for execute-request. When a body is sent with multipart-form-dara content type, we were using the default content type when adding the multipart string to the actual MultipartEntity object. This default content type is plain/text with ISO_8859_1 encoding charset. The fix was to enforce using StandarCharsets.UTF_8. --- .../executor/request/client/HttpClient.java | 13 ++++++------ .../ExecuteRequestIntegrationTest.java | 21 +++++++++++++++++++ .../execute-request-encode-body.swadl.yaml | 18 ++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 workflow-bot-app/src/test/resources/request/execute-request-encode-body.swadl.yaml diff --git a/workflow-bot-app/src/main/java/com/symphony/bdk/workflow/engine/executor/request/client/HttpClient.java b/workflow-bot-app/src/main/java/com/symphony/bdk/workflow/engine/executor/request/client/HttpClient.java index 18d22314..2772b658 100644 --- a/workflow-bot-app/src/main/java/com/symphony/bdk/workflow/engine/executor/request/client/HttpClient.java +++ b/workflow-bot-app/src/main/java/com/symphony/bdk/workflow/engine/executor/request/client/HttpClient.java @@ -64,25 +64,26 @@ private HttpResponse executeWithBody(Request request, Object body, Map bodyAsMap = (LinkedHashMap) body; - bodyAsMap.forEach((key, value) -> multipartEntityBuilder.addTextBody(key, value.toString())); + ContentType textBodyContentType = ContentType.create("text/plain", StandardCharsets.UTF_8); + bodyAsMap.forEach((key, value) -> multipartEntityBuilder.addTextBody(key, value.toString(), textBodyContentType)); request.body(multipartEntityBuilder.build()); // The content type with boundary is provided in the entity, otherwise it is overridden headers.remove(HttpHeaders.CONTENT_TYPE); - } else if (body != null && StringUtils.isNotEmpty(contentType)) { - if (contentType.equals(ContentType.APPLICATION_JSON.getMimeType()) && !(body instanceof String)) { + } else if (body != null && StringUtils.isNotEmpty(headerContentType)) { + if (headerContentType.equals(ContentType.APPLICATION_JSON.getMimeType()) && !(body instanceof String)) { request.bodyString(OBJECT_MAPPER.writeValueAsString(body), ContentType.APPLICATION_JSON); } else { - request.bodyString(body.toString(), ContentType.parse(contentType)); + request.bodyString(body.toString(), ContentType.parse(headerContentType)); } } else if (body != null) { // if no content type is provided, we set application/json by default diff --git a/workflow-bot-app/src/test/java/com/symphony/bdk/workflow/ExecuteRequestIntegrationTest.java b/workflow-bot-app/src/test/java/com/symphony/bdk/workflow/ExecuteRequestIntegrationTest.java index 6c88114e..1df17a7d 100644 --- a/workflow-bot-app/src/test/java/com/symphony/bdk/workflow/ExecuteRequestIntegrationTest.java +++ b/workflow-bot-app/src/test/java/com/symphony/bdk/workflow/ExecuteRequestIntegrationTest.java @@ -1,6 +1,7 @@ package com.symphony.bdk.workflow; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; @@ -71,6 +72,26 @@ void executeRequestSuccessful(MappingBuilder method, String swadlFile, List