LabradorRetriever { public void copyTo(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException { if (shouldMock()) { return; } assert httpRequest != null; assert httpResponse != null; final long start = System.currentTimeMillis(); int dataLength = -1; try { final URLConnection connection = openConnection(); connection.setRequestProperty("Accept-Language", httpRequest.getHeader("Accept-Language")); connection.connect(); httpResponse.setContentType(connection.getContentType()); final String contentDisposition = connection.getHeaderField("Content-Disposition"); if (contentDisposition != null) { httpResponse.setHeader("Content-Disposition", contentDisposition); } final OutputStream output = httpResponse.getOutputStream(); dataLength = pump(output, connection); } finally { LOG.info("http call done in " + (System.currentTimeMillis() - start) + " ms with " + dataLength / 1024 + " KB read for " + url); } } LabradorRetriever(URL url);  LabradorRetriever(URL url, Map<String, String> headers); void copyTo(HttpServletRequest httpRequest, HttpServletResponse httpResponse); void post(ByteArrayOutputStream payload);  }
@Test public void testCopyTo() throws IOException { Utils.setProperty(Parameters.PARAMETER_SYSTEM_PREFIX + "mockLabradorRetriever", "false"); final File file = File.createTempFile("testLabradorRetriever", null); try { final HttpServletRequest request = createNiceMock(HttpServletRequest.class); final HttpServletResponse response = createNiceMock(HttpServletResponse.class); new LabradorRetriever(file.toURI().toURL()).copyTo(request, response); } finally { if (!file.delete()) { file.deleteOnExit(); } } }