Skip to content

Commit 705ef38

Browse files
author
Nakul Sabharwal
committed
For fixing issue #95 , Added UTF-8 as parameter of getBytes and handling exception.
1 parent 53a2fc0 commit 705ef38

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/java/com/microsoft/graph/http/DefaultHttpProvider.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.IOException;
4040
import java.io.InputStream;
4141
import java.io.OutputStream;
42+
import java.io.UnsupportedEncodingException;
4243
import java.net.URL;
4344
import java.util.List;
4445
import java.util.Map;
@@ -58,6 +59,11 @@ public class DefaultHttpProvider implements IHttpProvider {
5859
* The content type for JSON responses
5960
*/
6061
static final String JSON_CONTENT_TYPE = "application/json";
62+
63+
/**
64+
* The encoding type for getBytes
65+
*/
66+
static final String ENCODING_TYPE = "UTF-8";
6167

6268
/**
6369
* The serializer
@@ -254,7 +260,7 @@ private <Result, Body, DeserializeType> Result sendRequestInternal(final IHttpRe
254260
} else {
255261
logger.logDebug("Sending " + serializable.getClass().getName() + " as request body");
256262
final String serializeObject = serializer.serializeObject(serializable);
257-
bytesToWrite = serializeObject.getBytes("UTF-8");
263+
bytesToWrite = serializeObject.getBytes(ENCODING_TYPE);
258264

259265
// If the user hasn't specified a Content-Type for the request
260266
if (!hasHeader(requestHeaders, CONTENT_TYPE_HEADER_NAME)) {
@@ -403,7 +409,13 @@ private <Result> Result handleJsonResponse(final InputStream in, Map<String, Lis
403409
*/
404410
private <Result> Result handleEmptyResponse(Map<String, List<String>> responseHeaders, final Class<Result> clazz) {
405411
//Create an empty object to attach the response headers to
406-
InputStream in = new ByteArrayInputStream("{}".getBytes());
412+
InputStream in = null;
413+
try{
414+
in = new ByteArrayInputStream("{}".getBytes(ENCODING_TYPE));
415+
}
416+
catch(UnsupportedEncodingException ex) {
417+
ex.printStackTrace();
418+
}
407419

408420
return handleJsonResponse(in, responseHeaders, clazz);
409421
}

0 commit comments

Comments
 (0)