Skip to content

Commit 69fbd2f

Browse files
committed
Delegate usesPathPatterns() call to mappings
Update `CompositeHandlerMapping` so that the `usesPathPatterns()` method returns `true` if any of the delegate mappings return `true`. Closes gh-24877
1 parent 3e376b9 commit 69fbd2f

File tree

4 files changed

+87
-12
lines changed

4 files changed

+87
-12
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerMapping.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,10 +43,7 @@ class CompositeHandlerMapping implements HandlerMapping {
4343

4444
@Override
4545
public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
46-
if (this.mappings == null) {
47-
this.mappings = extractMappings();
48-
}
49-
for (HandlerMapping mapping : this.mappings) {
46+
for (HandlerMapping mapping : getMappings()) {
5047
HandlerExecutionChain handler = mapping.getHandler(request);
5148
if (handler != null) {
5249
return handler;
@@ -55,6 +52,23 @@ public HandlerExecutionChain getHandler(HttpServletRequest request) throws Excep
5552
return null;
5653
}
5754

55+
@Override
56+
public boolean usesPathPatterns() {
57+
for (HandlerMapping mapping : getMappings()) {
58+
if (mapping.usesPathPatterns()) {
59+
return true;
60+
}
61+
}
62+
return false;
63+
}
64+
65+
private List<HandlerMapping> getMappings() {
66+
if (this.mappings == null) {
67+
this.mappings = extractMappings();
68+
}
69+
return this.mappings;
70+
}
71+
5872
private List<HandlerMapping> extractMappings() {
5973
List<HandlerMapping> list = new ArrayList<>(this.beanFactory.getBeansOfType(HandlerMapping.class).values());
6074
list.remove(this);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,6 @@
2222

2323
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
25-
import org.springframework.boot.test.context.SpringBootTest;
26-
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2725
import org.springframework.boot.test.web.client.TestRestTemplate;
2826
import org.springframework.boot.web.server.LocalServerPort;
2927
import org.springframework.core.env.Environment;
@@ -33,13 +31,11 @@
3331
import static org.assertj.core.api.Assertions.assertThat;
3432

3533
/**
36-
* Integration tests for separate management and main service ports.
34+
* Base class for integration tests with separate management and main service ports.
3735
*
3836
* @author Dave Syer
3937
*/
40-
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0",
41-
"management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" })
42-
class ManagementPortAndPathSampleActuatorApplicationTests {
38+
abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
4339

4440
@LocalServerPort
4541
private int port;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import org.springframework.boot.test.context.SpringBootTest;
20+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
21+
22+
/**
23+
* Integration tests for separate management and main service ports.
24+
*
25+
* @author Dave Syer
26+
*/
27+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0",
28+
"management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" })
29+
class ManagementPortAndPathWithAntPatcherSampleActuatorApplicationTests
30+
extends AbstractManagementPortAndPathSampleActuatorApplicationTests {
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import org.springframework.boot.test.context.SpringBootTest;
20+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
21+
22+
/**
23+
* Integration tests for separate management and main service ports.
24+
*
25+
* @author Dave Syer
26+
*/
27+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
28+
properties = { "spring.mvc.pathmatch.matching-strategy=path-pattern-parser", "management.server.port=0",
29+
"management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" })
30+
class ManagementPortAndPathWithPathMatcherSampleActuatorApplicationTests
31+
extends AbstractManagementPortAndPathSampleActuatorApplicationTests {
32+
33+
}

0 commit comments

Comments
 (0)