From d18377a2372fc50dbc9b9a10a07fc9a25e5a7da7 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:10:49 -0400 Subject: [PATCH] fix(HttpUtils): Use UTF-8 when forwarding request bodies to OTP. --- .../middleware/utils/HttpUtils.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java b/src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java index 684c00279..1188f33e9 100644 --- a/src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java +++ b/src/main/java/org/opentripplanner/middleware/utils/HttpUtils.java @@ -19,7 +19,6 @@ import javax.ws.rs.core.UriBuilder; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.http.HttpTimeoutException; import java.time.LocalDate; @@ -102,26 +101,16 @@ public static HttpResponseValues httpRequestRawResponse(URI uri, int timeoutInSe httpUriRequest = deleteRequest; break; case PUT: - try { - HttpPut putRequest = new HttpPut(uri); - putRequest.setEntity(new StringEntity(bodyContent)); - putRequest.setConfig(timeoutConfig); - httpUriRequest = putRequest; - } catch (UnsupportedEncodingException e) { - LOG.error("Unsupported encoding type", e); - return null; - } + HttpPut putRequest = new HttpPut(uri); + putRequest.setEntity(new StringEntity(bodyContent, "UTF-8")); + putRequest.setConfig(timeoutConfig); + httpUriRequest = putRequest; break; case POST: - try { - HttpPost postRequest = new HttpPost(uri); - postRequest.setEntity(new StringEntity(bodyContent)); - postRequest.setConfig(timeoutConfig); - httpUriRequest = postRequest; - } catch (UnsupportedEncodingException e) { - LOG.error("Unsupported encoding type", e); - return null; - } + HttpPost postRequest = new HttpPost(uri); + postRequest.setEntity(new StringEntity(bodyContent, "UTF-8")); + postRequest.setConfig(timeoutConfig); + httpUriRequest = postRequest; break; case HEAD: case OPTIONS: