List of usage examples for org.springframework.http.client ClientHttpResponse getBody
InputStream getBody() throws IOException;
From source file:org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests.java
protected String getResponse(String url) throws IOException, URISyntaxException { ClientHttpResponse response = getClientResponse(url); try {/*from w w w . ja va 2s.c om*/ return StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8")); } finally { response.close(); } }
From source file:org.springframework.cloud.netflix.turbine.stream.TurbineStreamTests.java
private ResponseEntity<String> extract(ClientHttpResponse response) throws IOException { // The message has to be sent after the endpoint is activated, so this is a // convenient place to put it stubTrigger.trigger("metrics"); byte[] bytes = new byte[1024]; StringBuilder builder = new StringBuilder(); int read = 0; while (read >= 0 && StringUtils.countOccurrencesOf(builder.toString(), "\n") < 2) { read = response.getBody().read(bytes, 0, bytes.length); if (read > 0) { latch.countDown();/*from www. j a v a 2s . c om*/ builder.append(new String(bytes, 0, read)); } log.debug("Building: " + builder); } log.debug("Done: " + builder); return ResponseEntity.status(response.getStatusCode()).headers(response.getHeaders()) .body(builder.toString()); }
From source file:org.springframework.social.google.api.impl.AbstractGoogleApiOperations.java
protected AbstractGoogleApiOperations(RestTemplate restTemplate, boolean isAuthorized) { this.restTemplate = restTemplate; this.isAuthorized = isAuthorized; restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { @Override//from w w w . j ava2s .co m public void handleError(ClientHttpResponse response) throws IOException { if (logger.isWarnEnabled()) { String bodyText = StreamUtils.copyToString(response.getBody(), Charset.defaultCharset()); logger.warn("Google API REST response body:" + bodyText); } } }); }