@Test public void testReturnPathFromRoutingContext() { RequestMetric requestMetric = new RequestMetric(); requestMetric.routingContext = Mockito.mock(RoutingContext.class); Route currentRoute = Mockito.mock(Route.class); Mockito.when(requestMetric.routingContext.currentRoute()).thenReturn(currentRoute); Mockito.when(currentRoute.getPath()).thenReturn("/item"); Assertions.assertEquals("/item", requestMetric.getHttpRequestPath()); }
String getHttpRequestPath() { if (pathMatched) { return path; } if (routingContext != null) { String rcPath = routingContext.get(HTTP_REQUEST_PATH); if (rcPath != null) { return rcPath; } String matchedPath = routingContext.currentRoute().getPath(); if (matchedPath != null) { if (matchedPath.contains(":")) { matchedPath = vertxRoutePath.computeIfAbsent(matchedPath, k -> { String segments[] = k.split("/"); for (int i = 0; i < segments.length; i++) { segments[i] = VERTX_ROUTE_PARAM.matcher(segments[i]).replaceAll("{$1}"); } return String.join("/", segments); }); } return matchedPath; } } return path; }
RequestMetric { String getHttpRequestPath() { if (pathMatched) { return path; } if (routingContext != null) { String rcPath = routingContext.get(HTTP_REQUEST_PATH); if (rcPath != null) { return rcPath; } String matchedPath = routingContext.currentRoute().getPath(); if (matchedPath != null) { if (matchedPath.contains(":")) { matchedPath = vertxRoutePath.computeIfAbsent(matchedPath, k -> { String segments[] = k.split("/"); for (int i = 0; i < segments.length; i++) { segments[i] = VERTX_ROUTE_PARAM.matcher(segments[i]).replaceAll("{$1}"); } return String.join("/", segments); }); } return matchedPath; } } return path; } }
RequestMetric { String getHttpRequestPath() { if (pathMatched) { return path; } if (routingContext != null) { String rcPath = routingContext.get(HTTP_REQUEST_PATH); if (rcPath != null) { return rcPath; } String matchedPath = routingContext.currentRoute().getPath(); if (matchedPath != null) { if (matchedPath.contains(":")) { matchedPath = vertxRoutePath.computeIfAbsent(matchedPath, k -> { String segments[] = k.split("/"); for (int i = 0; i < segments.length; i++) { segments[i] = VERTX_ROUTE_PARAM.matcher(segments[i]).replaceAll("{$1}"); } return String.join("/", segments); }); } return matchedPath; } } return path; }  }
RequestMetric { String getHttpRequestPath() { if (pathMatched) { return path; } if (routingContext != null) { String rcPath = routingContext.get(HTTP_REQUEST_PATH); if (rcPath != null) { return rcPath; } String matchedPath = routingContext.currentRoute().getPath(); if (matchedPath != null) { if (matchedPath.contains(":")) { matchedPath = vertxRoutePath.computeIfAbsent(matchedPath, k -> { String segments[] = k.split("/"); for (int i = 0; i < segments.length; i++) { segments[i] = VERTX_ROUTE_PARAM.matcher(segments[i]).replaceAll("{$1}"); } return String.join("/", segments); }); } return matchedPath; } } return path; }  static void setRequestMetric(Context context, RequestMetric requestMetric); static RequestMetric retrieveRequestMetric(Context context); }
RequestMetric { String getHttpRequestPath() { if (pathMatched) { return path; } if (routingContext != null) { String rcPath = routingContext.get(HTTP_REQUEST_PATH); if (rcPath != null) { return rcPath; } String matchedPath = routingContext.currentRoute().getPath(); if (matchedPath != null) { if (matchedPath.contains(":")) { matchedPath = vertxRoutePath.computeIfAbsent(matchedPath, k -> { String segments[] = k.split("/"); for (int i = 0; i < segments.length; i++) { segments[i] = VERTX_ROUTE_PARAM.matcher(segments[i]).replaceAll("{$1}"); } return String.join("/", segments); }); } return matchedPath; } } return path; }  static void setRequestMetric(Context context, RequestMetric requestMetric); static RequestMetric retrieveRequestMetric(Context context);  }