|
40 | 40 | import java.io.OutputStream; |
41 | 41 | import java.io.UnsupportedEncodingException; |
42 | 42 | import java.net.URL; |
| 43 | +import java.nio.charset.Charset; |
| 44 | +import java.nio.charset.StandardCharsets; |
43 | 45 | import java.util.List; |
44 | 46 | import java.util.Locale; |
45 | 47 | import java.util.Map; |
@@ -74,7 +76,7 @@ public class CoreHttpProvider implements IHttpProvider<Request> { |
74 | 76 | /** |
75 | 77 | * The encoding type for getBytes |
76 | 78 | */ |
77 | | - private static final String JSON_ENCODING = "UTF-8"; |
| 79 | + private static final Charset JSON_ENCODING = StandardCharsets.UTF_8; |
78 | 80 | /** |
79 | 81 | * The content type for JSON responses |
80 | 82 | */ |
@@ -295,14 +297,10 @@ public <Result, Body> Request getHttpRequest(@Nonnull final IHttpRequest request |
295 | 297 | } else { |
296 | 298 | logger.logDebug("Sending " + serializable.getClass().getName() + " as request body"); |
297 | 299 | final String serializeObject = serializer.serializeObject(serializable); |
298 | | - try { |
299 | | - bytesToWrite = serializeObject.getBytes(JSON_ENCODING); |
300 | | - } catch (final UnsupportedEncodingException ex) { |
301 | | - final ClientException clientException = new ClientException("Unsupported encoding problem: ", |
302 | | - ex); |
303 | | - logger.logError("Unsupported encoding problem: " + ex.getMessage(), ex); |
304 | | - throw clientException; |
305 | | - } |
| 300 | + if(serializeObject == null) { |
| 301 | + throw new ClientException("Error during serialization of request body, the result was null", null); |
| 302 | + } |
| 303 | + bytesToWrite = serializeObject.getBytes(JSON_ENCODING); |
306 | 304 |
|
307 | 305 | // If the user hasn't specified a Content-Type for the request |
308 | 306 | if (!hasHeader(requestHeaders, CONTENT_TYPE_HEADER_NAME)) { |
@@ -593,9 +591,8 @@ private Request convertIHttpRequestToOkHttpRequest(IHttpRequest request) { |
593 | 591 | @Nullable |
594 | 592 | public static String streamToString(@Nonnull final InputStream input) { |
595 | 593 | Objects.requireNonNull(input, "parameter input cannot be null"); |
596 | | - final String httpStreamEncoding = "UTF-8"; |
597 | 594 | final String endOfFile = "\\A"; |
598 | | - try (final Scanner scanner = new Scanner(input, httpStreamEncoding)) { |
| 595 | + try (final Scanner scanner = new Scanner(input, JSON_ENCODING.name())) { |
599 | 596 | scanner.useDelimiter(endOfFile); |
600 | 597 | if (scanner.hasNext()) { |
601 | 598 | return scanner.next(); |
|
0 commit comments