Skip to content

Commit

Permalink
Fix character encoding for binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Jan 29, 2025
1 parent 81cf6ae commit 9c3658e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,15 @@ public Response queryResult(String rsURL, String queryId, QueryRequest queryRequ
HttpClientUtil.composeURL(rsURL, pathName), createHeaders(queryRequest.getResourceCredentials()), body
);

byte[] content = httpClientUtil.readBytesFromResponse(resourcesResponse);
if (resourcesResponse.getStatusLine().getStatusCode() != 200) {
logger.error("ResourceRS did not return a 200");
HttpClientUtil.throwResponseError(resourcesResponse, rsURL);
}
return Response.ok(resourcesResponse.getEntity().getContent()).build();
return Response.ok(content).build();
} catch (JsonProcessingException e) {
logger.error("Unable to encode resource credentials");
throw new NotAuthorizedException("Unable to encode resource credentials", e);
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
closeHttpResponse(resourcesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ public String readObjectFromResponse(HttpResponse response, Charset charset) {
}
}

public byte[] readBytesFromResponse(HttpResponse response) {
logger.debug("HttpClientUtil readObjectFromResponse(HttpResponse response)");
try {
byte[] responseBody = EntityUtils.toByteArray(response.getEntity());
logger.debug("readObjectFromResponse() responseBody {}", responseBody);
return responseBody;
} catch (IOException e) {
throw new ApplicationException("Incorrect object type returned", e);
}
}

public static <T> T readObjectFromResponse(HttpResponse response, Class<T> expectedElementType) {
logger.debug("HttpClientUtil readObjectFromResponse()");
try {
Expand Down

0 comments on commit 9c3658e

Please sign in to comment.