Skip to content

Commit 017efda

Browse files
committed
Add @EndpointServlet and migrate Jolokia
Add first class support for Servlet based endpoints and rework the Jolokia endpoint to use it. Fixes spring-projectsgh-10264
1 parent f8cdc01 commit 017efda

File tree

32 files changed

+1344
-258
lines changed

32 files changed

+1344
-258
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2018 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+
* http://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 org.springframework.boot.actuate.autoconfigure.endpoint.web;
18+
19+
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
20+
import org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar;
21+
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
26+
27+
/**
28+
* {@link ManagementContextConfiguration} for servlet endpoints.
29+
*
30+
* @author Phillip Webb
31+
*
32+
* @since 2.0.0
33+
*/
34+
@Configuration
35+
@ConditionalOnWebApplication(type = Type.SERVLET)
36+
public class ServletEndpointManagementContextConfiguration {
37+
38+
@Bean
39+
public ServletEndpointRegistrar servletEndpointRegistrar(
40+
WebEndpointProperties properties,
41+
ServletEndpointsSupplier servletEndpointsSupplier) {
42+
return new ServletEndpointRegistrar(properties.getBasePath(),
43+
servletEndpointsSupplier.getEndpoints());
44+
}
45+
46+
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java

+20
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,23 @@
3232
import org.springframework.boot.actuate.endpoint.invoke.OperationInvokerAdvisor;
3333
import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
3434
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
35+
import org.springframework.boot.actuate.endpoint.web.ExposableServletEndpoint;
3536
import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint;
3637
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
3738
import org.springframework.boot.actuate.endpoint.web.PathMapper;
3839
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
3940
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointDiscoverer;
4041
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
4142
import org.springframework.boot.actuate.endpoint.web.annotation.ExposableControllerEndpoint;
43+
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointDiscoverer;
44+
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
4245
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
4346
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
4447
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4548
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4649
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4750
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
51+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
4852
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4953
import org.springframework.context.ApplicationContext;
5054
import org.springframework.context.annotation.Bean;
@@ -138,4 +142,20 @@ public ExposeExcludePropertyEndpointFilter<ExposableControllerEndpoint> controll
138142
ExposableControllerEndpoint.class, expose, exclude);
139143
}
140144

145+
@ConditionalOnWebApplication(type = Type.SERVLET)
146+
static class WebEndpointServletAutoConfiguration {
147+
148+
@Bean
149+
@ConditionalOnMissingBean(ServletEndpointsSupplier.class)
150+
public ServletEndpointDiscoverer servletEndpointDiscoverer(
151+
ApplicationContext applicationContext, PathMapper webEndpointPathMapper,
152+
ObjectProvider<Collection<OperationInvokerAdvisor>> invokerAdvisors,
153+
ObjectProvider<Collection<EndpointFilter<ExposableServletEndpoint>>> filters) {
154+
return new ServletEndpointDiscoverer(applicationContext,
155+
webEndpointPathMapper,
156+
filters.getIfAvailable(Collections::emptyList));
157+
}
158+
159+
}
160+
141161
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2018 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+
* http://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 org.springframework.boot.actuate.autoconfigure.jolokia;
18+
19+
import java.util.Map;
20+
import java.util.function.Supplier;
21+
22+
import org.jolokia.http.AgentServlet;
23+
24+
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
25+
import org.springframework.boot.actuate.endpoint.web.EndpointServlet;
26+
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint;
27+
28+
/**
29+
* {@link Endpoint} to expose a Jolokia {@link AgentServlet}.
30+
*
31+
* @author Phillip Webb
32+
* @since 2.0.0
33+
*/
34+
@ServletEndpoint(id = "jolokia")
35+
public class JolokiaEndpoint implements Supplier<EndpointServlet> {
36+
37+
private Map<String, String> initParameters;
38+
39+
public JolokiaEndpoint(Map<String, String> initParameters) {
40+
this.initParameters = initParameters;
41+
}
42+
43+
@Override
44+
public EndpointServlet get() {
45+
return new EndpointServlet(AgentServlet.class)
46+
.withInitParameters(this.initParameters);
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-2018 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+
* http://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 org.springframework.boot.actuate.autoconfigure.jolokia;
18+
19+
import org.jolokia.http.AgentServlet;
20+
21+
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
22+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
26+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.context.annotation.Configuration;
29+
30+
/**
31+
* {@link EnableAutoConfiguration Auto-configuration} for the {@link JolokiaEndpoint}.
32+
*
33+
* @author Phillip Webb
34+
* @since 2.0.0
35+
*/
36+
@Configuration
37+
@ConditionalOnWebApplication(type = Type.SERVLET)
38+
@ConditionalOnClass(AgentServlet.class)
39+
@EnableConfigurationProperties(JolokiaProperties.class)
40+
public class JolokiaEndpointAutoConfiguration {
41+
42+
@Bean
43+
@ConditionalOnEnabledEndpoint
44+
public JolokiaEndpoint jolokiaEndpoint(JolokiaProperties properties) {
45+
return new JolokiaEndpoint(properties.getConfig());
46+
}
47+
48+
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaManagementContextConfiguration.java

-81
This file was deleted.

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaProperties.java

+2-28
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.
@@ -29,41 +29,15 @@
2929
* @author Stephane Nicoll
3030
* @since 2.0.0
3131
*/
32-
@ConfigurationProperties(prefix = "management.jolokia")
32+
@ConfigurationProperties(prefix = "management.endpoint.jolokia")
3333
public class JolokiaProperties {
3434

35-
/**
36-
* Whether to enable Jolokia.
37-
*/
38-
private boolean enabled;
39-
40-
/**
41-
* Path at which Jolokia is available.
42-
*/
43-
private String path = "/jolokia";
44-
4535
/**
4636
* Jolokia settings. These are traditionally set using servlet parameters. Refer to
4737
* the documentation of Jolokia for more details.
4838
*/
4939
private final Map<String, String> config = new HashMap<>();
5040

51-
public boolean isEnabled() {
52-
return this.enabled;
53-
}
54-
55-
public void setEnabled(boolean enabled) {
56-
this.enabled = enabled;
57-
}
58-
59-
public String getPath() {
60-
return this.path;
61-
}
62-
63-
public void setPath(String path) {
64-
this.path = path;
65-
}
66-
6741
public Map<String, String> getConfig() {
6842
return this.config;
6943
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@
795795
"type": "java.lang.String",
796796
"description": "Endpoint URL path.",
797797
"deprecation": {
798-
"reason": "Endpoint path is no longer customizable.",
798+
"replacement": "management.endpoints.web.path-mapping.jolokia",
799799
"level": "error"
800800
}
801801
},
@@ -1734,4 +1734,3 @@
17341734
}
17351735
]
17361736
}
1737-

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ org.springframework.boot.actuate.autoconfigure.info.InfoContributorAutoConfigura
2323
org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration,\
2424
org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration,\
2525
org.springframework.boot.actuate.autoconfigure.jms.JmsHealthIndicatorAutoConfiguration,\
26+
org.springframework.boot.actuate.autoconfigure.jolokia.JolokiaEndpointAutoConfiguration,\
2627
org.springframework.boot.actuate.autoconfigure.ldap.LdapHealthIndicatorAutoConfiguration,\
2728
org.springframework.boot.actuate.autoconfigure.liquibase.LiquibaseEndpointAutoConfiguration,\
2829
org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointAutoConfiguration,\
@@ -47,10 +48,10 @@ org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoC
4748
org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration
4849

4950
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
51+
org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration,\
5052
org.springframework.boot.actuate.autoconfigure.endpoint.web.reactive.WebFluxEndpointManagementContextConfiguration,\
5153
org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration,\
5254
org.springframework.boot.actuate.autoconfigure.endpoint.web.jersey.JerseyWebEndpointManagementContextConfiguration,\
53-
org.springframework.boot.actuate.autoconfigure.jolokia.JolokiaManagementContextConfiguration,\
5455
org.springframework.boot.actuate.autoconfigure.web.jersey.JerseyManagementChildContextConfiguration,\
5556
org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration,\
5657
org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration,\

0 commit comments

Comments
 (0)