Skip to content

Commit d66e108

Browse files
committed
Revert actuator changes related to path pattern parsing
See gh-31547
1 parent 67b5f42 commit d66e108

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
6363
Collection<ExposableWebEndpoint> endpoints, EndpointMediaTypes endpointMediaTypes,
6464
CorsConfiguration corsConfiguration, CloudFoundrySecurityInterceptor securityInterceptor,
6565
EndpointLinksResolver linksResolver) {
66-
super(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, true);
66+
super(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, true,
67+
AbstractWebMvcEndpointHandlerMapping.pathPatternParser);
6768
this.securityInterceptor = securityInterceptor;
6869
this.linksResolver = linksResolver;
6970
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
3838
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
3939
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
40+
import org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping;
4041
import org.springframework.boot.actuate.endpoint.web.servlet.AdditionalHealthEndpointPathsWebMvcHandlerMapping;
4142
import org.springframework.boot.actuate.endpoint.web.servlet.ControllerEndpointHandlerMapping;
4243
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
@@ -84,7 +85,7 @@ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpoint
8485
boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
8586
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
8687
corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
87-
shouldRegisterLinksMapping);
88+
shouldRegisterLinksMapping, AbstractWebMvcEndpointHandlerMapping.pathPatternParser);
8889
}
8990

9091
private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment,

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
3333
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
3434
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint;
35+
import org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping;
3536
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
3637
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
3738
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -55,7 +56,6 @@
5556
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
5657
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
5758
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
58-
import org.springframework.web.util.pattern.PathPatternParser;
5959

6060
import static org.assertj.core.api.Assertions.assertThat;
6161
import static org.hamcrest.Matchers.both;
@@ -87,7 +87,7 @@ void webMvcEndpointHandlerMappingIsConfiguredWithPathPatternParser() {
8787
this.context.setServletContext(new MockServletContext());
8888
this.context.refresh();
8989
WebMvcEndpointHandlerMapping handlerMapping = this.context.getBean(WebMvcEndpointHandlerMapping.class);
90-
assertThat(handlerMapping.getPatternParser()).isInstanceOf(PathPatternParser.class);
90+
assertThat(handlerMapping.getPatternParser()).isEqualTo(AbstractWebMvcEndpointHandlerMapping.pathPatternParser);
9191
}
9292

9393
@Test

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
102102

103103
private RequestMappingInfo.BuilderConfiguration builderConfig = new RequestMappingInfo.BuilderConfiguration();
104104

105+
/**
106+
* Instance of {@link PathPatternParser} shared across actuator configuration.
107+
*/
108+
public static final PathPatternParser pathPatternParser = new PathPatternParser();
109+
105110
/**
106111
* Creates a new {@code WebEndpointHandlerMapping} that provides mappings for the
107112
* operations of the given {@code webEndpoints}.
@@ -128,11 +133,29 @@ public AbstractWebMvcEndpointHandlerMapping(EndpointMapping endpointMapping,
128133
public AbstractWebMvcEndpointHandlerMapping(EndpointMapping endpointMapping,
129134
Collection<ExposableWebEndpoint> endpoints, EndpointMediaTypes endpointMediaTypes,
130135
CorsConfiguration corsConfiguration, boolean shouldRegisterLinksMapping) {
136+
this(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, shouldRegisterLinksMapping, null);
137+
}
138+
139+
/**
140+
* Creates a new {@code AbstractWebMvcEndpointHandlerMapping} that provides mappings
141+
* for the operations of the given endpoints.
142+
* @param endpointMapping the base mapping for all endpoints
143+
* @param endpoints the web endpoints
144+
* @param endpointMediaTypes media types consumed and produced by the endpoints
145+
* @param corsConfiguration the CORS configuration for the endpoints or {@code null}
146+
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
147+
* @param pathPatternParser the path pattern parser
148+
*/
149+
public AbstractWebMvcEndpointHandlerMapping(EndpointMapping endpointMapping,
150+
Collection<ExposableWebEndpoint> endpoints, EndpointMediaTypes endpointMediaTypes,
151+
CorsConfiguration corsConfiguration, boolean shouldRegisterLinksMapping,
152+
PathPatternParser pathPatternParser) {
131153
this.endpointMapping = endpointMapping;
132154
this.endpoints = endpoints;
133155
this.endpointMediaTypes = endpointMediaTypes;
134156
this.corsConfiguration = corsConfiguration;
135157
this.shouldRegisterLinksMapping = shouldRegisterLinksMapping;
158+
setPatternParser(pathPatternParser);
136159
setOrder(-100);
137160
}
138161

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcEndpointHandlerMapping.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.web.bind.annotation.ResponseBody;
3232
import org.springframework.web.cors.CorsConfiguration;
3333
import org.springframework.web.servlet.HandlerMapping;
34+
import org.springframework.web.util.pattern.PathPatternParser;
3435

3536
/**
3637
* A custom {@link HandlerMapping} that makes web endpoints available over HTTP using
@@ -62,6 +63,27 @@ public WebMvcEndpointHandlerMapping(EndpointMapping endpointMapping, Collection<
6263
setOrder(-100);
6364
}
6465

66+
/**
67+
* Creates a new {@code WebMvcEndpointHandlerMapping} instance that provides mappings
68+
* for the given endpoints.
69+
* @param endpointMapping the base mapping for all endpoints
70+
* @param endpoints the web endpoints
71+
* @param endpointMediaTypes media types consumed and produced by the endpoints
72+
* @param corsConfiguration the CORS configuration for the endpoints or {@code null}
73+
* @param linksResolver resolver for determining links to available endpoints
74+
* @param shouldRegisterLinksMapping whether the links endpoint should be registered
75+
* @param pathPatternParser the path pattern parser
76+
*/
77+
public WebMvcEndpointHandlerMapping(EndpointMapping endpointMapping, Collection<ExposableWebEndpoint> endpoints,
78+
EndpointMediaTypes endpointMediaTypes, CorsConfiguration corsConfiguration,
79+
EndpointLinksResolver linksResolver, boolean shouldRegisterLinksMapping,
80+
PathPatternParser pathPatternParser) {
81+
super(endpointMapping, endpoints, endpointMediaTypes, corsConfiguration, shouldRegisterLinksMapping,
82+
pathPatternParser);
83+
this.linksResolver = linksResolver;
84+
setOrder(-100);
85+
}
86+
6587
@Override
6688
protected LinksHandler getLinksHandler() {
6789
return new WebMvcLinksHandler();

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
124124
import org.springframework.web.servlet.view.InternalResourceViewResolver;
125125
import org.springframework.web.util.UrlPathHelper;
126-
import org.springframework.web.util.pattern.PathPatternParser;
127126

128127
/**
129128
* {@link EnableAutoConfiguration Auto-configuration} for {@link EnableWebMvc Web MVC}.
@@ -159,11 +158,6 @@ public class WebMvcAutoConfiguration {
159158
*/
160159
public static final String DEFAULT_SUFFIX = "";
161160

162-
/**
163-
* Instance of {@link PathPatternParser} shared across MVC and actuator configuration.
164-
*/
165-
public static final PathPatternParser pathPatternParser = new PathPatternParser();
166-
167161
private static final String SERVLET_LOCATION = "/";
168162

169163
@Bean

0 commit comments

Comments
 (0)