Skip to content

Commit

Permalink
Misc (Azure#170)
Browse files Browse the repository at this point in the history
* Support data plan in azure token credentials

* [Fix Azure/azure-sdk-for-java#1520] check null response body on error

* Fix logging response
  • Loading branch information
jianghaolu authored May 19, 2017
1 parent 5e8d36f commit 2431dac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ hs_err_pid*
# ide
.idea
*.iml
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ public ServiceResponse<T> build(Response<ResponseBody> response) throws IOExcept
return new ServiceResponse<>(null, response);
} else {
try {
String responseContent = responseBody.string();
responseBody = ResponseBody.create(responseBody.contentType(), responseContent);
String responseContent = "";
if (responseBody != null) {
responseContent = responseBody.source().buffer().clone().readUtf8();
}
throw exceptionType.getConstructor(String.class, Response.class, (Class<?>) responseTypes.get(0))
.newInstance("Status code " + statusCode + ", " + responseContent, response, buildBody(statusCode, responseBody));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Expand Down Expand Up @@ -207,8 +209,7 @@ else if (type == InputStream.class) {
}
// Deserialize
else {
String responseContent = responseBody.string();
responseBody.close();
String responseContent = responseBody.source().buffer().clone().readUtf8();
if (responseContent.length() <= 0) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Response intercept(Chain chain) throws IOException {
// log headers
if (logLevel == LogLevel.HEADERS || logLevel == LogLevel.BODY_AND_HEADERS) {
for (String header : response.headers().names()) {
log(logger, String.format("%s: %s", header, Joiner.on(", ").join(request.headers(header))));
log(logger, String.format("%s: %s", header, Joiner.on(", ").join(response.headers(header))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public <T> T deserialize(String value, final Type type) throws IOException {
*/
private static ObjectMapper initializeObjectMapper(ObjectMapper mapper) {
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true)
.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
Expand Down

0 comments on commit 2431dac

Please sign in to comment.