@Override protected void storeResponse(HttpResponse response, ICommRestResponse restResponse) throws Exception{ try{ // deconstruct the response entity HttpEntity entity = response.getEntity(); // debug System.out.println(entity.getContentType()); System.out.println(entity.getContentLength()); LogHelper.w("RestRequest-Response", "content length %d", entity.getContentLength()); System.out.println(EntityUtils.getContentCharSet(entity)); // get input stream org.apache.http.conn.EofSensorInputStream inputStream = (EofSensorInputStream) entity.getContent(); // get image from input stream Bitmap image = BitmapFactory.decodeStream(inputStream); // add to response ICommRestResponse<Bitmap> streamResponse = restResponse; streamResponse.setResponseContent(image); // set success restResponse.setResponseCode( (long) (image == null ? 999 : 0)); }catch(Exception ex){ restResponse.setErrorMessage(ex.getMessage()); restResponse.setResponseCode((long) 999); } }
@Test public void shouldCallAbortAndCloseOnConnectionReleaseTrigger() throws IOException { EofSensorInputStream stream = mock(EofSensorInputStream.class); ClientHttpResponse response = mock(ClientHttpResponse.class); when(response.getBody()).thenReturn(stream); try (RestAsyncClientHttpResponse unit = new RestAsyncClientHttpResponse(response)) { unit.getBody().close(); } verify(stream).abortConnection(); verify(stream).close(); }
@Override protected void storeResponse(HttpResponse response, ICommRestResponse restResponse) throws Exception{ // deconstruct the response entity HttpEntity entity = response.getEntity(); // debug System.out.println(entity.getContentType()); System.out.println(entity.getContentLength()); System.out.println(EntityUtils.getContentCharSet(entity)); // get input stream org.apache.http.conn.EofSensorInputStream inputStream = (EofSensorInputStream) entity.getContent(); // add to response ICommRestResponse<InputStream> streamResponse = restResponse; streamResponse.setResponseContent(inputStream); }
@Override public InputStream getContent() throws IOException { return new EofSensorInputStream(this.wrappedEntity.getContent(), this); }