@Test void setExceptionHandlerMapTest() { DssRestExceptionHandlerResolver dssRestExceptionHandlerResolver = DssRestExceptionHandlerResolver.getInstance(); dssRestExceptionHandlerResolver.setExceptionHandlerMap(new DssExceptionHandler() { @ExceptionHandler(exception = NullPointerException.class) public DssRestServiceResponse globalExceptionHandleMethod(DssRestServiceActorCommandRequest request) { return null; } @ServiceExceptionHandler(service = TestService.class, exception = Exception.class) public DssRestServiceResponse serviceExceptionHandleMethod(DssRestServiceActorCommandRequest request) { return null; } }); assertTrue(dssRestExceptionHandlerResolver.getExceptionHandlerMap().containsKey(TestService.class)); assertTrue(dssRestExceptionHandlerResolver.getExceptionHandlerMap().containsKey(DssRestActorService.class)); }
public void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler) { Objects.requireNonNull(dssExceptionHandler); Method[] methods = dssExceptionHandler.getClass().getMethods(); HashMap<Class<? extends Exception>, ExceptionHandleMethod> globalExceptionHandlerMap = new HashMap<>(); for (Method method : methods) { if (method.isAnnotationPresent(ExceptionHandler.class)) { ExceptionHandler annotation = method.getAnnotation(ExceptionHandler.class); for (Class<? extends Exception> exception : annotation.exception()) { globalExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } else if (method.isAnnotationPresent(ServiceExceptionHandler.class)) { ServiceExceptionHandler annotation = method.getAnnotation(ServiceExceptionHandler.class); exceptionHandlerMap.putIfAbsent(annotation.service(), new HashMap<>()); Map<Class<? extends Exception>, ExceptionHandleMethod> serviceExceptionHandlerMap = exceptionHandlerMap.get(annotation.service()); for (Class<? extends Exception> exception : annotation.exception()) { serviceExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } } exceptionHandlerMap.put(DssRestActorService.class, globalExceptionHandlerMap); }
DssRestExceptionHandlerResolver { public void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler) { Objects.requireNonNull(dssExceptionHandler); Method[] methods = dssExceptionHandler.getClass().getMethods(); HashMap<Class<? extends Exception>, ExceptionHandleMethod> globalExceptionHandlerMap = new HashMap<>(); for (Method method : methods) { if (method.isAnnotationPresent(ExceptionHandler.class)) { ExceptionHandler annotation = method.getAnnotation(ExceptionHandler.class); for (Class<? extends Exception> exception : annotation.exception()) { globalExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } else if (method.isAnnotationPresent(ServiceExceptionHandler.class)) { ServiceExceptionHandler annotation = method.getAnnotation(ServiceExceptionHandler.class); exceptionHandlerMap.putIfAbsent(annotation.service(), new HashMap<>()); Map<Class<? extends Exception>, ExceptionHandleMethod> serviceExceptionHandlerMap = exceptionHandlerMap.get(annotation.service()); for (Class<? extends Exception> exception : annotation.exception()) { serviceExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } } exceptionHandlerMap.put(DssRestActorService.class, globalExceptionHandlerMap); } }
DssRestExceptionHandlerResolver { public void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler) { Objects.requireNonNull(dssExceptionHandler); Method[] methods = dssExceptionHandler.getClass().getMethods(); HashMap<Class<? extends Exception>, ExceptionHandleMethod> globalExceptionHandlerMap = new HashMap<>(); for (Method method : methods) { if (method.isAnnotationPresent(ExceptionHandler.class)) { ExceptionHandler annotation = method.getAnnotation(ExceptionHandler.class); for (Class<? extends Exception> exception : annotation.exception()) { globalExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } else if (method.isAnnotationPresent(ServiceExceptionHandler.class)) { ServiceExceptionHandler annotation = method.getAnnotation(ServiceExceptionHandler.class); exceptionHandlerMap.putIfAbsent(annotation.service(), new HashMap<>()); Map<Class<? extends Exception>, ExceptionHandleMethod> serviceExceptionHandlerMap = exceptionHandlerMap.get(annotation.service()); for (Class<? extends Exception> exception : annotation.exception()) { serviceExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } } exceptionHandlerMap.put(DssRestActorService.class, globalExceptionHandlerMap); } private  DssRestExceptionHandlerResolver(); }
DssRestExceptionHandlerResolver { public void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler) { Objects.requireNonNull(dssExceptionHandler); Method[] methods = dssExceptionHandler.getClass().getMethods(); HashMap<Class<? extends Exception>, ExceptionHandleMethod> globalExceptionHandlerMap = new HashMap<>(); for (Method method : methods) { if (method.isAnnotationPresent(ExceptionHandler.class)) { ExceptionHandler annotation = method.getAnnotation(ExceptionHandler.class); for (Class<? extends Exception> exception : annotation.exception()) { globalExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } else if (method.isAnnotationPresent(ServiceExceptionHandler.class)) { ServiceExceptionHandler annotation = method.getAnnotation(ServiceExceptionHandler.class); exceptionHandlerMap.putIfAbsent(annotation.service(), new HashMap<>()); Map<Class<? extends Exception>, ExceptionHandleMethod> serviceExceptionHandlerMap = exceptionHandlerMap.get(annotation.service()); for (Class<? extends Exception> exception : annotation.exception()) { serviceExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } } exceptionHandlerMap.put(DssRestActorService.class, globalExceptionHandlerMap); } private  DssRestExceptionHandlerResolver(); static DssRestExceptionHandlerResolver getInstance(); void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler); Map<Class<? extends DssRestActorService>, Map<Class<? extends Exception>, ExceptionHandleMethod>> getExceptionHandlerMap(); }
DssRestExceptionHandlerResolver { public void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler) { Objects.requireNonNull(dssExceptionHandler); Method[] methods = dssExceptionHandler.getClass().getMethods(); HashMap<Class<? extends Exception>, ExceptionHandleMethod> globalExceptionHandlerMap = new HashMap<>(); for (Method method : methods) { if (method.isAnnotationPresent(ExceptionHandler.class)) { ExceptionHandler annotation = method.getAnnotation(ExceptionHandler.class); for (Class<? extends Exception> exception : annotation.exception()) { globalExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } else if (method.isAnnotationPresent(ServiceExceptionHandler.class)) { ServiceExceptionHandler annotation = method.getAnnotation(ServiceExceptionHandler.class); exceptionHandlerMap.putIfAbsent(annotation.service(), new HashMap<>()); Map<Class<? extends Exception>, ExceptionHandleMethod> serviceExceptionHandlerMap = exceptionHandlerMap.get(annotation.service()); for (Class<? extends Exception> exception : annotation.exception()) { serviceExceptionHandlerMap.put(exception, setExceptionHandleMethod(dssExceptionHandler, method)); } } } exceptionHandlerMap.put(DssRestActorService.class, globalExceptionHandlerMap); } private  DssRestExceptionHandlerResolver(); static DssRestExceptionHandlerResolver getInstance(); void setExceptionHandlerMap(DssExceptionHandler dssExceptionHandler); Map<Class<? extends DssRestActorService>, Map<Class<? extends Exception>, ExceptionHandleMethod>> getExceptionHandlerMap();  }