use of com.dtflys.forest.exceptions.ForestInterceptorDefineException in project forest by dromara.
the class TestExceptions method testInterceptorDefineException.
@Test
public void testInterceptorDefineException() {
ForestInterceptorDefineException exception = new ForestInterceptorDefineException(TestErrorInterceptor.class);
assertThat(exception.getMessage()).isEqualTo("[Forest] Interceptor class 'com.dtflys.test.exception.TestExceptions$TestErrorInterceptor' cannot be initialized, because interceptor class must implements com.dtflys.forest.interceptor.Interceptor");
assertThat(exception.getInterceptorClass()).isEqualTo(TestErrorInterceptor.class);
}
use of com.dtflys.forest.exceptions.ForestInterceptorDefineException in project forest by dromara.
the class ForestMethod method processParameterAnnotation.
/**
* 处理参数的注解
* @param parameter 方法参数-字符串模板解析对象,{@link MappingParameter}类实例
* @param anns 方法参数注解的二维数组
*/
private void processParameterAnnotation(MappingParameter parameter, Annotation[] anns) {
for (int i = 0; i < anns.length; i++) {
Annotation ann = anns[i];
Class annType = ann.annotationType();
if (annType.getPackage().getName().startsWith("java.")) {
continue;
}
Annotation[] subAnnArray = annType.getAnnotations();
if (subAnnArray.length > 0) {
processParameterAnnotation(parameter, subAnnArray);
}
ParamLifeCycle paramLifeCycleAnn = (ParamLifeCycle) annType.getAnnotation(ParamLifeCycle.class);
if (paramLifeCycleAnn != null) {
Class<? extends ParameterAnnotationLifeCycle> interceptorClass = paramLifeCycleAnn.value();
if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
throw new ForestInterceptorDefineException(interceptorClass);
}
ParameterAnnotationLifeCycle lifeCycle = addInterceptor(interceptorClass);
lifeCycle.onParameterInitialized(this, parameter, ann);
}
}
}
use of com.dtflys.forest.exceptions.ForestInterceptorDefineException in project forest by dromara.
the class ForestMethod method getAnnotationLifeCycleClass.
private Class<? extends Interceptor> getAnnotationLifeCycleClass(Annotation annotation) {
Class<? extends Annotation> annType = annotation.annotationType();
Class<? extends MethodAnnotationLifeCycle> interceptorClass = null;
MethodLifeCycle methodLifeCycleAnn = annType.getAnnotation(MethodLifeCycle.class);
if (methodLifeCycleAnn == null) {
BaseLifeCycle baseLifeCycle = annType.getAnnotation(BaseLifeCycle.class);
if (baseLifeCycle != null) {
Class<? extends BaseAnnotationLifeCycle> baseAnnLifeCycleClass = baseLifeCycle.value();
if (baseAnnLifeCycleClass != null) {
if (MethodAnnotationLifeCycle.class.isAssignableFrom(baseAnnLifeCycleClass)) {
interceptorClass = (Class<? extends MethodAnnotationLifeCycle>) baseAnnLifeCycleClass;
} else {
return baseAnnLifeCycleClass;
}
}
}
}
if (methodLifeCycleAnn != null || interceptorClass != null) {
if (interceptorClass == null) {
interceptorClass = methodLifeCycleAnn.value();
if (!Interceptor.class.isAssignableFrom(interceptorClass)) {
throw new ForestInterceptorDefineException(interceptorClass);
}
}
}
return interceptorClass;
}
Aggregations