Skip to content

Commit 660b912

Browse files
committed
Merge branch '2.0.x'
2 parents 4e27d17 + 2110215 commit 660b912

File tree

2 files changed

+20
-0
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+20
-0
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.http.HttpStatus;
2727
import org.springframework.util.StringUtils;
2828
import org.springframework.web.servlet.HandlerMapping;
29+
import org.springframework.web.util.pattern.PathPattern;
2930

3031
/**
3132
* Factory methods for {@link Tag Tags} associated with a request-response exchange that
@@ -39,6 +40,8 @@
3940
*/
4041
public final class WebMvcTags {
4142

43+
private static final String DATA_REST_PATH_PATTERN_ATTRIBUTE = "org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH";
44+
4245
private static final Tag URI_NOT_FOUND = Tag.of("uri", "NOT_FOUND");
4346

4447
private static final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION");
@@ -138,6 +141,11 @@ private static HttpStatus extractStatus(HttpServletResponse response) {
138141
}
139142

140143
private static String getMatchingPattern(HttpServletRequest request) {
144+
PathPattern dataRestPathPattern = (PathPattern) request
145+
.getAttribute(DATA_REST_PATH_PATTERN_ATTRIBUTE);
146+
if (dataRestPathPattern != null) {
147+
return dataRestPathPattern.getPatternString();
148+
}
141149
return (String) request
142150
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
143151
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.mock.web.MockHttpServletRequest;
2424
import org.springframework.mock.web.MockHttpServletResponse;
2525
import org.springframework.web.servlet.HandlerMapping;
26+
import org.springframework.web.util.pattern.PathPatternParser;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
2829

@@ -39,6 +40,17 @@ public class WebMvcTagsTests {
3940

4041
private final MockHttpServletResponse response = new MockHttpServletResponse();
4142

43+
@Test
44+
public void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable() {
45+
this.request.setAttribute(
46+
"org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH",
47+
new PathPatternParser().parse("/api/cities"));
48+
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
49+
"/api/{repository}");
50+
Tag tag = WebMvcTags.uri(this.request, this.response);
51+
assertThat(tag.getValue()).isEqualTo("/api/cities");
52+
}
53+
4254
@Test
4355
public void uriTagValueIsBestMatchingPatternWhenAvailable() {
4456
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,

0 commit comments

Comments
 (0)