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
efc3f888
Commit
efc3f888
authored
Feb 07, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid exception throw-catch for non-MatchableHandlerMapping mappings
Closes gh-11912
parent
b3ed46af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
5 deletions
+31
-5
WebMvcMetricsFilter.java
...boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java
+31
-5
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java
View file @
efc3f888
...
...
@@ -28,6 +28,7 @@ import java.util.function.Supplier;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
javax.servlet.http.HttpServletResponse
;
import
io.micrometer.core.annotation.Timed
;
...
...
@@ -49,6 +50,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.HandlerExecutionChain
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.handler.HandlerMappingIntrospector
;
import
org.springframework.web.servlet.handler.MatchableHandlerMapping
;
import
org.springframework.web.util.NestedServletException
;
...
...
@@ -125,11 +127,18 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
}
private
Object
getHandler
(
HttpServletRequest
request
)
throws
Exception
{
MatchableHandlerMapping
handlerMapping
=
getMappingIntrospector
()
.
getMatchableHandlerMapping
(
request
);
HandlerExecutionChain
chain
=
(
handlerMapping
==
null
?
null
:
handlerMapping
.
getHandler
(
request
));
return
(
chain
==
null
?
null
:
chain
.
getHandler
());
HttpServletRequest
wrapper
=
new
UnmodifiableAttributesRequestWrapper
(
request
);
for
(
HandlerMapping
handlerMapping
:
getMappingIntrospector
()
.
getHandlerMappings
())
{
HandlerExecutionChain
chain
=
handlerMapping
.
getHandler
(
wrapper
);
if
(
chain
!=
null
)
{
if
(
handlerMapping
instanceof
MatchableHandlerMapping
)
{
return
chain
.
getHandler
();
}
return
null
;
}
}
return
null
;
}
private
HandlerMappingIntrospector
getMappingIntrospector
()
{
...
...
@@ -272,4 +281,21 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
}
/**
* An {@link HttpServletRequestWrapper} that prevents modification of the request's
* attributes.
*/
private
static
final
class
UnmodifiableAttributesRequestWrapper
extends
HttpServletRequestWrapper
{
private
UnmodifiableAttributesRequestWrapper
(
HttpServletRequest
request
)
{
super
(
request
);
}
@Override
public
void
setAttribute
(
String
name
,
Object
value
)
{
}
}
}
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