Enhance PrestashopClient to use UTF-8 encoding for XML body in POST and PUT methods
This commit is contained in:
@@ -19,6 +19,9 @@ import java.util.Base64;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class PrestashopClient {
|
public class PrestashopClient {
|
||||||
|
|
||||||
|
private static final MediaType APPLICATION_XML_UTF8 =
|
||||||
|
new MediaType("application", "xml", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
private final RestClient client;
|
private final RestClient client;
|
||||||
private final String baseUrl;
|
private final String baseUrl;
|
||||||
|
|
||||||
@@ -73,10 +76,11 @@ public class PrestashopClient {
|
|||||||
public String postXml(String path, MultiValueMap<String, String> params, String xmlBody) {
|
public String postXml(String path, MultiValueMap<String, String> params, String xmlBody) {
|
||||||
String uri = buildUri(path, params);
|
String uri = buildUri(path, params);
|
||||||
log.info("[PrestaShop] POST XML {}", uri);
|
log.info("[PrestaShop] POST XML {}", uri);
|
||||||
|
byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8);
|
||||||
return client.post()
|
return client.post()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.contentType(MediaType.APPLICATION_XML)
|
.contentType(APPLICATION_XML_UTF8)
|
||||||
.body(xmlBody)
|
.body(bodyBytes)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.body(String.class);
|
.body(String.class);
|
||||||
}
|
}
|
||||||
@@ -84,10 +88,11 @@ public class PrestashopClient {
|
|||||||
public String putXml(String path, MultiValueMap<String, String> params, String xmlBody) {
|
public String putXml(String path, MultiValueMap<String, String> params, String xmlBody) {
|
||||||
String uri = buildUri(path, params);
|
String uri = buildUri(path, params);
|
||||||
log.info("[PrestaShop] PUT XML {}", uri);
|
log.info("[PrestaShop] PUT XML {}", uri);
|
||||||
|
byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8);
|
||||||
return client.put()
|
return client.put()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.contentType(MediaType.APPLICATION_XML)
|
.contentType(APPLICATION_XML_UTF8)
|
||||||
.body(xmlBody)
|
.body(bodyBytes)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.body(String.class);
|
.body(String.class);
|
||||||
}
|
}
|
||||||
@@ -125,12 +130,15 @@ public class PrestashopClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("[PrestaShop] POST (proxy) {}", uri);
|
log.info("[PrestaShop] POST (proxy) {}", uri);
|
||||||
|
log.info("[PrestaShop] XML envoyé (proxy POST):\n{}", xmlBody);
|
||||||
|
|
||||||
|
byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return client.post()
|
return client.post()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.contentType(MediaType.APPLICATION_XML)
|
.contentType(APPLICATION_XML_UTF8)
|
||||||
.body(xmlBody)
|
.body(bodyBytes)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.toEntity(String.class);
|
.toEntity(String.class);
|
||||||
} catch (RestClientResponseException ex) {
|
} catch (RestClientResponseException ex) {
|
||||||
@@ -157,12 +165,15 @@ public class PrestashopClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("[PrestaShop] PUT (proxy) {}", uri);
|
log.info("[PrestaShop] PUT (proxy) {}", uri);
|
||||||
|
log.info("[PrestaShop] XML envoyé (proxy PUT):\n{}", xmlBody);
|
||||||
|
|
||||||
|
byte[] bodyBytes = xmlBody.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return client.put()
|
return client.put()
|
||||||
.uri(uri)
|
.uri(uri)
|
||||||
.contentType(MediaType.APPLICATION_XML)
|
.contentType(APPLICATION_XML_UTF8)
|
||||||
.body(xmlBody)
|
.body(bodyBytes)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
.toEntity(String.class);
|
.toEntity(String.class);
|
||||||
} catch (RestClientResponseException ex) {
|
} catch (RestClientResponseException ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user