HttpSpanFactory { public static @Nullable String determineUriPathTemplate(@Nullable HttpServletRequest request) { if (request == null) { return null; } String path = getRequestAttributeAsString(request, KnownZipkinTags.HTTP_ROUTE); if (StringUtils.isNotBlank(path)) { return path; } path = getRequestAttributeAsString(request, SPRING_BEST_MATCHING_PATTERN_REQUEST_ATTRIBUTE_KEY); if (StringUtils.isNotBlank(path)) { return path; } return null; } private  HttpSpanFactory(); static Span fromHttpServletRequest(HttpServletRequest servletRequest, List<String> userIdHeaderKeys); static String getUserIdFromHttpServletRequest(HttpServletRequest servletRequest, List<String> userIdHeaderKeys); static @Nullable String determineUriPathTemplate(@Nullable HttpServletRequest request); static @NotNull String getSpanName(@Nullable HttpServletRequest request);  }
@DataProvider(value = { "/some/http/route | /some/spring/pattern | /some/http/route", "/some/http/route | null | /some/http/route", "/some/http/route | | /some/http/route", "/some/http/route | [whitespace] | /some/http/route", "null | /some/spring/pattern | /some/spring/pattern", " | /some/spring/pattern | /some/spring/pattern", "[whitespace] | /some/spring/pattern | /some/spring/pattern", "null | null | null", " | | null", "[whitespace] | [whitespace] | null", }, splitBy = "\\|") @Test public void determineUriPathTemplate_works_as_expected( String httpRouteRequestAttr, String springMatchingPatternRequestAttr, String expectedResult ) { if ("[whitespace]".equals(httpRouteRequestAttr)) { httpRouteRequestAttr = " \t\r\n "; } if ("[whitespace]".equals(springMatchingPatternRequestAttr)) { springMatchingPatternRequestAttr = " \t\r\n "; } doReturn(httpRouteRequestAttr).when(request).getAttribute(KnownZipkinTags.HTTP_ROUTE); doReturn(springMatchingPatternRequestAttr) .when(request).getAttribute(HttpSpanFactory.SPRING_BEST_MATCHING_PATTERN_REQUEST_ATTRIBUTE_KEY); String result = HttpSpanFactory.determineUriPathTemplate(request); assertThat(result).isEqualTo(expectedResult); }
@Test public void determineUriPathTemplate_returns_null_if_passed_null() { assertThat(HttpSpanFactory.determineUriPathTemplate(null)).isNull(); }