Polish
This commit is contained in:
parent
d07e18143d
commit
fbf34e261e
|
|
@ -32,11 +32,24 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@ManagedResource
|
@ManagedResource
|
||||||
public class DataEndpointMBean extends EndpointMBean {
|
public class DataEndpointMBean extends EndpointMBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link DataEndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @deprecated since 1.3 in favor of
|
||||||
|
* {@link #DataEndpointMBean(String, Endpoint, ObjectMapper)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DataEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
public DataEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||||
super(beanName, endpoint);
|
super(beanName, endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link DataEndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||||
|
*/
|
||||||
public DataEndpointMBean(String beanName, Endpoint<?> endpoint,
|
public DataEndpointMBean(String beanName, Endpoint<?> endpoint,
|
||||||
ObjectMapper objectMapper) {
|
ObjectMapper objectMapper) {
|
||||||
super(beanName, endpoint, objectMapper);
|
super(beanName, endpoint, objectMapper);
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,24 @@ public class EndpointMBean {
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @deprecated since 1.3 in favor of
|
||||||
|
* {@link #EndpointMBean(String, Endpoint, ObjectMapper)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public EndpointMBean(String beanName, Endpoint<?> endpoint) {
|
public EndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||||
this(beanName, endpoint, new ObjectMapper());
|
this(beanName, endpoint, new ObjectMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||||
|
*/
|
||||||
public EndpointMBean(String beanName, Endpoint<?> endpoint, ObjectMapper objectMapper) {
|
public EndpointMBean(String beanName, Endpoint<?> endpoint, ObjectMapper objectMapper) {
|
||||||
Assert.notNull(beanName, "BeanName must not be null");
|
Assert.notNull(beanName, "BeanName must not be null");
|
||||||
Assert.notNull(endpoint, "Endpoint must not be null");
|
Assert.notNull(endpoint, "Endpoint must not be null");
|
||||||
|
|
@ -71,15 +84,12 @@ public class EndpointMBean {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result instanceof String) {
|
if (result instanceof String) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.getClass().isArray() || result instanceof List) {
|
if (result.getClass().isArray() || result instanceof List) {
|
||||||
return this.mapper.convertValue(result, List.class);
|
return this.mapper.convertValue(result, List.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mapper.convertValue(result, Map.class);
|
return this.mapper.convertValue(result, Map.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,19 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointMBeanExporter} instance.
|
||||||
|
*/
|
||||||
public EndpointMBeanExporter() {
|
public EndpointMBeanExporter() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointMBeanExporter} instance.
|
||||||
|
* @param objectMapper the object mapper
|
||||||
|
*/
|
||||||
public EndpointMBeanExporter(ObjectMapper objectMapper) {
|
public EndpointMBeanExporter(ObjectMapper objectMapper) {
|
||||||
this.objectMapper = objectMapper == null ? new ObjectMapper() : objectMapper;
|
this.objectMapper = (objectMapper == null ? new ObjectMapper() : objectMapper);
|
||||||
setAutodetect(false);
|
setAutodetect(false);
|
||||||
setNamingStrategy(this.defaultNamingStrategy);
|
setNamingStrategy(this.defaultNamingStrategy);
|
||||||
setAssembler(this.assembler);
|
setAssembler(this.assembler);
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,27 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@ManagedResource
|
@ManagedResource
|
||||||
public class ShutdownEndpointMBean extends EndpointMBean {
|
public class ShutdownEndpointMBean extends EndpointMBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ShutdownEndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @deprecated since 1.3 in favor of
|
||||||
|
* {@link #ShutdownEndpointMBean(String, Endpoint, ObjectMapper)}
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint) {
|
||||||
super(beanName, endpoint);
|
super(beanName, endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ShutdownEndpointMBean} instance.
|
||||||
|
* @param beanName the bean name
|
||||||
|
* @param endpoint the endpoint to wrap
|
||||||
|
* @param objectMapper the {@link ObjectMapper} used to convert the payload
|
||||||
|
*/
|
||||||
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint,
|
public ShutdownEndpointMBean(String beanName, Endpoint<?> endpoint,
|
||||||
ObjectMapper mapper) {
|
ObjectMapper objectMapper) {
|
||||||
super(beanName, endpoint, mapper);
|
super(beanName, endpoint, objectMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManagedOperation(description = "Shutdown the ApplicationContext")
|
@ManagedOperation(description = "Shutdown the ApplicationContext")
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,7 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo(
|
MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo(
|
||||||
getObjectName("endpoint1", this.context));
|
getObjectName("endpoint1", this.context));
|
||||||
assertNotNull(mbeanInfo);
|
assertNotNull(mbeanInfo);
|
||||||
|
|
@ -93,9 +91,7 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint2", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint2", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
getObjectName("endpoint1", this.context)));
|
getObjectName("endpoint1", this.context)));
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
|
|
@ -113,9 +109,7 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
getObjectName("test-domain", "endpoint1", false, this.context)));
|
getObjectName("test-domain", "endpoint1", false, this.context)));
|
||||||
}
|
}
|
||||||
|
|
@ -132,9 +126,7 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
getObjectName("test-domain", "endpoint1", true, this.context)));
|
getObjectName("test-domain", "endpoint1", true, this.context)));
|
||||||
}
|
}
|
||||||
|
|
@ -156,9 +148,7 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
ObjectNameManager.getInstance(getObjectName("test-domain", "endpoint1",
|
ObjectNameManager.getInstance(getObjectName("test-domain", "endpoint1",
|
||||||
true, this.context).toString()
|
true, this.context).toString()
|
||||||
|
|
@ -173,13 +163,10 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
TestEndpoint.class));
|
TestEndpoint.class));
|
||||||
GenericApplicationContext parent = new GenericApplicationContext();
|
GenericApplicationContext parent = new GenericApplicationContext();
|
||||||
|
|
||||||
this.context.setParent(parent);
|
this.context.setParent(parent);
|
||||||
parent.refresh();
|
parent.refresh();
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
|
|
||||||
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
assertNotNull(mbeanExporter.getServer().getMBeanInfo(
|
||||||
getObjectName("endpoint1", this.context)));
|
getObjectName("endpoint1", this.context)));
|
||||||
|
|
||||||
|
|
@ -194,12 +181,10 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
JsonConversionEndpoint.class));
|
JsonConversionEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
Object response = mbeanExporter.getServer().invoke(
|
Object response = mbeanExporter.getServer().invoke(
|
||||||
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
||||||
new String[0]);
|
new String[0]);
|
||||||
|
|
||||||
assertThat(response, is(instanceOf(Map.class)));
|
assertThat(response, is(instanceOf(Map.class)));
|
||||||
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(Long.class)));
|
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(Long.class)));
|
||||||
}
|
}
|
||||||
|
|
@ -217,12 +202,10 @@ public class EndpointMBeanExporterTests {
|
||||||
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(
|
||||||
JsonConversionEndpoint.class));
|
JsonConversionEndpoint.class));
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
|
|
||||||
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
|
||||||
Object response = mbeanExporter.getServer().invoke(
|
Object response = mbeanExporter.getServer().invoke(
|
||||||
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
getObjectName("endpoint1", this.context), "getData", new Object[0],
|
||||||
new String[0]);
|
new String[0]);
|
||||||
|
|
||||||
assertThat(response, is(instanceOf(Map.class)));
|
assertThat(response, is(instanceOf(Map.class)));
|
||||||
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(String.class)));
|
assertThat(((Map<?, ?>) response).get("date"), is(instanceOf(String.class)));
|
||||||
}
|
}
|
||||||
|
|
@ -242,10 +225,8 @@ public class EndpointMBeanExporterTests {
|
||||||
.getIdentityHexString(applicationContext
|
.getIdentityHexString(applicationContext
|
||||||
.getBean(beanKey))));
|
.getBean(beanKey))));
|
||||||
}
|
}
|
||||||
else {
|
return ObjectNameManager.getInstance(String.format("%s:type=Endpoint,name=%s",
|
||||||
return ObjectNameManager.getInstance(String.format(
|
domain, beanKey));
|
||||||
"%s:type=Endpoint,name=%s", domain, beanKey));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TestEndpoint extends AbstractEndpoint<String> {
|
public static class TestEndpoint extends AbstractEndpoint<String> {
|
||||||
|
|
@ -258,6 +239,7 @@ public class EndpointMBeanExporterTests {
|
||||||
public String invoke() {
|
public String invoke() {
|
||||||
return "hello world";
|
return "hello world";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class JsonConversionEndpoint extends
|
public static class JsonConversionEndpoint extends
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,7 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
||||||
this.beanClassLoader)));
|
this.beanClassLoader)));
|
||||||
|
|
||||||
// Remove those specifically disabled
|
// Remove those specifically disabled
|
||||||
List<String> excluded = new ArrayList<String>(Arrays.asList(attributes
|
List<String> excluded = Arrays.asList(attributes.getStringArray("exclude"));
|
||||||
.getStringArray("exclude")));
|
|
||||||
factories.removeAll(excluded);
|
factories.removeAll(excluded);
|
||||||
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.condition;
|
package org.springframework.boot.autoconfigure.condition;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
@ -87,7 +88,7 @@ public class ConditionEvaluationReport {
|
||||||
*/
|
*/
|
||||||
public void recordExclusions(List<String> exclusions) {
|
public void recordExclusions(List<String> exclusions) {
|
||||||
Assert.notNull(exclusions, "exclusions must not be null");
|
Assert.notNull(exclusions, "exclusions must not be null");
|
||||||
this.exclusions = exclusions;
|
this.exclusions = new ArrayList<String>(exclusions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,14 +107,6 @@ public class ConditionEvaluationReport {
|
||||||
return Collections.unmodifiableMap(this.outcomes);
|
return Collections.unmodifiableMap(this.outcomes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the classes that have been excluded from condition evaluation.
|
|
||||||
* @return the names of the excluded classes
|
|
||||||
*/
|
|
||||||
public List<String> getExclusions() {
|
|
||||||
return Collections.unmodifiableList(this.exclusions);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNoMatchOutcomeToAncestors(String source) {
|
private void addNoMatchOutcomeToAncestors(String source) {
|
||||||
String prefix = source + "$";
|
String prefix = source + "$";
|
||||||
for (Entry<String, ConditionAndOutcomes> entry : this.outcomes.entrySet()) {
|
for (Entry<String, ConditionAndOutcomes> entry : this.outcomes.entrySet()) {
|
||||||
|
|
@ -125,6 +118,14 @@ public class ConditionEvaluationReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the classes that have been excluded from condition evaluation.
|
||||||
|
* @return the names of the excluded classes
|
||||||
|
*/
|
||||||
|
public List<String> getExclusions() {
|
||||||
|
return Collections.unmodifiableList(this.exclusions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The parent report (from a parent BeanFactory if there is one).
|
* The parent report (from a parent BeanFactory if there is one).
|
||||||
* @return the parent report (or null if there isn't one)
|
* @return the parent report (or null if there isn't one)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue