diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java index f7d6c0627..b36d12326 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java @@ -53,6 +53,7 @@ import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod; import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodFromTarget; +import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodInfo; import static com.netflix.hystrix.contrib.javanica.utils.EnvUtils.isCompileWeaving; import static com.netflix.hystrix.contrib.javanica.utils.ajc.AjcUtils.getAjcMethodAroundAdvice; @@ -272,7 +273,14 @@ private enum HystrixPointcutType { COLLAPSER; static HystrixPointcutType of(Method method) { - return method.isAnnotationPresent(HystrixCommand.class) ? COMMAND : COLLAPSER; + if (method.isAnnotationPresent(HystrixCommand.class)) { + return COMMAND; + } else if (method.isAnnotationPresent(HystrixCollapser.class)) { + return COLLAPSER; + } else { + String methodInfo = getMethodInfo(method); + throw new IllegalStateException("'https://github.com/Netflix/Hystrix/issues/1458' - no valid annotation found for: \n" + methodInfo); + } } } diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java index 40d3f4ece..45c3615ea 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java @@ -24,6 +24,8 @@ import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Type; /** * Provides common methods to retrieve information from JoinPoint and not only. @@ -123,4 +125,76 @@ public static Optional getAnnotation(Class type, Cl return Optional.absent(); } + public static String getMethodInfo(Method m) { + StringBuilder info = new StringBuilder(); + info.append("Method signature:").append("\n"); + info.append(m.toGenericString()).append("\n"); + + info.append("\nFlags:").append("\n"); + info.append("Bridge=").append(m.isBridge()).append("\n"); + info.append("Synthetic=").append(m.isSynthetic()).append("\n"); + info.append("Final=").append(Modifier.isFinal(m.getModifiers())).append("\n"); + info.append("Native=").append(Modifier.isNative(m.getModifiers())).append("\n"); + info.append("Synchronized=").append(Modifier.isSynchronized(m.getModifiers())).append("\n"); + info.append("Abstract=").append(Modifier.isAbstract(m.getModifiers())).append("\n"); + info.append("AccessLevel=").append(getAccessLevel(m.getModifiers())).append("\n"); + + info.append("\nReturn Type: \n"); + info.append("ReturnType=").append(m.getReturnType()).append("\n"); + info.append("GenericReturnType=").append(m.getGenericReturnType()).append("\n"); + + info.append("\nParameters:"); + Class[] pType = m.getParameterTypes(); + Type[] gpType = m.getGenericParameterTypes(); + if (pType.length != 0) { + info.append("\n"); + } else { + info.append("empty\n"); + } + for (int i = 0; i < pType.length; i++) { + info.append("parameter [").append(i).append("]:\n"); + info.append("ParameterType=").append(pType[i]).append("\n"); + info.append("GenericParameterType=").append(gpType[i]).append("\n"); + } + + info.append("\nExceptions:"); + Class[] xType = m.getExceptionTypes(); + Type[] gxType = m.getGenericExceptionTypes(); + if (xType.length != 0) { + info.append("\n"); + } else { + info.append("empty\n"); + } + for (int i = 0; i < xType.length; i++) { + info.append("exception [").append(i).append("]:\n"); + info.append("ExceptionType=").append(xType[i]).append("\n"); + info.append("GenericExceptionType=").append(gxType[i]).append("\n"); + } + + info.append("\nAnnotations:"); + if (m.getAnnotations().length != 0) { + info.append("\n"); + } else { + info.append("empty\n"); + } + + for (int i = 0; i < m.getAnnotations().length; i++) { + info.append("annotation[").append(i).append("]=").append(m.getAnnotations()[i]).append("\n"); + } + + return info.toString(); + } + + private static String getAccessLevel(int modifiers) { + if (Modifier.isPublic(modifiers)) { + return "public"; + } else if (Modifier.isProtected(modifiers)) { + return "protected"; + } else if (Modifier.isPrivate(modifiers)) { + return "private"; + } else { + return "default"; + } + } + }