+ // Need to use buffered response because input stream may need to be consumed multiple times.
+ ClientHttpResponse bufferedResponse = new ClientHttpResponse()
+ {
+ private byte[] lazyBody;
+
+ @Override
+ public HttpStatus getStatusCode() throws IOException
+ {
+ return response.getStatusCode();
+ }
+
+ @Override
+ public synchronized InputStream getBody() throws IOException
+ {
+ if (lazyBody == null) {
+ InputStream bodyStream = response.getBody();
+ if (bodyStream != null) {
+ lazyBody = FileCopyUtils.copyToByteArray(bodyStream);
+ }
+ else {
+ lazyBody = new byte[0];
+ }
+ }
+ return new ByteArrayInputStream(lazyBody);
+ }
+
+ @Override
+ public HttpHeaders getHeaders()
+ {
+ return response.getHeaders();
+ }
+
+ @Override
+ public String getStatusText() throws IOException
+ {
+ return response.getStatusText();
+ }
+
+ @Override
+ public void close()
+ {
+ response.close();
+ }