Commit 157e3382ab300c0017be84553d22d63a002f4bf5

Authored by Cleverson Sacramento
1 parent c20d0c4b
Exists in master

Tentativa de resolver o problema de detecção de @ExceptionHandler com

uso de Proxy
impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
... ... @@ -39,7 +39,10 @@ package br.gov.frameworkdemoiselle.exception;
39 39 import java.io.Serializable;
40 40 import java.lang.reflect.InvocationTargetException;
41 41 import java.lang.reflect.Method;
  42 +import java.util.ArrayList;
  43 +import java.util.Arrays;
42 44 import java.util.HashMap;
  45 +import java.util.List;
43 46 import java.util.Map;
44 47  
45 48 import javax.interceptor.AroundInvoke;
... ... @@ -70,7 +73,7 @@ public class ExceptionHandlerInterceptor implements Serializable {
70 73 getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName()));
71 74  
72 75 boolean handled = false;
73   - Class<?> type = target.getClass().getSuperclass();
  76 + Class<?> type = target.getClass();
74 77  
75 78 if (!isLoaded(type)) {
76 79 loadHandlers(type);
... ... @@ -115,7 +118,14 @@ public class ExceptionHandlerInterceptor implements Serializable {
115 118 */
116 119 private void loadHandlers(final Class<?> type) {
117 120 Map<Class<?>, Method> mapHandlers = new HashMap<Class<?>, Method>();
118   - Method[] methods = type.getMethods();
  121 +
  122 + List<Method> methods = new ArrayList<Method>();
  123 + Class<?> tempType = type;
  124 +
  125 + while (tempType != null) {
  126 + methods.addAll(Arrays.asList(tempType.getMethods()));
  127 + tempType = tempType.getSuperclass();
  128 + }
119 129  
120 130 for (Method method : methods) {
121 131 if (method.isAnnotationPresent(ExceptionHandler.class)) {
... ... @@ -123,6 +133,7 @@ public class ExceptionHandlerInterceptor implements Serializable {
123 133 mapHandlers.put(method.getParameterTypes()[0], method);
124 134 }
125 135 }
  136 +
126 137 cache.put(type, mapHandlers);
127 138 }
128 139  
... ...