ApacheHttpClientTagAdapter extends HttpTagAndSpanNamingAdapter<HttpRequest, HttpResponse> { @Override public @Nullable String getRequestPath(@Nullable HttpRequest request) { if (request == null) { return null; } if (request instanceof HttpRequestWrapper) { String path = ((HttpRequestWrapper) request).getURI().getPath(); return stripQueryString(path); } String requestLine = request.getRequestLine().getUri(); requestLine = stripQueryString(requestLine); if (requestLine.startsWith("/")) { return requestLine; } if (!requestLine.toLowerCase().startsWith("http")) { return null; } int schemeColonAndDoubleSlashIndex = requestLine.indexOf(": if (schemeColonAndDoubleSlashIndex < 0) { return null; } int firstSlashIndexAfterSchemeDoubleSlash = requestLine.indexOf('/', (schemeColonAndDoubleSlashIndex + 3)); if (firstSlashIndexAfterSchemeDoubleSlash < 0) { return "/"; } return requestLine.substring(firstSlashIndexAfterSchemeDoubleSlash); }  @SuppressWarnings("unchecked") static ApacheHttpClientTagAdapter getDefaultInstance(); @Override @Nullable String getRequestPath(@Nullable HttpRequest request); @Override @Nullable Integer getResponseHttpStatus(@Nullable HttpResponse response); @Override @Nullable String getRequestHttpMethod(@Nullable HttpRequest request); @Override @Nullable String getRequestUriPathTemplate(@Nullable HttpRequest request, @Nullable HttpResponse response); @Override @Nullable String getRequestUrl(@Nullable HttpRequest request); @Override @Nullable String getHeaderSingleValue(@Nullable HttpRequest request, @NotNull String headerKey); @Override @Nullable List<String> getHeaderMultipleValue(@Nullable HttpRequest request, @NotNull String headerKey); @Override @Nullable String getSpanHandlerTagValue(@Nullable HttpRequest request, @Nullable HttpResponse response);  }
@DataProvider(value = { "http: "http: "/some/path | /some/path", "/some/path?thing=stuff | /some/path", "http: "http: "/ | /", "/?thing=stuff | /", }, splitBy = "\\|") @Test public void getRequestPath_works_as_expected_for_a_request_that_is_an_HttpRequestWrapper( String uriString, String expectedResult ) { HttpRequestWrapper requestWrapperMock = mock(HttpRequestWrapper.class); doReturn(URI.create(uriString)).when(requestWrapperMock).getURI(); String result = implSpy.getRequestPath(requestWrapperMock); assertThat(result).isEqualTo(expectedResult); }
@DataProvider(value = { "http: "http: "http: "http: "https: "https: "https: "https: "http: "http: "http: "http: "https: "https: "https: "https: "http: "https: "http: "https: "/some/path | /some/path", "/some/path?thing=stuff | /some/path", "/ | /", "/?thing=stuff | /", "nothttp: "missing/leading/slash | null", "http "http:/missing.scheme.double.slash/some/path | null", }, splitBy = "\\|") @Test public void getRequestPath_works_as_expected_for_a_request_that_is_not_an_HttpRequestWrapper( String uri, String expectedPath ) { doReturn(uri).when(requestLineMock).getUri(); String result = implSpy.getRequestPath(requestMock); assertThat(result).isEqualTo(expectedPath); verify(requestMock).getRequestLine(); verify(requestLineMock).getUri(); verifyNoMoreInteractions(requestMock, requestLineMock); }
@Test public void getRequestPath_returns_null_if_passed_null() { assertThat(implSpy.getRequestPath(null)).isNull(); }