Move JolokiaEndpoint so it is not an Endpoint
This commit is contained in:
@@ -20,7 +20,8 @@ import java.util.Map;
|
||||
|
||||
import org.jolokia.http.AgentServlet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.JolokiaEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.JolokiaMvcEndpoint;
|
||||
import org.springframework.boot.actuate.properties.ManagementServerProperties;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -65,6 +66,9 @@ public class JolokiaAutoConfiguration {
|
||||
|
||||
private RelaxedPropertyResolver environment;
|
||||
|
||||
@Autowired
|
||||
private ManagementServerProperties management;
|
||||
|
||||
@Autowired
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = new RelaxedPropertyResolver(environment);
|
||||
@@ -77,19 +81,17 @@ public class JolokiaAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean()
|
||||
public ServletRegistrationBean jolokiaServletRegistration() {
|
||||
ServletRegistrationBean registrationBean = new ServletRegistrationBean(
|
||||
jolokiaServlet(), this.environment.getProperty("endpoints.jolokia.path",
|
||||
"/jolokia") + "/*");
|
||||
public ServletRegistrationBean jolokiaServletRegistration(AgentServlet servlet) {
|
||||
ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet,
|
||||
this.management.getContextPath() + jolokiaEndpoint().getPath() + "/*");
|
||||
addInitParameters(registrationBean);
|
||||
return registrationBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JolokiaEndpoint jolokiaEndpoint() {
|
||||
return new JolokiaEndpoint();
|
||||
public JolokiaMvcEndpoint jolokiaEndpoint() {
|
||||
return new JolokiaMvcEndpoint();
|
||||
}
|
||||
|
||||
protected void addInitParameters(ServletRegistrationBean registrationBean) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import javax.servlet.Filter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
|
||||
import org.springframework.boot.actuate.properties.ManagementServerProperties;
|
||||
import org.springframework.boot.actuate.web.ErrorController;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
@@ -211,9 +212,9 @@ public class ManagementSecurityAutoConfiguration {
|
||||
return NO_PATHS;
|
||||
}
|
||||
|
||||
Set<? extends Endpoint<?>> endpoints = endpointHandlerMapping.getEndpoints();
|
||||
Set<? extends MvcEndpoint> endpoints = endpointHandlerMapping.getEndpoints();
|
||||
List<String> paths = new ArrayList<String>(endpoints.size());
|
||||
for (Endpoint<?> endpoint : endpoints) {
|
||||
for (MvcEndpoint endpoint : endpoints) {
|
||||
if (endpoint.isSensitive() == secure) {
|
||||
paths.add(endpoint.getPath());
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
/**
|
||||
* {@link RuntimeException} indicating an {@link Endpoint} implementation is not enabled.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
public class EndpointDisabledException extends RuntimeException {
|
||||
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping impleme
|
||||
/**
|
||||
* Return the endpoints
|
||||
*/
|
||||
public Set<? extends Endpoint<?>> getEndpoints() {
|
||||
public Set<? extends MvcEndpoint> getEndpoints() {
|
||||
return this.endpoints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -25,14 +29,48 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
@ConfigurationProperties(name = "endpoints.jolokia", ignoreUnknownFields = false)
|
||||
public class JolokiaEndpoint extends AbstractEndpoint<String> {
|
||||
public class JolokiaMvcEndpoint implements MvcEndpoint {
|
||||
|
||||
public JolokiaEndpoint() {
|
||||
super("/jolokia");
|
||||
@NotNull
|
||||
@Pattern(regexp = "/[^/]*", message = "Path must start with /")
|
||||
private String path;
|
||||
|
||||
private boolean sensitive;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public JolokiaMvcEndpoint() {
|
||||
this.path = "/jolokia";
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String invoke() {
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSensitive() {
|
||||
return this.sensitive;
|
||||
}
|
||||
|
||||
public void setSensitive(boolean sensitive) {
|
||||
this.sensitive = sensitive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getEndpointType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,11 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface MvcEndpoint extends Endpoint<Object> {
|
||||
public interface MvcEndpoint {
|
||||
|
||||
String getPath();
|
||||
|
||||
boolean isSensitive();
|
||||
|
||||
Class<?> getEndpointType();
|
||||
|
||||
|
||||
@@ -60,7 +60,9 @@ public class JolokiaAutoConfigurationTests {
|
||||
public void agentServletRegisteredWithAppContext() throws Exception {
|
||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||
this.context.register(Config.class, WebMvcAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
|
||||
ManagementServerPropertiesAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class,
|
||||
JolokiaAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(1, this.context.getBeanNamesForType(AgentServlet.class).length);
|
||||
}
|
||||
@@ -70,7 +72,9 @@ public class JolokiaAutoConfigurationTests {
|
||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||
TestUtils.addEnviroment(this.context, "endpoints.jolokia.enabled:false");
|
||||
this.context.register(Config.class, WebMvcAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
|
||||
ManagementServerPropertiesAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class,
|
||||
JolokiaAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertEquals(0, this.context.getBeanNamesForType(AgentServlet.class).length);
|
||||
}
|
||||
@@ -79,7 +83,9 @@ public class JolokiaAutoConfigurationTests {
|
||||
public void agentServletRegisteredWithServletContainer() throws Exception {
|
||||
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||
this.context.register(Config.class, WebMvcAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
|
||||
ManagementServerPropertiesAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class,
|
||||
JolokiaAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
Servlet servlet = null;
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
public class JolokiaEndpointTests extends AbstractEndpointTests<JolokiaEndpoint> {
|
||||
|
||||
public JolokiaEndpointTests() {
|
||||
super(Config.class, JolokiaEndpoint.class, "/jolokia", true, "endpoints.jolokia");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public static class Config {
|
||||
|
||||
@Bean
|
||||
public JolokiaEndpoint endpoint() {
|
||||
return new JolokiaEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.JolokiaEndpointTests.Config;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Christian Dupuis
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = { Config.class })
|
||||
@WebAppConfiguration
|
||||
public class JolokiaEndpointTests {
|
||||
|
||||
@Autowired
|
||||
private MvcEndpoints endpoints;
|
||||
|
||||
@Test
|
||||
public void endpointRegistered() throws Exception {
|
||||
assertEquals(1, this.endpoints.getEndpoints().size());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@EnableWebMvc
|
||||
@Import(EndpointWebMvcAutoConfiguration.class)
|
||||
public static class Config {
|
||||
|
||||
@Bean
|
||||
public JolokiaMvcEndpoint endpoint() {
|
||||
return new JolokiaMvcEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user