Ensure endpoints.jolokia.enabled=false switches off jolokia

pull/138/head
Dave Syer 11 years ago
parent 564475556e
commit 94e2f90793

@ -28,6 +28,8 @@ import org.springframework.http.HttpMethod;
@ConfigurationProperties(name = "endpoints.jolokia", ignoreUnknownFields = false)
public class JolokiaEndpoint extends AbstractEndpoint<String> {
private boolean enabled = true;
public JolokiaEndpoint() {
super("/jolokia");
}
@ -41,4 +43,12 @@ public class JolokiaEndpoint extends AbstractEndpoint<String> {
public HttpMethod[] methods() {
return NO_HTTP_METHOD;
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

@ -22,12 +22,14 @@ import javax.servlet.ServletRegistration;
import org.jolokia.http.AgentServlet;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.TestUtils;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory.RegisteredServlet;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -62,6 +64,16 @@ public class JolokiaAutoConfigurationTests {
assertEquals(1, this.context.getBeanNamesForType(AgentServlet.class).length);
}
@Test
public void agentDisabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
TestUtils.addEnviroment(this.context, "endpoints.jolokia.enabled:false");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
JolokiaAutoConfiguration.class);
this.context.refresh();
assertEquals(0, this.context.getBeanNamesForType(AgentServlet.class).length);
}
@Test
public void agentServletRegisteredWithServletContainer() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
@ -83,6 +95,7 @@ public class JolokiaAutoConfigurationTests {
}
@Configuration
@EnableConfigurationProperties
protected static class Config {
protected static MockEmbeddedServletContainerFactory containerFactory = null;

@ -85,7 +85,7 @@ public class AutoConfigurationReportLoggingInitializer implements
logAutoConfigurationReport(!this.applicationContext.isActive());
}
void logAutoConfigurationReport(boolean isCrashReport) {
public void logAutoConfigurationReport(boolean isCrashReport) {
if (this.report == null) {
this.report = AutoConfigurationReport.get(this.applicationContext
.getBeanFactory());

Loading…
Cancel
Save