/** * @param response The response to parse * @return A HttpResponse object made by consuming the response of the * given HttpMethod. * @throws IOException when problems occur processing the body content */ private HttpResponse makeResponse(org.apache.http.HttpResponse response) throws IOException { HttpResponseBuilder builder = new HttpResponseBuilder(); if (response.getAllHeaders() != null) { for (Header h : response.getAllHeaders()) { if (h.getName() != null) builder.addHeader(h.getName(), h.getValue()); } } HttpEntity entity = response.getEntity(); if (maxObjSize > 0 && entity != null && entity.getContentLength() > maxObjSize) { return HttpResponse.badrequest("Exceeded maximum number of bytes - " + maxObjSize); } byte[] responseBytes = (entity == null) ? null : toByteArraySafe(entity); return builder .setHttpStatusCode(response.getStatusLine().getStatusCode()) .setResponse(responseBytes) .create(); }
/** * @param response The response to parse * @return A HttpResponse object made by consuming the response of the * given HttpMethod. * @throws IOException when problems occur processing the body content */ private HttpResponse makeResponse(org.apache.http.HttpResponse response) throws IOException { HttpResponseBuilder builder = new HttpResponseBuilder(); if (response.getAllHeaders() != null) { for (Header h : response.getAllHeaders()) { if (h.getName() != null) builder.addHeader(h.getName(), h.getValue()); } } HttpEntity entity = response.getEntity(); if (maxObjSize > 0 && entity != null && entity.getContentLength() > maxObjSize) { return HttpResponse.badrequest("Exceeded maximum number of bytes - " + maxObjSize); } byte[] responseBytes = (entity == null) ? null : toByteArraySafe(entity); return builder .setHttpStatusCode(response.getStatusLine().getStatusCode()) .setResponse(responseBytes) .create(); }
/** * @param response The response to parse * @return A HttpResponse object made by consuming the response of the * given HttpMethod. * @throws IOException when problems occur processing the body content */ private HttpResponse makeResponse(org.apache.http.HttpResponse response) throws IOException { HttpResponseBuilder builder = new HttpResponseBuilder(); if (response.getAllHeaders() != null) { for (Header h : response.getAllHeaders()) { if (h.getName() != null) builder.addHeader(h.getName(), h.getValue()); } } HttpEntity entity = response.getEntity(); if (maxObjSize > 0 && entity.getContentLength() > maxObjSize) { return HttpResponse.badrequest("Exceeded maximum number of bytes - " + maxObjSize); } byte[] responseBytes = (entity == null) ? null : toByteArraySafe(entity); return builder .setHttpStatusCode(response.getStatusLine().getStatusCode()) .setResponse(responseBytes) .create(); }
@Test public void testToByteArraySafeHandleException() throws Exception { String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeHandlesExceptionWithNoMessage() throws Exception { EOFException e = new EOFException(); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeHandlesExceptionWithNoMessage() throws Exception { EOFException e = new EOFException(); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeHandleException() throws Exception { String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeHandlesExceptionWithNoMessage() throws Exception { EOFException e = new EOFException(); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); } }
@Test public void testToByteArraySafeHandleException() throws Exception { String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { fail("Exception Should have been caught"); } EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException1() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); String exceptionMessage = "IO Exception and Any Random Cause"; IOException e = new IOException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (IOException ioe) { assertEquals(exceptionMessage, ioe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException1() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); String exceptionMessage = "IO Exception and Any Random Cause"; IOException e = new IOException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (IOException ioe) { assertEquals(exceptionMessage, ioe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException3() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); // Return non-zero for 'InputStream.available()'. This should violate the other condition. EasyMock.expect(mockInputStream.available()).andReturn(1); String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } EasyMock.verify(mockEntity, mockInputStream); assertTrue(exceptionCaught); }
@Test public void testToByteArraySafeThrowsException1() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); String exceptionMessage = "IO Exception and Any Random Cause"; IOException e = new IOException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (IOException ioe) { assertEquals(exceptionMessage, ioe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException3() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); // Return non-zero for 'InputStream.available()'. This should violate the other condition. EasyMock.expect(mockInputStream.available()).andReturn(1); String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } EasyMock.verify(mockEntity, mockInputStream); assertTrue(exceptionCaught); }
@Test public void testToByteArraySafeThrowsException3() throws Exception { EasyMock.reset(mockInputStream); mockInputStream.close(); // Return non-zero for 'InputStream.available()'. This should violate the other condition. EasyMock.expect(mockInputStream.available()).andReturn(1); String exceptionMessage = "Unexpected end of ZLIB input stream"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } EasyMock.verify(mockEntity, mockInputStream); assertTrue(exceptionCaught); }
@Test public void testToByteArraySafeThrowsException2() throws Exception { String exceptionMessage = "EOF Exception and Any Random Cause"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException2() throws Exception { String exceptionMessage = "EOF Exception and Any Random Cause"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }
@Test public void testToByteArraySafeThrowsException2() throws Exception { String exceptionMessage = "EOF Exception and Any Random Cause"; EOFException e = new EOFException(exceptionMessage); EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes(); EasyMock.replay(mockEntity, mockInputStream); boolean exceptionCaught = false; try { fetcher.toByteArraySafe(mockEntity); } catch (EOFException eofe) { assertEquals(exceptionMessage, eofe.getMessage()); exceptionCaught = true; } assertTrue(exceptionCaught); EasyMock.verify(mockEntity, mockInputStream); }