Commit 157e3382ab300c0017be84553d22d63a002f4bf5
1 parent
c20d0c4b
Exists in
master
Tentativa de resolver o problema de detecção de @ExceptionHandler com
uso de Proxy
Showing
1 changed file
with
13 additions
and
2 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
@@ -39,7 +39,10 @@ package br.gov.frameworkdemoiselle.exception; | @@ -39,7 +39,10 @@ package br.gov.frameworkdemoiselle.exception; | ||
39 | import java.io.Serializable; | 39 | import java.io.Serializable; |
40 | import java.lang.reflect.InvocationTargetException; | 40 | import java.lang.reflect.InvocationTargetException; |
41 | import java.lang.reflect.Method; | 41 | import java.lang.reflect.Method; |
42 | +import java.util.ArrayList; | ||
43 | +import java.util.Arrays; | ||
42 | import java.util.HashMap; | 44 | import java.util.HashMap; |
45 | +import java.util.List; | ||
43 | import java.util.Map; | 46 | import java.util.Map; |
44 | 47 | ||
45 | import javax.interceptor.AroundInvoke; | 48 | import javax.interceptor.AroundInvoke; |
@@ -70,7 +73,7 @@ public class ExceptionHandlerInterceptor implements Serializable { | @@ -70,7 +73,7 @@ public class ExceptionHandlerInterceptor implements Serializable { | ||
70 | getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName())); | 73 | getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName())); |
71 | 74 | ||
72 | boolean handled = false; | 75 | boolean handled = false; |
73 | - Class<?> type = target.getClass().getSuperclass(); | 76 | + Class<?> type = target.getClass(); |
74 | 77 | ||
75 | if (!isLoaded(type)) { | 78 | if (!isLoaded(type)) { |
76 | loadHandlers(type); | 79 | loadHandlers(type); |
@@ -115,7 +118,14 @@ public class ExceptionHandlerInterceptor implements Serializable { | @@ -115,7 +118,14 @@ public class ExceptionHandlerInterceptor implements Serializable { | ||
115 | */ | 118 | */ |
116 | private void loadHandlers(final Class<?> type) { | 119 | private void loadHandlers(final Class<?> type) { |
117 | Map<Class<?>, Method> mapHandlers = new HashMap<Class<?>, Method>(); | 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 | for (Method method : methods) { | 130 | for (Method method : methods) { |
121 | if (method.isAnnotationPresent(ExceptionHandler.class)) { | 131 | if (method.isAnnotationPresent(ExceptionHandler.class)) { |
@@ -123,6 +133,7 @@ public class ExceptionHandlerInterceptor implements Serializable { | @@ -123,6 +133,7 @@ public class ExceptionHandlerInterceptor implements Serializable { | ||
123 | mapHandlers.put(method.getParameterTypes()[0], method); | 133 | mapHandlers.put(method.getParameterTypes()[0], method); |
124 | } | 134 | } |
125 | } | 135 | } |
136 | + | ||
126 | cache.put(type, mapHandlers); | 137 | cache.put(type, mapHandlers); |
127 | } | 138 | } |
128 | 139 |