Source:
protected void testHttpClientWithResponseHandler(HttpUriRequest request, String data, boolean fault) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); boolean badUrl = false; try { request.addHeader("test-header", "test-value"); if (fault) { request.addHeader("test-fault", "true"); } if (data != null && request instanceof HttpEntityEnclosingRequest) { StringEntity entity = new StringEntity(data, ContentType.create("text/plain", "UTF-8")); ((HttpEntityEnclosingRequest) request).setEntity(entity); } ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse( final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); assertEquals("Unexpected response code", 200, status); HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } }; String responseBody = httpclient.execute(request, responseHandler); assertEquals(HELLO_WORLD, responseBody); } catch (ConnectException ce) { assertEquals(BAD_URL, request.getURI().toString()); badUrl = true; } finally { httpclient.close(); } Wait.until(() -> getApmMockServer().getTraces().size() == 1); assertEquals(1, getApmMockServer().getTraces().size()); List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class); assertEquals("Expecting 1 producers", 1, producers.size()); Producer testProducer = producers.get(0); if (!badUrl) { String path = URI.create(SAY_HELLO_URL).getPath(); assertEquals(path, testProducer.getUri()); if (request.getURI().toString().endsWith(QUERY_STRING)) { assertEquals(QUERY_STRING, testProducer.getProperties(Constants.PROP_HTTP_QUERY).iterator().next().getValue()); } } else { assertEquals("true", testProducer.getProperties(Tags.ERROR.getKey()) .iterator().next().getValue()); } }

Target:
protected void testHttpClientWithResponseHandler(HttpUriRequest request, String data, boolean fault) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); boolean badUrl = false; try { request.addHeader("test-header", "test-value"); if (fault) { request.addHeader("test-fault", "true"); } if (data != null && request instanceof HttpEntityEnclosingRequest) { StringEntity entity = new StringEntity(data, ContentType.create("text/plain", "UTF-8")); ((HttpEntityEnclosingRequest) request).setEntity(entity); } ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse( final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); assertEquals("Unexpected response code", 200, status); HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity) : null; } }; String responseBody = httpclient.execute(request, responseHandler); assertEquals(HELLO_WORLD, responseBody); } catch (ConnectException ce) { assertEquals(BAD_URL, request.getURI().toString()); badUrl = true; } finally { httpclient.close(); } Wait.until(() -> getApmMockServer().getTraces().size() == 1); assertEquals(1, getApmMockServer().getTraces().size()); List<Producer> producers = NodeUtil.findNodes(getApmMockServer().getTraces().get(0).getNodes(), Producer.class); assertEquals("Expecting 1 producers", 1, producers.size()); Producer testProducer = producers.get(0); assertEquals(request.getURI().getPath(), testProducer.getUri()); if (!badUrl) { if (request.getURI().toString().endsWith(QUERY_STRING)) { assertEquals(QUERY_STRING, testProducer.getProperties(Constants.PROP_HTTP_QUERY).iterator().next().getValue()); } } else { assertEquals("true", testProducer.getProperties(Tags.ERROR.getKey()) .iterator().next().getValue()); } }