Example usage for org.springframework.http.client ClientHttpResponse getBody

List of usage examples for org.springframework.http.client ClientHttpResponse getBody

Introduction

In this page you can find the example usage for org.springframework.http.client ClientHttpResponse getBody.

Prototype

InputStream getBody() throws IOException;

Source Link

Document

Return the body of the message as an input stream.

Usage

From source file:org.springframework.social.wunderlist.api.impl.handler.ErrorResponseWrapper.java

private JsonNode asJson(ClientHttpResponse response) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new JsonFactory());
    return mapper.readValue(response.getBody(), JsonNode.class);
}

From source file:pl.sgorecki.facebook.marketing.ads.impl.FacebookAdsErrorHandler.java

private String readResponseJson(ClientHttpResponse response) throws IOException {
    String json = readFully(response.getBody());
    if (logger.isDebugEnabled()) {
        logger.debug("Error from Facebook: " + json);
    }/*from w w  w  . j  a va2 s. co  m*/
    return json;
}

From source file:org.springframework.social.wechat.api.impl.WechatErrorHandler.java

/**
 * Delegates to {@link #hasError(HttpStatus)} with the response status code.
 *///from  w w  w . ja  v a2s  .c  om
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
    String json = readFully(response.getBody());
    if (json.contains(ERROR_CODE) && json.contains(ERROR_MESSAGE)) {
        if (json.substring(json.indexOf(ERROR_MESSAGE)).contains("ok")) {
            return false;
        }
        return true;
    }
    return false;
}

From source file:com.epam.ta.reportportal.commons.exception.forwarding.ResponseForwardingException.java

public ResponseForwardingException(ClientHttpResponse response) throws IOException {
    this.headers = response.getHeaders();
    this.status = response.getStatusCode();
    this.body = ByteStreams.toByteArray(response.getBody());
}

From source file:de.zib.gndms.gndmc.utils.DefaultResponseExtractor.java

@Override
public void extractData(final String url, final ClientHttpResponse response) throws IOException {
    statusCode = response.getStatusCode().value();
    headers = response.getHeaders();/*w  w w  .  jav  a 2  s. c  o m*/
    body = response.getBody();
    this.url = url;
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.ApiResponseErrorHandler.java

private byte[] getResponseBody(ClientHttpResponse response) {
    try {//from w w w .j a  v  a2 s.co  m
        InputStream responseBody = response.getBody();
        if (responseBody != null) {
            return FileCopyUtils.copyToByteArray(responseBody);
        }
    } catch (IOException ex) {
        // ignore
    }
    return new byte[0];
}

From source file:org.springframework.social.linkedin.api.impl.LinkedInErrorHandler.java

private Map<String, Object> extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new JsonFactory());
    try {//from  ww w .java2 s.  c  o  m
        return mapper.<Map<String, Object>>readValue(response.getBody(),
                new TypeReference<Map<String, Object>>() {
                });
    } catch (JsonParseException e) {
        return Collections.emptyMap();
    }
}

From source file:io.bosh.client.jobs.SpringJobs.java

private final Observable<File> getGzip(Consumer<UriComponentsBuilder> builderCallback) {
    // For responses that have a Content-Type of application/x-gzip, we need to
    // decompress them. The RestTemplate and HttpClient don't handle this for
    // us/*from   www  . j  a  v  a 2 s  . com*/
    return createObservable(() -> {
        UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root);
        builderCallback.accept(builder);
        URI uri = builder.build().toUri();
        return this.restOperations.execute(uri, HttpMethod.GET, null, new ResponseExtractor<File>() {
            @Override
            public File extractData(ClientHttpResponse response) throws IOException {
                return decompress(response.getBody());
            }
        });
    });
}

From source file:org.springframework.social.box.connect.BoxOAuth2ErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) {
    String errorObject = null;//ww  w.j a  v a 2 s.co  m
    BoxOAuth2Error boxOAuth2Error = null;

    try {
        errorObject = readFully(response.getBody());
    } catch (Exception e) {
        throw new UncategorizedApiException(BOX, "No error details from Box", e);
    }

    ObjectMapper mapper = new ObjectMapper(new JsonFactory());
    mapper.registerModule(new BoxOAuth2ErrorModule());

    try {
        boxOAuth2Error = mapper.readValue(errorObject, BoxOAuth2Error.class);
    } catch (Exception e) {
        throw new UncategorizedApiException(BOX, "Could not parse error details from Box - " + errorObject, e);
    }

    if ((boxOAuth2Error.getError() == null) || (boxOAuth2Error.getErrorDescription() == null)) {
        throw new RejectedAuthorizationException(BOX,
                "Error while performing an OAuth2 operation - " + errorObject);
    }

    handleBoxOAuth2Error(boxOAuth2Error);
}