From de942e0d96bf96e807a33089ad9720be2ebaf770 Mon Sep 17 00:00:00 2001 From: Vincent Guillet Date: Wed, 3 Dec 2025 11:39:55 +0100 Subject: [PATCH] Enhance PrestashopClient to use UTF-8 encoding for XML body in POST and PUT methods --- .../service/prestashop/PrestashopClient.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/fr/gameovergne/api/service/prestashop/PrestashopClient.java b/api/src/main/java/fr/gameovergne/api/service/prestashop/PrestashopClient.java index 2b01389..8f919c6 100644 --- a/api/src/main/java/fr/gameovergne/api/service/prestashop/PrestashopClient.java +++ b/api/src/main/java/fr/gameovergne/api/service/prestashop/PrestashopClient.java @@ -19,6 +19,9 @@ import java.util.Base64; @Slf4j public class PrestashopClient { + private static final MediaType APPLICATION_XML_UTF8 = + new MediaType("application", "xml", StandardCharsets.UTF_8); + private final RestClient client; private final String baseUrl; @@ -73,10 +76,11 @@ public class PrestashopClient { public String postXml(String path, MultiValueMap params, String xmlBody) { String uri = buildUri(path, params); log.info("[PrestaShop] POST XML {}", uri); + byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8); return client.post() .uri(uri) - .contentType(MediaType.APPLICATION_XML) - .body(xmlBody) + .contentType(APPLICATION_XML_UTF8) + .body(bodyBytes) .retrieve() .body(String.class); } @@ -84,10 +88,11 @@ public class PrestashopClient { public String putXml(String path, MultiValueMap params, String xmlBody) { String uri = buildUri(path, params); log.info("[PrestaShop] PUT XML {}", uri); + byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8); return client.put() .uri(uri) - .contentType(MediaType.APPLICATION_XML) - .body(xmlBody) + .contentType(APPLICATION_XML_UTF8) + .body(bodyBytes) .retrieve() .body(String.class); } @@ -125,12 +130,15 @@ public class PrestashopClient { } log.info("[PrestaShop] POST (proxy) {}", uri); + log.info("[PrestaShop] XML envoyé (proxy POST):\n{}", xmlBody); + + byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8); try { return client.post() .uri(uri) - .contentType(MediaType.APPLICATION_XML) - .body(xmlBody) + .contentType(APPLICATION_XML_UTF8) + .body(bodyBytes) .retrieve() .toEntity(String.class); } catch (RestClientResponseException ex) { @@ -157,12 +165,15 @@ public class PrestashopClient { } log.info("[PrestaShop] PUT (proxy) {}", uri); + log.info("[PrestaShop] XML envoyé (proxy PUT):\n{}", xmlBody); + + byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8); try { return client.put() .uri(uri) - .contentType(MediaType.APPLICATION_XML) - .body(xmlBody) + .contentType(APPLICATION_XML_UTF8) + .body(bodyBytes) .retrieve() .toEntity(String.class); } catch (RestClientResponseException ex) {