Skip to content

Commit 42c053c

Browse files
committed
Merge branch '2.0.x'
2 parents b18a456 + 6de479f commit 42c053c

File tree

127 files changed

+419
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+419
-210
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public Object handle(HttpServletRequest request, Map<String, String> body) {
134134
}
135135
return this.delegate.handle(request, body);
136136
}
137+
137138
}
138139

139140
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*
3232
* @author Phillip Webb
3333
* @author Andy Wilkinson
34-
*
3534
* @since 2.0.0
3635
*/
3736
@Configuration

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import org.springframework.boot.util.LambdaSafe;
2929

3030
/**
31-
* Configurer to apply {@link MeterRegistryCustomizer customizers},
32-
* {@link MeterFilter filters}, {@link MeterBinder binders} and {@link Metrics#addRegistry
33-
* global registration} to {@link MeterRegistry meter registries}. This configurer
34-
* intentionally skips {@link CompositeMeterRegistry} with the assumptions that the
35-
* registries it contains are beans and will be customized directly.
31+
* Configurer to apply {@link MeterRegistryCustomizer customizers}, {@link MeterFilter
32+
* filters}, {@link MeterBinder binders} and {@link Metrics#addRegistry global
33+
* registration} to {@link MeterRegistry meter registries}. This configurer intentionally
34+
* skips {@link CompositeMeterRegistry} with the assumptions that the registries it
35+
* contains are beans and will be customized directly.
3636
*
3737
* @author Jon Schneider
3838
* @author Phillip Webb

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
3434
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
3535
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
36+
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider;
3637
import org.springframework.boot.security.servlet.ApplicationContextRequestMatcher;
3738
import org.springframework.core.annotation.AnnotationUtils;
3839
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
3940
import org.springframework.security.web.util.matcher.OrRequestMatcher;
4041
import org.springframework.security.web.util.matcher.RequestMatcher;
4142
import org.springframework.util.Assert;
4243
import org.springframework.util.StringUtils;
44+
import org.springframework.web.context.WebApplicationContext;
4345

4446
/**
4547
* Factory that can be used to create a {@link RequestMatcher} for actuator endpoint
@@ -114,7 +116,7 @@ public static LinksRequestMatcher toLinks() {
114116
* The request matcher used to match against {@link Endpoint actuator endpoints}.
115117
*/
116118
public static final class EndpointRequestMatcher
117-
extends ApplicationContextRequestMatcher<PathMappedEndpoints> {
119+
extends ApplicationContextRequestMatcher<WebApplicationContext> {
118120

119121
private final List<Object> includes;
120122

@@ -140,7 +142,7 @@ private EndpointRequestMatcher(String[] endpoints, boolean includeLinks) {
140142

141143
private EndpointRequestMatcher(List<Object> includes, List<Object> excludes,
142144
boolean includeLinks) {
143-
super(PathMappedEndpoints.class);
145+
super(WebApplicationContext.class);
144146
this.includes = includes;
145147
this.excludes = excludes;
146148
this.includeLinks = includeLinks;
@@ -163,32 +165,40 @@ public EndpointRequestMatcher excludingLinks() {
163165
}
164166

165167
@Override
166-
protected void initialized(Supplier<PathMappedEndpoints> pathMappedEndpoints) {
167-
this.delegate = createDelegate(pathMappedEndpoints);
168+
protected void initialized(
169+
Supplier<WebApplicationContext> webApplicationContext) {
170+
this.delegate = createDelegate(webApplicationContext);
168171
}
169172

170173
private RequestMatcher createDelegate(
171-
Supplier<PathMappedEndpoints> pathMappedEndpoints) {
174+
Supplier<WebApplicationContext> webApplicationContext) {
172175
try {
173-
return createDelegate(pathMappedEndpoints.get());
176+
WebApplicationContext context = webApplicationContext.get();
177+
PathMappedEndpoints pathMappedEndpoints = context
178+
.getBean(PathMappedEndpoints.class);
179+
DispatcherServletPathProvider pathProvider = context
180+
.getBean(DispatcherServletPathProvider.class);
181+
return createDelegate(pathMappedEndpoints, pathProvider.getServletPath());
174182
}
175183
catch (NoSuchBeanDefinitionException ex) {
176184
return EMPTY_MATCHER;
177185
}
178186
}
179187

180-
private RequestMatcher createDelegate(PathMappedEndpoints pathMappedEndpoints) {
188+
private RequestMatcher createDelegate(PathMappedEndpoints pathMappedEndpoints,
189+
String servletPath) {
181190
Set<String> paths = new LinkedHashSet<>();
182191
if (this.includes.isEmpty()) {
183192
paths.addAll(pathMappedEndpoints.getAllPaths());
184193
}
185194
streamPaths(this.includes, pathMappedEndpoints).forEach(paths::add);
186195
streamPaths(this.excludes, pathMappedEndpoints).forEach(paths::remove);
187-
List<RequestMatcher> delegateMatchers = getDelegateMatchers(paths);
196+
List<RequestMatcher> delegateMatchers = getDelegateMatchers(servletPath,
197+
paths);
188198
if (this.includeLinks
189199
&& StringUtils.hasText(pathMappedEndpoints.getBasePath())) {
190-
delegateMatchers.add(
191-
new AntPathRequestMatcher(pathMappedEndpoints.getBasePath()));
200+
delegateMatchers.add(new AntPathRequestMatcher(
201+
servletPath + pathMappedEndpoints.getBasePath()));
192202
}
193203
return new OrRequestMatcher(delegateMatchers);
194204
}
@@ -216,14 +226,16 @@ private String getEndpointId(Class<?> source) {
216226
return annotation.id();
217227
}
218228

219-
private List<RequestMatcher> getDelegateMatchers(Set<String> paths) {
220-
return paths.stream().map((path) -> new AntPathRequestMatcher(path + "/**"))
229+
private List<RequestMatcher> getDelegateMatchers(String servletPath,
230+
Set<String> paths) {
231+
return paths.stream()
232+
.map((path) -> new AntPathRequestMatcher(servletPath + path + "/**"))
221233
.collect(Collectors.toList());
222234
}
223235

224236
@Override
225237
protected boolean matches(HttpServletRequest request,
226-
Supplier<PathMappedEndpoints> context) {
238+
Supplier<WebApplicationContext> context) {
227239
return this.delegate.matches(request);
228240
}
229241

@@ -233,29 +245,41 @@ protected boolean matches(HttpServletRequest request,
233245
* The request matcher used to match against the links endpoint.
234246
*/
235247
public static final class LinksRequestMatcher
236-
extends ApplicationContextRequestMatcher<WebEndpointProperties> {
248+
extends ApplicationContextRequestMatcher<WebApplicationContext> {
237249

238250
private RequestMatcher delegate;
239251

240252
private LinksRequestMatcher() {
241-
super(WebEndpointProperties.class);
253+
super(WebApplicationContext.class);
242254
}
243255

244256
@Override
245-
protected void initialized(Supplier<WebEndpointProperties> properties) {
246-
this.delegate = createDelegate(properties.get());
257+
protected void initialized(
258+
Supplier<WebApplicationContext> webApplicationContext) {
259+
try {
260+
WebApplicationContext context = webApplicationContext.get();
261+
WebEndpointProperties properties = context
262+
.getBean(WebEndpointProperties.class);
263+
DispatcherServletPathProvider pathProvider = context
264+
.getBean(DispatcherServletPathProvider.class);
265+
this.delegate = createDelegate(pathProvider.getServletPath(), properties);
266+
}
267+
catch (NoSuchBeanDefinitionException ex) {
268+
this.delegate = EMPTY_MATCHER;
269+
}
247270
}
248271

249-
private RequestMatcher createDelegate(WebEndpointProperties properties) {
272+
private RequestMatcher createDelegate(String path,
273+
WebEndpointProperties properties) {
250274
if (StringUtils.hasText(properties.getBasePath())) {
251-
return new AntPathRequestMatcher(properties.getBasePath());
275+
return new AntPathRequestMatcher(path + properties.getBasePath());
252276
}
253277
return EMPTY_MATCHER;
254278
}
255279

256280
@Override
257281
protected boolean matches(HttpServletRequest request,
258-
Supplier<WebEndpointProperties> context) {
282+
Supplier<WebApplicationContext> context) {
259283
return this.delegate.matches(request);
260284
}
261285

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
2626
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
2727
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
28+
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider;
2829
import org.springframework.boot.web.servlet.error.ErrorAttributes;
2930
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
3031
import org.springframework.context.annotation.Bean;
@@ -92,4 +93,9 @@ public RequestContextFilter requestContextFilter() {
9293
return new OrderedRequestContextFilter();
9394
}
9495

96+
@Bean
97+
public DispatcherServletPathProvider childDispatcherServletPathProvider() {
98+
return () -> "";
99+
}
100+
95101
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ public ReactiveHealthIndicator reactiveHealthIndicator() {
124124
}
125125

126126
}
127+
127128
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/signalfx/SignalFxMetricsExportAutoConfigurationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public void autoConfiguresWithAnAccessToken() {
7171
@Test
7272
public void autoConfigurationCanBeDisabled() {
7373
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
74-
.withPropertyValues(
75-
"management.metrics.export.signalfx.enabled=false")
74+
.withPropertyValues("management.metrics.export.signalfx.enabled=false")
7675
.run((context) -> assertThat(context)
7776
.doesNotHaveBean(SignalFxMeterRegistry.class)
7877
.doesNotHaveBean(SignalFxConfig.class));

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimplePropertiesTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.assertj.core.api.Assertions.assertThat;
2323

2424
/**
25-
*
2625
* @author Stephane Nicoll
2726
*/
2827
public class SimplePropertiesTests {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
3131
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoint;
3232
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
33+
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider;
3334
import org.springframework.mock.web.MockHttpServletRequest;
3435
import org.springframework.mock.web.MockServletContext;
3536
import org.springframework.security.web.util.matcher.RequestMatcher;
@@ -71,6 +72,19 @@ public void toAnyEndpointShouldNotMatchOtherPath() {
7172
assertMatcher(matcher).doesNotMatch("/actuator/baz");
7273
}
7374

75+
@Test
76+
public void toAnyEndpointWhenServletPathNotEmptyShouldMatch() {
77+
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
78+
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
79+
"/actuator/foo");
80+
assertMatcher(matcher, "/actuator", "/spring").matches("/spring",
81+
"/actuator/bar");
82+
assertMatcher(matcher, "/actuator", "/spring").matches("/spring", "/actuator");
83+
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("/spring",
84+
"/actuator/baz");
85+
assertMatcher(matcher, "/actuator", "/spring").doesNotMatch("", "/actuator/foo");
86+
}
87+
7488
@Test
7589
public void toEndpointClassShouldMatchEndpointPath() {
7690
RequestMatcher matcher = EndpointRequest.to(FooEndpoint.class);
@@ -114,6 +128,14 @@ public void toLinksWhenBasePathEmptyShouldNotMatch() {
114128
assertMatcher.doesNotMatch("/");
115129
}
116130

131+
@Test
132+
public void toLinksWhenServletPathNotEmptyShouldNotMatch() {
133+
RequestMatcher matcher = EndpointRequest.toLinks();
134+
RequestMatcherAssert assertMatcher = assertMatcher(matcher, "/actuator",
135+
"/spring");
136+
assertMatcher.matches("/spring/actuator");
137+
}
138+
117139
@Test
118140
public void excludeByClassShouldNotMatchExcluded() {
119141
RequestMatcher matcher = EndpointRequest.toAnyEndpoint()
@@ -179,6 +201,11 @@ private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePa
179201
return assertMatcher(matcher, mockPathMappedEndpoints(basePath));
180202
}
181203

204+
private RequestMatcherAssert assertMatcher(RequestMatcher matcher, String basePath,
205+
String servletPath) {
206+
return assertMatcher(matcher, mockPathMappedEndpoints(basePath), servletPath);
207+
}
208+
182209
private PathMappedEndpoints mockPathMappedEndpoints(String basePath) {
183210
List<ExposableEndpoint<?>> endpoints = new ArrayList<>();
184211
endpoints.add(mockEndpoint("foo", "foo"));
@@ -195,6 +222,11 @@ private TestEndpoint mockEndpoint(String id, String rootPath) {
195222

196223
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
197224
PathMappedEndpoints pathMappedEndpoints) {
225+
return assertMatcher(matcher, pathMappedEndpoints, "");
226+
}
227+
228+
private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
229+
PathMappedEndpoints pathMappedEndpoints, String servletPath) {
198230
StaticWebApplicationContext context = new StaticWebApplicationContext();
199231
context.registerBean(WebEndpointProperties.class);
200232
if (pathMappedEndpoints != null) {
@@ -205,6 +237,8 @@ private RequestMatcherAssert assertMatcher(RequestMatcher matcher,
205237
properties.setBasePath(pathMappedEndpoints.getBasePath());
206238
}
207239
}
240+
DispatcherServletPathProvider pathProvider = () -> servletPath;
241+
context.registerBean(DispatcherServletPathProvider.class, () -> pathProvider);
208242
return assertThat(new RequestMatcherAssert(context, matcher));
209243
}
210244

@@ -219,26 +253,34 @@ private static class RequestMatcherAssert implements AssertDelegateTarget {
219253
this.matcher = matcher;
220254
}
221255

222-
public void matches(String path) {
223-
matches(mockRequest(path));
256+
public void matches(String servletPath) {
257+
matches(mockRequest(servletPath));
258+
}
259+
260+
public void matches(String servletPath, String pathInfo) {
261+
matches(mockRequest(servletPath, pathInfo));
224262
}
225263

226264
private void matches(HttpServletRequest request) {
227265
assertThat(this.matcher.matches(request))
228266
.as("Matches " + getRequestPath(request)).isTrue();
229267
}
230268

231-
public void doesNotMatch(String path) {
232-
doesNotMatch(mockRequest(path));
269+
public void doesNotMatch(String servletPath) {
270+
doesNotMatch(mockRequest(servletPath));
271+
}
272+
273+
public void doesNotMatch(String servletPath, String pathInfo) {
274+
doesNotMatch(mockRequest(servletPath, pathInfo));
233275
}
234276

235277
private void doesNotMatch(HttpServletRequest request) {
236278
assertThat(this.matcher.matches(request))
237279
.as("Does not match " + getRequestPath(request)).isFalse();
238280
}
239281

240-
private MockHttpServletRequest mockRequest(String path) {
241-
return mockRequest(null, path);
282+
private MockHttpServletRequest mockRequest(String servletPath) {
283+
return mockRequest(servletPath, null);
242284
}
243285

244286
private MockHttpServletRequest mockRequest(String servletPath, String path) {

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/MockServletWebServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/WebMvcEndpointChildContextConfigurationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.junit.Test;
2020

21+
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider;
2122
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
2223
import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
2324
import org.springframework.context.annotation.Bean;
@@ -62,6 +63,15 @@ public void contextShouldNotConfigureRequestContextFilterWhenRequestContextListe
6263
});
6364
}
6465

66+
@Test
67+
public void contextShouldConfigureDispatcherServletPathProviderWithEmptyPath() {
68+
this.contextRunner
69+
.withUserConfiguration(WebMvcEndpointChildContextConfiguration.class)
70+
.run((context) -> assertThat(context
71+
.getBean(DispatcherServletPathProvider.class).getServletPath())
72+
.isEmpty());
73+
}
74+
6575
static class ExistingConfig {
6676

6777
@Bean

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/beans/BeansEndpoint.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class BeansEndpoint {
4444
/**
4545
* Creates a new {@code BeansEndpoint} that will describe the beans in the given
4646
* {@code context} and all of its ancestors.
47-
*
4847
* @param context the application context
4948
* @see ConfigurableApplicationContext#getParent()
5049
*/

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public void serializeAsField(Object pojo, JsonGenerator jgen,
335335
}
336336
super.serializeAsField(pojo, jgen, provider, writer);
337337
}
338+
338339
}
339340

340341
/**

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/MissingParametersException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ public MissingParametersException(Set<OperationParameter> missingParameters) {
5151
public Set<OperationParameter> getMissingParameters() {
5252
return this.missingParameters;
5353
}
54+
5455
}

0 commit comments

Comments
 (0)