Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
21102155
Commit
21102155
authored
Oct 19, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide more detailed uri tag for calls to Data REST repositories
Closes gh-14872
parent
d838787e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
WebMvcTags.java
...ramework/boot/actuate/metrics/web/servlet/WebMvcTags.java
+8
-0
WebMvcTagsTests.java
...rk/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java
+12
-0
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java
View file @
21102155
...
...
@@ -24,6 +24,7 @@ import io.micrometer.core.instrument.Tag;
import
org.springframework.http.HttpStatus
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.util.pattern.PathPattern
;
/**
* Factory methods for {@link Tag Tags} associated with a request-response exchange that
...
...
@@ -36,6 +37,8 @@ import org.springframework.web.servlet.HandlerMapping;
*/
public
final
class
WebMvcTags
{
private
static
final
String
DATA_REST_PATH_PATTERN_ATTRIBUTE
=
"org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH"
;
private
static
final
Tag
URI_NOT_FOUND
=
Tag
.
of
(
"uri"
,
"NOT_FOUND"
);
private
static
final
Tag
URI_REDIRECTION
=
Tag
.
of
(
"uri"
,
"REDIRECTION"
);
...
...
@@ -119,6 +122,11 @@ public final class WebMvcTags {
}
private
static
String
getMatchingPattern
(
HttpServletRequest
request
)
{
PathPattern
dataRestPathPattern
=
(
PathPattern
)
request
.
getAttribute
(
DATA_REST_PATH_PATTERN_ATTRIBUTE
);
if
(
dataRestPathPattern
!=
null
)
{
return
dataRestPathPattern
.
getPatternString
();
}
return
(
String
)
request
.
getAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
);
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java
View file @
21102155
...
...
@@ -23,6 +23,7 @@ import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTags;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.util.pattern.PathPatternParser
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -38,6 +39,17 @@ public class WebMvcTagsTests {
private
final
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
@Test
public
void
uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable
()
{
this
.
request
.
setAttribute
(
"org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH"
,
new
PathPatternParser
().
parse
(
"/api/cities"
));
this
.
request
.
setAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
,
"/api/{repository}"
);
Tag
tag
=
WebMvcTags
.
uri
(
this
.
request
,
this
.
response
);
assertThat
(
tag
.
getValue
()).
isEqualTo
(
"/api/cities"
);
}
@Test
public
void
uriTagValueIsBestMatchingPatternWhenAvailable
()
{
this
.
request
.
setAttribute
(
HandlerMapping
.
BEST_MATCHING_PATTERN_ATTRIBUTE
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment