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 24
24
import org .springframework .http .HttpStatus ;
25
25
import org .springframework .util .StringUtils ;
26
26
import org .springframework .web .servlet .HandlerMapping ;
27
+ import org .springframework .web .util .pattern .PathPattern ;
27
28
28
29
/**
29
30
* Factory methods for {@link Tag Tags} associated with a request-response exchange that
36
37
*/
37
38
public final class WebMvcTags {
38
39
40
+ private static final String DATA_REST_PATH_PATTERN_ATTRIBUTE = "org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH" ;
41
+
39
42
private static final Tag URI_NOT_FOUND = Tag .of ("uri" , "NOT_FOUND" );
40
43
41
44
private static final Tag URI_REDIRECTION = Tag .of ("uri" , "REDIRECTION" );
@@ -119,6 +122,11 @@ private static HttpStatus extractStatus(HttpServletResponse response) {
119
122
}
120
123
121
124
private static String getMatchingPattern (HttpServletRequest request ) {
125
+ PathPattern dataRestPathPattern = (PathPattern ) request
126
+ .getAttribute (DATA_REST_PATH_PATTERN_ATTRIBUTE );
127
+ if (dataRestPathPattern != null ) {
128
+ return dataRestPathPattern .getPatternString ();
129
+ }
122
130
return (String ) request
123
131
.getAttribute (HandlerMapping .BEST_MATCHING_PATTERN_ATTRIBUTE );
124
132
}
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
@@ -38,6 +39,17 @@ public class WebMvcTagsTests {
38
39
39
40
private final MockHttpServletResponse response = new MockHttpServletResponse ();
40
41
42
+ @ Test
43
+ public void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable () {
44
+ this .request .setAttribute (
45
+ "org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH" ,
46
+ new PathPatternParser ().parse ("/api/cities" ));
47
+ this .request .setAttribute (HandlerMapping .BEST_MATCHING_PATTERN_ATTRIBUTE ,
48
+ "/api/{repository}" );
49
+ Tag tag = WebMvcTags .uri (this .request , this .response );
50
+ assertThat (tag .getValue ()).isEqualTo ("/api/cities" );
51
+ }
52
+
41
53
@ Test
42
54
public void uriTagValueIsBestMatchingPatternWhenAvailable () {
43
55
this .request .setAttribute (HandlerMapping .BEST_MATCHING_PATTERN_ATTRIBUTE ,
You can’t perform that action at this time.
0 commit comments