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
3ad2832c
Commit
3ad2832c
authored
Jan 19, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pattern extraction when MVC is using a PathPatternParser
Fixes gh-24874
parent
59b01324
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
3 deletions
+52
-3
RequestMappingConditionsDescription.java
...mappings/servlet/RequestMappingConditionsDescription.java
+9
-2
MappingsEndpointTests.java
...work/boot/actuate/web/mappings/MappingsEndpointTests.java
+43
-1
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/RequestMappingConditionsDescription.java
View file @
3ad2832c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -23,6 +23,7 @@ import java.util.stream.Collectors;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.servlet.mvc.condition.MediaTypeExpression
;
import
org.springframework.web.servlet.mvc.condition.NameValueExpression
;
import
org.springframework.web.servlet.mvc.condition.PatternsRequestCondition
;
import
org.springframework.web.servlet.mvc.method.RequestMappingInfo
;
/**
...
...
@@ -53,11 +54,17 @@ public class RequestMappingConditionsDescription {
this
.
methods
=
requestMapping
.
getMethodsCondition
().
getMethods
();
this
.
params
=
requestMapping
.
getParamsCondition
().
getExpressions
().
stream
()
.
map
(
NameValueExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
patterns
=
requestMapping
.
getPatternsCondition
().
getPatterns
(
);
this
.
patterns
=
extractPathPatterns
(
requestMapping
);
this
.
produces
=
requestMapping
.
getProducesCondition
().
getExpressions
().
stream
()
.
map
(
MediaTypeExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
}
private
Set
<
String
>
extractPathPatterns
(
RequestMappingInfo
requestMapping
)
{
PatternsRequestCondition
patternsCondition
=
requestMapping
.
getPatternsCondition
();
return
(
patternsCondition
!=
null
)
?
patternsCondition
.
getPatterns
()
:
requestMapping
.
getPathPatternsCondition
().
getPatternValues
();
}
public
List
<
MediaTypeExpressionDescription
>
getConsumes
()
{
return
this
.
consumes
;
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java
View file @
3ad2832c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
21
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -56,6 +56,9 @@ import org.springframework.web.reactive.function.server.RouterFunction;
import
org.springframework.web.reactive.function.server.ServerResponse
;
import
org.springframework.web.servlet.DispatcherServlet
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.PathMatchConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.util.pattern.PathPatternParser
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
...
@@ -94,6 +97,28 @@ class MappingsEndpointTests {
});
}
@Test
void
servletWebMappingsWithPathPatternParser
()
{
Supplier
<
ConfigurableWebApplicationContext
>
contextSupplier
=
prepareContextSupplier
();
new
WebApplicationContextRunner
(
contextSupplier
).
withUserConfiguration
(
EndpointConfiguration
.
class
,
ServletWebConfiguration
.
class
,
PathPatternParserConfiguration
.
class
).
run
((
context
)
->
{
ContextMappings
contextMappings
=
contextMappings
(
context
);
assertThat
(
contextMappings
.
getParentId
()).
isNull
();
assertThat
(
contextMappings
.
getMappings
()).
containsOnlyKeys
(
"dispatcherServlets"
,
"servletFilters"
,
"servlets"
);
Map
<
String
,
List
<
DispatcherServletMappingDescription
>>
dispatcherServlets
=
mappings
(
contextMappings
,
"dispatcherServlets"
);
assertThat
(
dispatcherServlets
).
containsOnlyKeys
(
"dispatcherServlet"
);
List
<
DispatcherServletMappingDescription
>
handlerMappings
=
dispatcherServlets
.
get
(
"dispatcherServlet"
);
assertThat
(
handlerMappings
).
hasSize
(
1
);
List
<
ServletRegistrationMappingDescription
>
servlets
=
mappings
(
contextMappings
,
"servlets"
);
assertThat
(
servlets
).
hasSize
(
1
);
List
<
FilterRegistrationMappingDescription
>
filters
=
mappings
(
contextMappings
,
"servletFilters"
);
assertThat
(
filters
).
hasSize
(
1
);
});
}
@Test
void
servletWebMappingsWithAdditionalDispatcherServlets
()
{
Supplier
<
ConfigurableWebApplicationContext
>
contextSupplier
=
prepareContextSupplier
();
...
...
@@ -260,4 +285,21 @@ class MappingsEndpointTests {
}
@Configuration
static
class
PathPatternParserConfiguration
{
@Bean
WebMvcConfigurer
pathPatternParserConfigurer
()
{
return
new
WebMvcConfigurer
()
{
@Override
public
void
configurePathMatch
(
PathMatchConfigurer
configurer
)
{
configurer
.
setPatternParser
(
new
PathPatternParser
());
}
};
}
}
}
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