|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2017 the original author or authors.
|
|
|
|
* Copyright 2012-2018 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.
|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
|
|
@ -92,16 +93,23 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
metadata instanceof MethodMetadata
|
|
|
|
metadata instanceof MethodMetadata
|
|
|
|
&& metadata.isAnnotated(Bean.class.getName()),
|
|
|
|
&& metadata.isAnnotated(Bean.class.getName()),
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods");
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods");
|
|
|
|
return getEndpointAttributes(context, (MethodMetadata) metadata);
|
|
|
|
Class<?> endpointType = getEndpointType(context, (MethodMetadata) metadata);
|
|
|
|
|
|
|
|
return getEndpointAttributes(endpointType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationAttributes getEndpointAttributes(ConditionContext context,
|
|
|
|
private Class<?> getEndpointType(ConditionContext context, MethodMetadata metadata) {
|
|
|
|
MethodMetadata metadata) {
|
|
|
|
Map<String, Object> attributes = metadata
|
|
|
|
|
|
|
|
.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName());
|
|
|
|
|
|
|
|
if (attributes != null && attributes.containsKey("endpoint")) {
|
|
|
|
|
|
|
|
Class<?> target = (Class<?>) attributes.get("endpoint");
|
|
|
|
|
|
|
|
if (target != Void.class) {
|
|
|
|
|
|
|
|
return target;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
|
|
|
|
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Class<?> returnType = ClassUtils.forName(metadata.getReturnTypeName(),
|
|
|
|
return ClassUtils.forName(metadata.getReturnTypeName(),
|
|
|
|
context.getClassLoader());
|
|
|
|
context.getClassLoader());
|
|
|
|
return getEndpointAttributes(returnType);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable ex) {
|
|
|
|
catch (Throwable ex) {
|
|
|
|
throw new IllegalStateException("Failed to extract endpoint id for "
|
|
|
|
throw new IllegalStateException("Failed to extract endpoint id for "
|
|
|
@ -119,8 +127,8 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
|
|
|
|
attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type,
|
|
|
|
EndpointExtension.class, false, true);
|
|
|
|
EndpointExtension.class, false, true);
|
|
|
|
Assert.state(attributes != null,
|
|
|
|
Assert.state(attributes != null,
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods that "
|
|
|
|
"No endpoint is specified and the return type of the @Bean method is "
|
|
|
|
+ "return an @Endpoint or @EndpointExtension");
|
|
|
|
+ "neither an @Endpoint, nor an @EndpointExtension");
|
|
|
|
return getEndpointAttributes(attributes.getClass("endpoint"));
|
|
|
|
return getEndpointAttributes(attributes.getClass("endpoint"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|