List of usage examples for org.springframework.http.client ClientHttpResponse ClientHttpResponse
ClientHttpResponse
From source file:com.pepaproch.gtswsdl.LoginRequestInterceptor.java
private ClientHttpResponse logResponse(ClientHttpResponse response) throws IOException { ClientHttpResponse result = new ClientHttpResponse() { InputStream in;/* w ww .j av a 2s . c o m*/ InputStream oldIn = response.getBody(); String jsonResponse; @Override public HttpStatus getStatusCode() throws IOException { return response.getStatusCode(); } @Override public int getRawStatusCode() throws IOException { return response.getRawStatusCode(); } @Override public String getStatusText() throws IOException { return response.getStatusText(); } @Override public void close() { try { Logger.getLogger(LoginRequestInterceptor.class).log(Level.DEBUG, jsonResponse); in.close(); oldIn.close(); } catch (IOException ex) { java.util.logging.Logger.getLogger(LoginRequestInterceptor.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } } @Override public InputStream getBody() throws IOException { if (in == null) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { byte[] readBuffer = new byte[4 * 1024]; int lenght; while ((lenght = oldIn.read(readBuffer)) != -1) { baos.write(readBuffer, 0, lenght); } baos.flush(); jsonResponse = baos.toString(); in = new ByteArrayInputStream(baos.toByteArray()); } } return in; } @Override public HttpHeaders getHeaders() { return response.getHeaders(); } }; return result; }