Java Code Examples for javax.ws.rs.client.ClientResponseContext#getEntityStream()

The following examples show how to use javax.ws.rs.client.ClientResponseContext#getEntityStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllureJaxRs.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private String getBody(final ClientResponseContext responseContext) throws IOException {
    try (InputStream stream = responseContext.getEntityStream();
         ByteArrayOutputStream result = new ByteArrayOutputStream()) {
        final byte[] buffer = new byte[1024];

        int length = stream.read(buffer);
        while (length != -1) {
            result.write(buffer, 0, length);
            length = stream.read(buffer);
        }
        responseContext.setEntityStream(new ByteArrayInputStream(result.toByteArray()));
        return result.toString(StandardCharsets.UTF_8.toString());
    }
}
 
Example 2
Source File: RoboZonkyFilter.java    From robozonky with Apache License 2.0 5 votes vote down vote up
private String getResponseEntity(final ClientResponseContext clientResponseContext) throws IOException {
    if (shouldLogEntity(clientResponseContext)) {
        final InterceptingInputStream s = new InterceptingInputStream(clientResponseContext.getEntityStream());
        clientResponseContext.setEntityStream(s);
        logger.debug("Response body is: {}", s.getContents());
        return s.getContents();
    } else {
        return "";
    }
}
 
Example 3
Source File: ResteasyGitLabClientBuilder.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private String getResponseBody(ClientResponseContext context) {
    try (InputStream entityStream = context.getEntityStream()) {
        if (entityStream != null) {
            byte[] bytes = IOUtils.toByteArray(entityStream);
            context.setEntityStream(new ByteArrayInputStream(bytes));
            return new String(bytes);
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failure during reading the response body", e);
        context.setEntityStream(new ByteArrayInputStream(new byte[0]));
    }
    return "";
}