Rename EndpointType to EndpointExposure

Closes gh-10100
This commit is contained in:
Stephane Nicoll 2017-08-29 11:50:27 +02:00
parent f9e5b07eec
commit 3ef3b40783
16 changed files with 113 additions and 114 deletions

View File

@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.context.annotation.Conditional;
/**
@ -33,7 +33,7 @@ import org.springframework.context.annotation.Conditional;
* <p>
* If no specific {@code endpoints.<id>.*} or {@code endpoints.default.*} properties are
* defined, the condition matches the {@code enabledByDefault} value regardless of the
* specific {@link EndpointDelivery}, if any. If any property are set, they are evaluated
* specific {@link EndpointExposure}, if any. If any property are set, they are evaluated
* with a sensible order of precedence.
* <p>
* For instance if {@code endpoints.default.enabled} is {@code false} but

View File

@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.jmx.JmxEndpointExtension;
import org.springframework.boot.endpoint.web.WebEndpointExtension;
import org.springframework.context.annotation.Bean;
@ -104,10 +104,10 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
if (endpoint == null) {
return null;
}
// If both types are set, all delivery technologies are exposed
EndpointDelivery[] delivery = endpoint.delivery();
// If both types are set, all exposure technologies are exposed
EndpointExposure[] exposures = endpoint.exposure();
return new EndpointAttributes(endpoint.id(), endpoint.enabledByDefault(),
(delivery.length == 1 ? delivery[0] : null));
(exposures.length == 1 ? exposures[0] : null));
}
private static class EndpointAttributes {
@ -116,19 +116,19 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
private final boolean enabled;
private final EndpointDelivery delivery;
private final EndpointExposure exposure;
EndpointAttributes(String id, boolean enabled, EndpointDelivery delivery) {
EndpointAttributes(String id, boolean enabled, EndpointExposure exposure) {
if (!StringUtils.hasText(id)) {
throw new IllegalStateException("Endpoint id could not be determined");
}
this.id = id;
this.enabled = enabled;
this.delivery = delivery;
this.exposure = exposure;
}
public EndpointEnablement getEnablement(EndpointEnablementProvider provider) {
return provider.getEndpointEnablement(this.id, this.enabled, this.delivery);
return provider.getEndpointEnablement(this.id, this.enabled, this.exposure);
}
}

View File

@ -34,7 +34,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.endpoint.ConversionServiceOperationParameterMapper;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.OperationParameterMapper;
import org.springframework.boot.endpoint.jmx.EndpointMBeanRegistrar;
import org.springframework.boot.endpoint.jmx.JmxAnnotationEndpointDiscoverer;
@ -102,7 +102,7 @@ public class EndpointInfrastructureAutoConfiguration {
ObjectProvider<ObjectMapper> objectMapper) {
EndpointProvider<JmxEndpointOperation> endpointProvider = new EndpointProvider<>(
this.applicationContext.getEnvironment(), endpointDiscoverer,
EndpointDelivery.JMX);
EndpointExposure.JMX);
EndpointMBeanRegistrar endpointMBeanRegistrar = new EndpointMBeanRegistrar(
mBeanServer, new DefaultEndpointObjectNameFactory(properties, mBeanServer,
ObjectUtils.getIdentityHexString(this.applicationContext)));
@ -127,7 +127,7 @@ public class EndpointInfrastructureAutoConfiguration {
return new EndpointProvider<>(this.applicationContext.getEnvironment(),
webEndpointDiscoverer(operationParameterMapper,
cachingConfigurationFactory),
EndpointDelivery.WEB);
EndpointExposure.WEB);
}
private WebAnnotationEndpointDiscoverer webEndpointDiscoverer(

View File

@ -20,8 +20,8 @@ import java.util.Collection;
import java.util.stream.Collectors;
import org.springframework.boot.actuate.autoconfigure.endpoint.support.EndpointEnablementProvider;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointDiscoverer;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.EndpointInfo;
import org.springframework.boot.endpoint.Operation;
import org.springframework.core.env.Environment;
@ -40,19 +40,19 @@ public final class EndpointProvider<T extends Operation> {
private final EndpointEnablementProvider endpointEnablementProvider;
private final EndpointDelivery delivery;
private final EndpointExposure exposure;
/**
* Creates a new instance.
* @param environment the environment to use to check the endpoints that are enabled
* @param discoverer the discoverer to get the initial set of endpoints
* @param delivery the delivery technology for the endpoint
* @param exposure the exposure technology for the endpoint
*/
public EndpointProvider(Environment environment, EndpointDiscoverer<T> discoverer,
EndpointDelivery delivery) {
EndpointExposure exposure) {
this.discoverer = discoverer;
this.endpointEnablementProvider = new EndpointEnablementProvider(environment);
this.delivery = delivery;
this.exposure = exposure;
}
public Collection<EndpointInfo<T>> getEndpoints() {
@ -62,7 +62,7 @@ public final class EndpointProvider<T extends Operation> {
private boolean isEnabled(EndpointInfo<?> endpoint) {
return this.endpointEnablementProvider.getEndpointEnablement(endpoint.getId(),
endpoint.isEnabledByDefault(), this.delivery).isEnabled();
endpoint.isEnabledByDefault(), this.exposure).isEnabled();
}
}

View File

@ -16,7 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.support;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
@ -54,16 +54,16 @@ public class EndpointEnablementProvider {
* Return the {@link EndpointEnablement} of an endpoint for a specific tech exposure.
* @param endpointId the id of the endpoint
* @param enabledByDefault whether the endpoint is enabled by default or not
* @param delivery the requested {@link EndpointDelivery}
* @param exposure the requested {@link EndpointExposure}
* @return the {@link EndpointEnablement} of that endpoint for the specified
* {@link EndpointDelivery}
* {@link EndpointExposure}
*/
public EndpointEnablement getEndpointEnablement(String endpointId,
boolean enabledByDefault, EndpointDelivery delivery) {
boolean enabledByDefault, EndpointExposure exposure) {
Assert.hasText(endpointId, "Endpoint id must have a value");
Assert.isTrue(!endpointId.equals("default"), "Endpoint id 'default' is a reserved "
+ "value and cannot be used by an endpoint");
EndpointEnablement result = findEnablement(endpointId, delivery);
EndpointEnablement result = findEnablement(endpointId, exposure);
if (result != null) {
return result;
}
@ -74,23 +74,23 @@ public class EndpointEnablementProvider {
// All endpoints specific attributes have been looked at. Checking default value
// for the endpoint
if (!enabledByDefault) {
return getDefaultEndpointEnablement(endpointId, false, delivery);
return getDefaultEndpointEnablement(endpointId, false, exposure);
}
return getGlobalEndpointEnablement(endpointId, enabledByDefault,
delivery);
exposure);
}
private EndpointEnablement findEnablement(String endpointId,
EndpointDelivery delivery) {
if (delivery != null) {
return findEnablement(getKey(endpointId, delivery));
EndpointExposure exposure) {
if (exposure != null) {
return findEnablement(getKey(endpointId, exposure));
}
return findEnablementForAnyDeliveryTechnology(endpointId);
return findEnablementForAnyExposureTechnology(endpointId);
}
private EndpointEnablement getGlobalEndpointEnablement(String endpointId,
boolean enabledByDefault, EndpointDelivery delivery) {
EndpointEnablement result = findGlobalEndpointEnablement(delivery);
boolean enabledByDefault, EndpointExposure exposure) {
EndpointEnablement result = findGlobalEndpointEnablement(exposure);
if (result != null) {
return result;
}
@ -99,27 +99,27 @@ public class EndpointEnablementProvider {
return result;
}
return getDefaultEndpointEnablement(endpointId, enabledByDefault,
delivery);
exposure);
}
private EndpointEnablement findGlobalEndpointEnablement(
EndpointDelivery delivery) {
if (delivery != null) {
EndpointEnablement result = findEnablement(getKey("default", delivery));
EndpointExposure exposure) {
if (exposure != null) {
EndpointEnablement result = findEnablement(getKey("default", exposure));
if (result != null) {
return result;
}
if (!delivery.isEnabledByDefault()) {
return getDefaultEndpointEnablement("default", false, delivery);
if (!exposure.isEnabledByDefault()) {
return getDefaultEndpointEnablement("default", false, exposure);
}
return null;
}
return findEnablementForAnyDeliveryTechnology("default");
return findEnablementForAnyExposureTechnology("default");
}
private EndpointEnablement findEnablementForAnyDeliveryTechnology(String endpointId) {
for (EndpointDelivery candidate : EndpointDelivery.values()) {
EndpointEnablement result = findEnablementForDeliveryTechnology(endpointId,
private EndpointEnablement findEnablementForAnyExposureTechnology(String endpointId) {
for (EndpointExposure candidate : EndpointExposure.values()) {
EndpointEnablement result = findEnablementForExposureTechnology(endpointId,
candidate);
if (result != null && result.isEnabled()) {
return result;
@ -128,34 +128,33 @@ public class EndpointEnablementProvider {
return null;
}
private EndpointEnablement findEnablementForDeliveryTechnology(String endpointId,
EndpointDelivery delivery) {
String endpointTypeKey = getKey(endpointId, delivery);
EndpointEnablement endpointTypeSpecificOutcome = findEnablement(endpointTypeKey);
return endpointTypeSpecificOutcome;
private EndpointEnablement findEnablementForExposureTechnology(String endpointId,
EndpointExposure exposure) {
String endpointTypeKey = getKey(endpointId, exposure);
return findEnablement(endpointTypeKey);
}
private EndpointEnablement getDefaultEndpointEnablement(String endpointId,
boolean enabledByDefault, EndpointDelivery delivery) {
boolean enabledByDefault, EndpointExposure exposure) {
return new EndpointEnablement(enabledByDefault, createDefaultEnablementMessage(
endpointId, enabledByDefault, delivery));
endpointId, enabledByDefault, exposure));
}
private String createDefaultEnablementMessage(String endpointId,
boolean enabledByDefault, EndpointDelivery delivery) {
boolean enabledByDefault, EndpointExposure exposure) {
StringBuilder message = new StringBuilder();
message.append(String.format("endpoint '%s' ", endpointId));
if (delivery != null) {
if (exposure != null) {
message.append(
String.format("(%s) ", delivery.name().toLowerCase()));
String.format("(%s) ", exposure.name().toLowerCase()));
}
message.append(String.format("is %s by default",
(enabledByDefault ? "enabled" : "disabled")));
return message.toString();
}
private String getKey(String endpointId, EndpointDelivery delivery) {
return getKey(endpointId, delivery.name().toLowerCase() + ".enabled");
private String getKey(String endpointId, EndpointExposure exposure) {
return getKey(endpointId, exposure.name().toLowerCase() + ".enabled");
}
private String getKey(String endpointId, String suffix) {

View File

@ -36,7 +36,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.ReadOperation;
import org.springframework.boot.endpoint.web.WebEndpointResponse;
import org.springframework.core.io.FileSystemResource;
@ -55,7 +55,7 @@ import org.springframework.util.ReflectionUtils;
* @since 2.0.0
*/
@ConfigurationProperties(prefix = "endpoints.heapdump")
@Endpoint(id = "heapdump", delivery = EndpointDelivery.WEB)
@Endpoint(id = "heapdump", exposure = EndpointExposure.WEB)
public class HeapDumpWebEndpoint {
private final long timeout;

View File

@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.ReadOperation;
import org.springframework.boot.logging.LogFile;
import org.springframework.core.env.Environment;
@ -39,7 +39,7 @@ import org.springframework.core.io.Resource;
* @since 2.0.0
*/
@ConfigurationProperties(prefix = "endpoints.logfile")
@Endpoint(id = "logfile", delivery = EndpointDelivery.WEB)
@Endpoint(id = "logfile", exposure = EndpointExposure.WEB)
public class LogFileWebEndpoint {
private static final Log logger = LogFactory.getLog(LogFileWebEndpoint.class);

View File

@ -19,7 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint;
import org.junit.Test;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.jmx.JmxEndpointExtension;
import org.springframework.boot.endpoint.web.WebEndpointExtension;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@ -297,8 +297,8 @@ public class ConditionalOnEnabledEndpointTests {
}
@Endpoint(id = "bar", delivery = { EndpointDelivery.WEB,
EndpointDelivery.JMX }, enabledByDefault = false)
@Endpoint(id = "bar", exposure = { EndpointExposure.WEB,
EndpointExposure.JMX }, enabledByDefault = false)
static class BarEndpoint {
}
@ -314,7 +314,7 @@ public class ConditionalOnEnabledEndpointTests {
}
@Endpoint(id = "onlyweb", delivery = EndpointDelivery.WEB)
@Endpoint(id = "onlyweb", exposure = EndpointExposure.WEB)
static class OnlyWebEndpoint {
}

View File

@ -20,7 +20,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.util.ObjectUtils;
@ -188,42 +188,42 @@ public class EndpointEnablementProviderTests {
@Test
public void specificEnabledByDefault() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.JMX);
EndpointExposure.JMX);
validate(enablement, true, "endpoint 'foo' (jmx) is enabled by default");
}
@Test
public void specificDisabledViaEndpointProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.foo.enabled=false");
EndpointExposure.WEB, "endpoints.foo.enabled=false");
validate(enablement, false, "found property endpoints.foo.enabled");
}
@Test
public void specificDisabledViaTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.foo.web.enabled=false");
EndpointExposure.WEB, "endpoints.foo.web.enabled=false");
validate(enablement, false, "found property endpoints.foo.web.enabled");
}
@Test
public void specificNotDisabledViaUnrelatedTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.JMX, "endpoints.foo.web.enabled=false");
EndpointExposure.JMX, "endpoints.foo.web.enabled=false");
validate(enablement, true, "endpoint 'foo' (jmx) is enabled by default");
}
@Test
public void specificDisabledViaGeneralProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.JMX, "endpoints.default.enabled=false");
EndpointExposure.JMX, "endpoints.default.enabled=false");
validate(enablement, false, "found property endpoints.default.enabled");
}
@Test
public void specificEnabledOverrideViaEndpointProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.default.enabled=false",
EndpointExposure.WEB, "endpoints.default.enabled=false",
"endpoints.foo.enabled=true");
validate(enablement, true, "found property endpoints.foo.enabled");
}
@ -231,7 +231,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificEnabledOverrideViaTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.foo.enabled=false",
EndpointExposure.WEB, "endpoints.foo.enabled=false",
"endpoints.foo.web.enabled=true");
validate(enablement, true, "found property endpoints.foo.web.enabled");
}
@ -239,7 +239,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificEnabledOverrideHasNotEffectWithUnrelatedTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.foo.enabled=false",
EndpointExposure.WEB, "endpoints.foo.enabled=false",
"endpoints.foo.jmx.enabled=true");
validate(enablement, false, "found property endpoints.foo.enabled");
}
@ -247,7 +247,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificEnabledOverrideViaGeneralWebProperty() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.default.enabled=false",
EndpointExposure.WEB, "endpoints.default.enabled=false",
"endpoints.default.web.enabled=true");
validate(enablement, true, "found property endpoints.default.web.enabled");
}
@ -255,7 +255,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificEnabledOverrideHasNoEffectWithUnrelatedTechProperty() {
validate(
getEndpointEnablement("foo", true, EndpointDelivery.JMX,
getEndpointEnablement("foo", true, EndpointExposure.JMX,
"endpoints.default.enabled=false", "endpoints.default.web.enabled=true"),
false, "found property endpoints.default.enabled");
}
@ -263,7 +263,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificDisabledWithEndpointPropertyEvenWithEnabledGeneralProperties() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.default.enabled=true",
EndpointExposure.WEB, "endpoints.default.enabled=true",
"endpoints.default.web.enabled=true", "endpoints.default.jmx.enabled=true",
"endpoints.foo.enabled=false");
validate(enablement, false, "found property endpoints.foo.enabled");
@ -272,7 +272,7 @@ public class EndpointEnablementProviderTests {
@Test
public void specificDisabledWithTechPropertyEvenWithEnabledGeneralProperties() {
EndpointEnablement enablement = getEndpointEnablement("foo", true,
EndpointDelivery.WEB, "endpoints.default.enabled=true",
EndpointExposure.WEB, "endpoints.default.enabled=true",
"endpoints.default.web.enabled=true", "endpoints.default.jmx.enabled=true",
"endpoints.foo.enabled=true", "endpoints.foo.web.enabled=false");
validate(enablement, false, "found property endpoints.foo.web.enabled");
@ -281,49 +281,49 @@ public class EndpointEnablementProviderTests {
@Test
public void specificDisabledByDefaultWithAnnotationFlag() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB);
EndpointExposure.WEB);
validate(enablement, false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.default.enabled=true");
EndpointExposure.WEB, "endpoints.default.enabled=true");
validate(enablement, false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralWebProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.default.web.enabled=true");
EndpointExposure.WEB, "endpoints.default.web.enabled=true");
validate(enablement, false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralJmxProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.default.jmx.enabled=true");
EndpointExposure.WEB, "endpoints.default.jmx.enabled=true");
validate(enablement, false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagAndEndpointProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.bar.enabled=true");
EndpointExposure.WEB, "endpoints.bar.enabled=true");
validate(enablement, true, "found property endpoints.bar.enabled");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagAndTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.bar.web.enabled=true");
EndpointExposure.WEB, "endpoints.bar.web.enabled=true");
validate(enablement, true, "found property endpoints.bar.web.enabled");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagHasNoEffectWithUnrelatedTechProperty() {
EndpointEnablement enablement = getEndpointEnablement("bar", false,
EndpointDelivery.WEB, "endpoints.bar.jmx.enabled=true");
EndpointExposure.WEB, "endpoints.bar.jmx.enabled=true");
validate(enablement, false, "endpoint 'bar' (web) is disabled by default");
}
@ -333,11 +333,11 @@ public class EndpointEnablementProviderTests {
}
private EndpointEnablement getEndpointEnablement(String id, boolean enabledByDefault,
EndpointDelivery delivery, String... environment) {
EndpointExposure exposure, String... environment) {
MockEnvironment env = new MockEnvironment();
TestPropertyValues.of(environment).applyTo(env);
EndpointEnablementProvider provider = new EndpointEnablementProvider(env);
return provider.getEndpointEnablement(id, enabledByDefault, delivery);
return provider.getEndpointEnablement(id, enabledByDefault, exposure);
}
private void validate(EndpointEnablement enablement, boolean enabled,

View File

@ -70,15 +70,15 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
/**
* Perform endpoint discovery, including discovery and merging of extensions.
* @param extensionType the annotation type of the extension
* @param delivery the {@link EndpointDelivery} that should be considered
* @param exposure the {@link EndpointExposure} that should be considered
* @return the list of {@link EndpointInfo EndpointInfos} that describes the
* discovered endpoints matching the specified {@link EndpointDelivery}
* discovered endpoints matching the specified {@link EndpointExposure}
*/
protected Collection<EndpointInfoDescriptor<T, K>> discoverEndpoints(
Class<? extends Annotation> extensionType, EndpointDelivery delivery) {
Map<Class<?>, EndpointInfo<T>> endpoints = discoverEndpoints(delivery);
Class<? extends Annotation> extensionType, EndpointExposure exposure) {
Map<Class<?>, EndpointInfo<T>> endpoints = discoverEndpoints(exposure);
Map<Class<?>, EndpointExtensionInfo<T>> extensions = discoverExtensions(endpoints,
extensionType, delivery);
extensionType, exposure);
Collection<EndpointInfoDescriptor<T, K>> result = new ArrayList<>();
endpoints.forEach((endpointClass, endpointInfo) -> {
EndpointExtensionInfo<T> extension = extensions.remove(endpointClass);
@ -87,7 +87,7 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
return result;
}
private Map<Class<?>, EndpointInfo<T>> discoverEndpoints(EndpointDelivery delivery) {
private Map<Class<?>, EndpointInfo<T>> discoverEndpoints(EndpointExposure exposure) {
String[] beanNames = this.applicationContext
.getBeanNamesForAnnotation(Endpoint.class);
Map<Class<?>, EndpointInfo<T>> endpoints = new LinkedHashMap<>();
@ -96,7 +96,7 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
Class<?> beanType = this.applicationContext.getType(beanName);
AnnotationAttributes attributes = AnnotatedElementUtils
.findMergedAnnotationAttributes(beanType, Endpoint.class, true, true);
if (isDeliveredOver(attributes, delivery)) {
if (isExposedOver(attributes, exposure)) {
EndpointInfo<T> info = createEndpointInfo(beanName, beanType, attributes);
EndpointInfo<T> previous = endpointsById.putIfAbsent(info.getId(), info);
Assert.state(previous == null, () -> "Found two endpoints with the id '"
@ -117,7 +117,7 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
private Map<Class<?>, EndpointExtensionInfo<T>> discoverExtensions(
Map<Class<?>, EndpointInfo<T>> endpoints,
Class<? extends Annotation> extensionType, EndpointDelivery delivery) {
Class<? extends Annotation> extensionType, EndpointExposure delivery) {
if (extensionType == null) {
return Collections.emptyMap();
}
@ -129,7 +129,7 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
Class<?> endpointType = getEndpointType(extensionType, beanType);
AnnotationAttributes endpointAttributes = AnnotatedElementUtils
.getMergedAnnotationAttributes(endpointType, Endpoint.class);
Assert.state(isDeliveredOver(endpointAttributes, delivery),
Assert.state(isExposedOver(endpointAttributes, delivery),
"Invalid extension " + beanType.getName() + "': endpoint '"
+ endpointType.getName()
+ "' does not support such extension");
@ -199,14 +199,14 @@ public abstract class AnnotationEndpointDiscoverer<T extends Operation, K>
return result;
}
private boolean isDeliveredOver(AnnotationAttributes attributes,
EndpointDelivery delivery) {
if (delivery == null) {
private boolean isExposedOver(AnnotationAttributes attributes,
EndpointExposure exposure) {
if (exposure == null) {
return true;
}
EndpointDelivery[] supported = (EndpointDelivery[]) attributes.get("delivery");
EndpointExposure[] supported = (EndpointExposure[]) attributes.get("exposure");
return ObjectUtils.isEmpty(supported)
|| ObjectUtils.containsElement(supported, delivery);
|| ObjectUtils.containsElement(supported, exposure);
}
private Map<Method, T> discoverOperations(String id, String name, Class<?> type) {

View File

@ -41,11 +41,11 @@ public @interface Endpoint {
String id();
/**
* Defines the {@link EndpointDelivery delivery technologies} over which the
* endpoint should be delivered over. By default, all technologies are supported.
* @return the supported endpoint delivery technologies
* Defines the {@link EndpointExposure technologies} over which the endpoint should be
* exposed. By default, all technologies are supported.
* @return the supported endpoint exposure technologies
*/
EndpointDelivery[] delivery() default {};
EndpointExposure[] exposure() default {};
/**
* Whether or not the endpoint is enabled by default.

View File

@ -17,12 +17,12 @@
package org.springframework.boot.endpoint;
/**
* An enumeration of the available {@link Endpoint} delivery technologies.
* An enumeration of the available {@link Endpoint} exposure technologies.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
public enum EndpointDelivery {
public enum EndpointExposure {
/**
* Expose the endpoint as a JMX MBean.
@ -36,7 +36,7 @@ public enum EndpointDelivery {
private final boolean enabledByDefault;
EndpointDelivery(boolean enabledByDefault) {
EndpointExposure(boolean enabledByDefault) {
this.enabledByDefault = enabledByDefault;
}

View File

@ -31,7 +31,7 @@ import org.springframework.boot.endpoint.AnnotationEndpointDiscoverer;
import org.springframework.boot.endpoint.CachingConfiguration;
import org.springframework.boot.endpoint.CachingOperationInvoker;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.EndpointInfo;
import org.springframework.boot.endpoint.OperationInvoker;
import org.springframework.boot.endpoint.OperationParameterMapper;
@ -76,7 +76,7 @@ public class JmxAnnotationEndpointDiscoverer
@Override
public Collection<EndpointInfo<JmxEndpointOperation>> discoverEndpoints() {
Collection<EndpointInfoDescriptor<JmxEndpointOperation, String>> endpointDescriptors = discoverEndpoints(
JmxEndpointExtension.class, EndpointDelivery.JMX);
JmxEndpointExtension.class, EndpointExposure.JMX);
verifyThatOperationsHaveDistinctName(endpointDescriptors);
return endpointDescriptors.stream().map(EndpointInfoDescriptor::getEndpointInfo)
.collect(Collectors.toList());

View File

@ -31,7 +31,7 @@ import org.springframework.boot.endpoint.AnnotationEndpointDiscoverer;
import org.springframework.boot.endpoint.CachingConfiguration;
import org.springframework.boot.endpoint.CachingOperationInvoker;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.EndpointInfo;
import org.springframework.boot.endpoint.OperationInvoker;
import org.springframework.boot.endpoint.OperationParameterMapper;
@ -80,7 +80,7 @@ public class WebAnnotationEndpointDiscoverer extends
@Override
public Collection<EndpointInfo<WebEndpointOperation>> discoverEndpoints() {
Collection<EndpointInfoDescriptor<WebEndpointOperation, OperationRequestPredicate>> endpoints = discoverEndpoints(
WebEndpointExtension.class, EndpointDelivery.WEB);
WebEndpointExtension.class, EndpointExposure.WEB);
verifyThatOperationsHaveDistinctPredicates(endpoints);
return endpoints.stream().map(EndpointInfoDescriptor::getEndpointInfo)
.collect(Collectors.toList());

View File

@ -31,7 +31,7 @@ import org.springframework.boot.endpoint.CachingConfiguration;
import org.springframework.boot.endpoint.CachingOperationInvoker;
import org.springframework.boot.endpoint.ConversionServiceOperationParameterMapper;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.EndpointInfo;
import org.springframework.boot.endpoint.ReadOperation;
import org.springframework.boot.endpoint.ReflectiveOperationInvoker;
@ -331,7 +331,7 @@ public class JmxAnnotationEndpointDiscovererTests {
}
@Endpoint(id = "jmx", delivery = EndpointDelivery.JMX)
@Endpoint(id = "jmx", exposure = EndpointExposure.JMX)
private static class TestJmxEndpoint {
@ReadOperation
@ -410,7 +410,7 @@ public class JmxAnnotationEndpointDiscovererTests {
}
@Endpoint(id = "nonjmx", delivery = EndpointDelivery.WEB)
@Endpoint(id = "nonjmx", exposure = EndpointExposure.WEB)
private static class NonJmxEndpoint {
@ReadOperation

View File

@ -37,7 +37,7 @@ import org.springframework.boot.endpoint.CachingConfiguration;
import org.springframework.boot.endpoint.CachingOperationInvoker;
import org.springframework.boot.endpoint.ConversionServiceOperationParameterMapper;
import org.springframework.boot.endpoint.Endpoint;
import org.springframework.boot.endpoint.EndpointDelivery;
import org.springframework.boot.endpoint.EndpointExposure;
import org.springframework.boot.endpoint.EndpointInfo;
import org.springframework.boot.endpoint.OperationInvoker;
import org.springframework.boot.endpoint.ReadOperation;
@ -375,7 +375,7 @@ public class WebAnnotationEndpointDiscovererTests {
}
@Endpoint(id = "nonweb", delivery = EndpointDelivery.JMX)
@Endpoint(id = "nonweb", exposure = EndpointExposure.JMX)
static class NonWebEndpoint {
@ReadOperation