|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
* Copyright 2012-2019 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.
|
|
|
@ -90,15 +90,11 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationAttributes getEndpointAttributes(ConditionContext context,
|
|
|
|
private AnnotationAttributes getEndpointAttributes(ConditionContext context,
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
Assert.state(
|
|
|
|
return getEndpointAttributes(getEndpointType(context, metadata));
|
|
|
|
metadata instanceof MethodMetadata
|
|
|
|
|
|
|
|
&& metadata.isAnnotated(Bean.class.getName()),
|
|
|
|
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods");
|
|
|
|
|
|
|
|
Class<?> endpointType = getEndpointType(context, (MethodMetadata) metadata);
|
|
|
|
|
|
|
|
return getEndpointAttributes(endpointType);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?> getEndpointType(ConditionContext context, MethodMetadata metadata) {
|
|
|
|
private Class<?> getEndpointType(ConditionContext context,
|
|
|
|
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
Map<String, Object> attributes = metadata
|
|
|
|
Map<String, Object> attributes = metadata
|
|
|
|
.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName());
|
|
|
|
.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName());
|
|
|
|
if (attributes != null && attributes.containsKey("endpoint")) {
|
|
|
|
if (attributes != null && attributes.containsKey("endpoint")) {
|
|
|
@ -107,15 +103,19 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
return target;
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
|
|
|
|
Assert.state(
|
|
|
|
|
|
|
|
metadata instanceof MethodMetadata
|
|
|
|
|
|
|
|
&& metadata.isAnnotated(Bean.class.getName()),
|
|
|
|
|
|
|
|
"OnEnabledEndpointCondition must be used on @Bean methods when the endpoint is not specified");
|
|
|
|
|
|
|
|
MethodMetadata methodMetadata = (MethodMetadata) metadata;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return ClassUtils.forName(metadata.getReturnTypeName(),
|
|
|
|
return ClassUtils.forName(methodMetadata.getReturnTypeName(),
|
|
|
|
context.getClassLoader());
|
|
|
|
context.getClassLoader());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable ex) {
|
|
|
|
catch (Throwable ex) {
|
|
|
|
throw new IllegalStateException("Failed to extract endpoint id for "
|
|
|
|
throw new IllegalStateException("Failed to extract endpoint id for "
|
|
|
|
+ metadata.getDeclaringClassName() + "." + metadata.getMethodName(),
|
|
|
|
+ methodMetadata.getDeclaringClassName() + "."
|
|
|
|
ex);
|
|
|
|
+ methodMetadata.getMethodName(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|