|
|
|
@ -90,6 +90,9 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|
|
|
|
checkBlock4RestTemplate(sentinelRestTemplate.fallbackClass(),
|
|
|
|
|
sentinelRestTemplate.fallback(), beanName,
|
|
|
|
|
SentinelConstants.FALLBACK_TYPE);
|
|
|
|
|
checkBlock4RestTemplate(sentinelRestTemplate.urlCleanerClass(),
|
|
|
|
|
sentinelRestTemplate.urlCleaner(), beanName,
|
|
|
|
|
SentinelConstants.URLCLEANER_TYPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,
|
|
|
|
@ -111,8 +114,14 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|
|
|
|
throw new IllegalArgumentException(type + " method attribute exists but "
|
|
|
|
|
+ type + " class attribute is not exists in bean[" + beanName + "]");
|
|
|
|
|
}
|
|
|
|
|
Class[] args = new Class[] { HttpRequest.class, byte[].class,
|
|
|
|
|
ClientHttpRequestExecution.class, BlockException.class };
|
|
|
|
|
Class[] args;
|
|
|
|
|
if (type.equals(SentinelConstants.URLCLEANER_TYPE)) {
|
|
|
|
|
args = new Class[] { String.class };
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
args = new Class[] { HttpRequest.class, byte[].class,
|
|
|
|
|
ClientHttpRequestExecution.class, BlockException.class };
|
|
|
|
|
}
|
|
|
|
|
String argsStr = Arrays.toString(
|
|
|
|
|
Arrays.stream(args).map(clazz -> clazz.getSimpleName()).toArray());
|
|
|
|
|
Method foundMethod = ClassUtils.getStaticMethod(blockClass, blockMethod, args);
|
|
|
|
@ -127,21 +136,32 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|
|
|
|
+ ", please check your class name, method name and arguments");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ClientHttpResponse.class.isAssignableFrom(foundMethod.getReturnType())) {
|
|
|
|
|
log.error(
|
|
|
|
|
"{} method return value in bean[{}] is not ClientHttpResponse: {}#{}{}",
|
|
|
|
|
type, beanName, blockClass.getName(), blockMethod, argsStr);
|
|
|
|
|
Class<?> standardReturnType;
|
|
|
|
|
if (type.equals(SentinelConstants.URLCLEANER_TYPE)) {
|
|
|
|
|
standardReturnType = String.class;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
standardReturnType = ClientHttpResponse.class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!standardReturnType.isAssignableFrom(foundMethod.getReturnType())) {
|
|
|
|
|
log.error("{} method return value in bean[{}] is not {}: {}#{}{}", type,
|
|
|
|
|
beanName, standardReturnType.getName(), blockClass.getName(),
|
|
|
|
|
blockMethod, argsStr);
|
|
|
|
|
throw new IllegalArgumentException(type + " method return value in bean["
|
|
|
|
|
+ beanName + "] is not ClientHttpResponse: " + blockClass.getName()
|
|
|
|
|
+ "#" + blockMethod + argsStr);
|
|
|
|
|
+ beanName + "] is not " + standardReturnType.getName() + ": "
|
|
|
|
|
+ blockClass.getName() + "#" + blockMethod + argsStr);
|
|
|
|
|
}
|
|
|
|
|
if (type.equals(SentinelConstants.BLOCK_TYPE)) {
|
|
|
|
|
BlockClassRegistry.updateBlockHandlerFor(blockClass, blockMethod,
|
|
|
|
|
foundMethod);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
else if (type.equals(SentinelConstants.FALLBACK_TYPE)) {
|
|
|
|
|
BlockClassRegistry.updateFallbackFor(blockClass, blockMethod, foundMethod);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BlockClassRegistry.updateUrlCleanerFor(blockClass, blockMethod, foundMethod);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
|
|
|
@ -177,7 +197,9 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|
|
|
|
.append(sentinelRestTemplate.blockHandlerClass().getSimpleName())
|
|
|
|
|
.append(sentinelRestTemplate.blockHandler()).append("_")
|
|
|
|
|
.append(sentinelRestTemplate.fallbackClass().getSimpleName())
|
|
|
|
|
.append(sentinelRestTemplate.fallback());
|
|
|
|
|
.append(sentinelRestTemplate.fallback()).append("_")
|
|
|
|
|
.append(sentinelRestTemplate.urlCleanerClass().getSimpleName())
|
|
|
|
|
.append(sentinelRestTemplate.urlCleaner());
|
|
|
|
|
RestTemplate restTemplate = (RestTemplate) bean;
|
|
|
|
|
String interceptorBeanName = interceptorBeanNamePrefix + "@"
|
|
|
|
|
+ bean.toString();
|
|
|
|
|