Commit b16a973d authored by Josh Thornhill's avatar Josh Thornhill Committed by Andy Wilkinson

Honor the endpoint.enabled property when registering MBeans

Fixes gh-2873
Closes gh-2890
parent ef49ced1
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -138,7 +138,8 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc ...@@ -138,7 +138,8 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
protected void locateAndRegisterEndpoints() { protected void locateAndRegisterEndpoints() {
Map<String, Endpoint> endpoints = this.beanFactory.getBeansOfType(Endpoint.class); Map<String, Endpoint> endpoints = this.beanFactory.getBeansOfType(Endpoint.class);
for (Map.Entry<String, Endpoint> endpointEntry : endpoints.entrySet()) { for (Map.Entry<String, Endpoint> endpointEntry : endpoints.entrySet()) {
if (!this.registeredEndpoints.contains(endpointEntry.getValue())) { if (!this.registeredEndpoints.contains(endpointEntry.getValue())
&& endpointEntry.getValue().isEnabled()) {
registerEndpoint(endpointEntry.getKey(), endpointEntry.getValue()); registerEndpoint(endpointEntry.getKey(), endpointEntry.getValue());
this.registeredEndpoints.add(endpointEntry.getValue()); this.registeredEndpoints.add(endpointEntry.getValue());
} }
......
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -37,7 +37,9 @@ import org.springframework.jmx.support.ObjectNameManager; ...@@ -37,7 +37,9 @@ import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link EndpointMBeanExporter} * Tests for {@link EndpointMBeanExporter}
...@@ -73,6 +75,36 @@ public class EndpointMBeanExporterTests { ...@@ -73,6 +75,36 @@ public class EndpointMBeanExporterTests {
assertEquals(3, mbeanInfo.getAttributes().length); assertEquals(3, mbeanInfo.getAttributes().length);
} }
@Test
public void testSkipRegistrationOfDisabledEndpoint() throws Exception {
this.context = new GenericApplicationContext();
this.context.registerBeanDefinition("endpointMbeanExporter",
new RootBeanDefinition(EndpointMBeanExporter.class));
MutablePropertyValues mvp = new MutablePropertyValues();
mvp.add("enabled", Boolean.FALSE);
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
TestEndpoint.class, null, mvp));
this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertFalse(mbeanExporter.getServer().isRegistered(
getObjectName("endpoint1", this.context)));
}
@Test
public void testRegistrationOfEnabledEndpoint() throws Exception {
this.context = new GenericApplicationContext();
this.context.registerBeanDefinition("endpointMbeanExporter",
new RootBeanDefinition(EndpointMBeanExporter.class));
MutablePropertyValues mvp = new MutablePropertyValues();
mvp.add("enabled", Boolean.TRUE);
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
TestEndpoint.class, null, mvp));
this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertTrue(mbeanExporter.getServer().isRegistered(
getObjectName("endpoint1", this.context)));
}
@Test @Test
public void testRegistrationTwoEndpoints() throws Exception { public void testRegistrationTwoEndpoints() throws Exception {
this.context = new GenericApplicationContext(); this.context = new GenericApplicationContext();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment