@Test public void invokeMethodTest() throws Exception { Event event = new Event(); event.setTopic("cart.created"); EventService eventService = new EventService(); eventService.invokeHandler(event, mockApiContext); }
protected void invokeHandler(Event event, ApiContext apiContext) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { String topic[] = event.getTopic().split("\\."); String eventCategory = topic[0].substring(0, 1).toUpperCase() + topic[0].substring(1); String eventAction = topic[1]; Object handler = EventManager.getInstance().getRegisteredClassHandlers(eventCategory); if (handler !=null) { String methodName = eventAction; String className = handler.getClass().getName(); try { Method m; m = handler.getClass().getMethod(methodName, ApiContext.class, Event.class); m.invoke(handler, apiContext, event); } catch (NoSuchMethodException e) { logger.warn("No " + eventAction + " method on class " + className); throw e; } catch (SecurityException e) { logger.warn("Security exception: " + e.getMessage()); throw e; } catch (IllegalAccessException e) { logger.warn("Illegal access for method " + eventAction + " on class " + className); throw e; } catch (IllegalArgumentException e) { logger.warn("Illegal argument exception for method " + eventAction + " on class " + className); throw e; } catch (InvocationTargetException e) { logger.warn("Invocation target exception for method " + eventAction + " on class " + className); throw e; } } }
EventService { protected void invokeHandler(Event event, ApiContext apiContext) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { String topic[] = event.getTopic().split("\\."); String eventCategory = topic[0].substring(0, 1).toUpperCase() + topic[0].substring(1); String eventAction = topic[1]; Object handler = EventManager.getInstance().getRegisteredClassHandlers(eventCategory); if (handler !=null) { String methodName = eventAction; String className = handler.getClass().getName(); try { Method m; m = handler.getClass().getMethod(methodName, ApiContext.class, Event.class); m.invoke(handler, apiContext, event); } catch (NoSuchMethodException e) { logger.warn("No " + eventAction + " method on class " + className); throw e; } catch (SecurityException e) { logger.warn("Security exception: " + e.getMessage()); throw e; } catch (IllegalAccessException e) { logger.warn("Illegal access for method " + eventAction + " on class " + className); throw e; } catch (IllegalArgumentException e) { logger.warn("Illegal argument exception for method " + eventAction + " on class " + className); throw e; } catch (InvocationTargetException e) { logger.warn("Invocation target exception for method " + eventAction + " on class " + className); throw e; } } } }
EventService { protected void invokeHandler(Event event, ApiContext apiContext) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { String topic[] = event.getTopic().split("\\."); String eventCategory = topic[0].substring(0, 1).toUpperCase() + topic[0].substring(1); String eventAction = topic[1]; Object handler = EventManager.getInstance().getRegisteredClassHandlers(eventCategory); if (handler !=null) { String methodName = eventAction; String className = handler.getClass().getName(); try { Method m; m = handler.getClass().getMethod(methodName, ApiContext.class, Event.class); m.invoke(handler, apiContext, event); } catch (NoSuchMethodException e) { logger.warn("No " + eventAction + " method on class " + className); throw e; } catch (SecurityException e) { logger.warn("Security exception: " + e.getMessage()); throw e; } catch (IllegalAccessException e) { logger.warn("Illegal access for method " + eventAction + " on class " + className); throw e; } catch (IllegalArgumentException e) { logger.warn("Illegal argument exception for method " + eventAction + " on class " + className); throw e; } catch (InvocationTargetException e) { logger.warn("Invocation target exception for method " + eventAction + " on class " + className); throw e; } } }  }
EventService { protected void invokeHandler(Event event, ApiContext apiContext) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { String topic[] = event.getTopic().split("\\."); String eventCategory = topic[0].substring(0, 1).toUpperCase() + topic[0].substring(1); String eventAction = topic[1]; Object handler = EventManager.getInstance().getRegisteredClassHandlers(eventCategory); if (handler !=null) { String methodName = eventAction; String className = handler.getClass().getName(); try { Method m; m = handler.getClass().getMethod(methodName, ApiContext.class, Event.class); m.invoke(handler, apiContext, event); } catch (NoSuchMethodException e) { logger.warn("No " + eventAction + " method on class " + className); throw e; } catch (SecurityException e) { logger.warn("Security exception: " + e.getMessage()); throw e; } catch (IllegalAccessException e) { logger.warn("Illegal access for method " + eventAction + " on class " + className); throw e; } catch (IllegalArgumentException e) { logger.warn("Illegal argument exception for method " + eventAction + " on class " + className); throw e; } catch (InvocationTargetException e) { logger.warn("Invocation target exception for method " + eventAction + " on class " + className); throw e; } } }  EventHandlerStatus dispatchEvent(HttpServletRequest httpRequest); }
EventService { protected void invokeHandler(Event event, ApiContext apiContext) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException { String topic[] = event.getTopic().split("\\."); String eventCategory = topic[0].substring(0, 1).toUpperCase() + topic[0].substring(1); String eventAction = topic[1]; Object handler = EventManager.getInstance().getRegisteredClassHandlers(eventCategory); if (handler !=null) { String methodName = eventAction; String className = handler.getClass().getName(); try { Method m; m = handler.getClass().getMethod(methodName, ApiContext.class, Event.class); m.invoke(handler, apiContext, event); } catch (NoSuchMethodException e) { logger.warn("No " + eventAction + " method on class " + className); throw e; } catch (SecurityException e) { logger.warn("Security exception: " + e.getMessage()); throw e; } catch (IllegalAccessException e) { logger.warn("Illegal access for method " + eventAction + " on class " + className); throw e; } catch (IllegalArgumentException e) { logger.warn("Illegal argument exception for method " + eventAction + " on class " + className); throw e; } catch (InvocationTargetException e) { logger.warn("Invocation target exception for method " + eventAction + " on class " + className); throw e; } } }  EventHandlerStatus dispatchEvent(HttpServletRequest httpRequest);  }