File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
spring-boot-project/spring-boot-actuator/src
main/java/org/springframework/boot/actuate/metrics/web/servlet
test/java/org/springframework/boot/actuate/endpoint/web/servlet Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 26
26
import org .springframework .http .HttpStatus ;
27
27
import org .springframework .util .StringUtils ;
28
28
import org .springframework .web .servlet .HandlerMapping ;
29
+ import org .springframework .web .util .pattern .PathPattern ;
29
30
30
31
/**
31
32
* Factory methods for {@link Tag Tags} associated with a request-response exchange that
39
40
*/
40
41
public final class WebMvcTags {
41
42
43
+ private static final String DATA_REST_PATH_PATTERN_ATTRIBUTE = "org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH" ;
44
+
42
45
private static final Tag URI_NOT_FOUND = Tag .of ("uri" , "NOT_FOUND" );
43
46
44
47
private static final Tag URI_REDIRECTION = Tag .of ("uri" , "REDIRECTION" );
@@ -138,6 +141,11 @@ private static HttpStatus extractStatus(HttpServletResponse response) {
138
141
}
139
142
140
143
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
+ }
141
149
return (String ) request
142
150
.getAttribute (HandlerMapping .BEST_MATCHING_PATTERN_ATTRIBUTE );
143
151
}
Original file line number Diff line number Diff line change 23
23
import org .springframework .mock .web .MockHttpServletRequest ;
24
24
import org .springframework .mock .web .MockHttpServletResponse ;
25
25
import org .springframework .web .servlet .HandlerMapping ;
26
+ import org .springframework .web .util .pattern .PathPatternParser ;
26
27
27
28
import static org .assertj .core .api .Assertions .assertThat ;
28
29
@@ -39,6 +40,17 @@ public class WebMvcTagsTests {
39
40
40
41
private final MockHttpServletResponse response = new MockHttpServletResponse ();
41
42
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
+
42
54
@ Test
43
55
public void uriTagValueIsBestMatchingPatternWhenAvailable () {
44
56
this .request .setAttribute (HandlerMapping .BEST_MATCHING_PATTERN_ATTRIBUTE ,
You can’t perform that action at this time.
0 commit comments