@Override public void execute(QuartzJobContext quartzJobContext, Job job) throws Throwable { methodInvoker.invoke(); } }
@Override public void execute(QuartzJobContext quartzJobContext, Job job) throws Throwable { methodInvoker.invoke(); } }
/** * Invoke the method via the MethodInvoker. */ @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { Assert.state(this.methodInvoker != null, "No MethodInvoker set"); try { context.setResult(this.methodInvoker.invoke()); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof JobExecutionException) { // -> JobExecutionException, to be logged at info level by Quartz throw (JobExecutionException) ex.getTargetException(); } else { // -> "unhandled exception", to be logged at error level by Quartz throw new JobMethodInvocationFailedException(this.methodInvoker, ex.getTargetException()); } } catch (Exception ex) { // -> "unhandled exception", to be logged at error level by Quartz throw new JobMethodInvocationFailedException(this.methodInvoker, ex); } } }
return (T) methodInvoker.invoke();
/** * Invoke the method via the MethodInvoker. */ @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { Assert.state(this.methodInvoker != null, "No MethodInvoker set"); try { context.setResult(this.methodInvoker.invoke()); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof JobExecutionException) { // -> JobExecutionException, to be logged at info level by Quartz throw (JobExecutionException) ex.getTargetException(); } else { // -> "unhandled exception", to be logged at error level by Quartz throw new JobMethodInvocationFailedException(this.methodInvoker, ex.getTargetException()); } } catch (Exception ex) { // -> "unhandled exception", to be logged at error level by Quartz throw new JobMethodInvocationFailedException(this.methodInvoker, ex); } } }
private Object doInvoke(MethodInvoker invoker) throws Exception{ try { invoker.prepare(); } catch (ClassNotFoundException | NoSuchMethodException e) { throw new DynamicMethodInvocationException(e); } try { return invoker.invoke(); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } else { throw new InvocationTargetThrowableWrapper(e.getCause()); } } catch (IllegalAccessException e) { throw new DynamicMethodInvocationException(e); } }
/** * Added due to JDK 7 compatibility. */ public Logger getParentLogger() throws SQLFeatureNotSupportedException{ MethodInvoker invoker = new MethodInvoker(); invoker.setTargetObject(dataSource); invoker.setTargetMethod("getParentLogger"); try { invoker.prepare(); return (Logger) invoker.invoke(); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException nsme) { throw new SQLFeatureNotSupportedException(nsme); } } }
/** * Prepare and invoke the invoker, rethrow checked exceptions as unchecked. * @param invoker configured invoker * @return return value of the invoked method */ @SuppressWarnings("unchecked") private T doInvoke(MethodInvoker invoker) throws Exception { try { invoker.prepare(); } catch (ClassNotFoundException | NoSuchMethodException e) { throw new DynamicMethodInvocationException(e); } try { return (T) invoker.invoke(); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } else { throw new InvocationTargetThrowableWrapper(e.getCause()); } } catch (IllegalAccessException e) { throw new DynamicMethodInvocationException(e); } }
private Object doInvoke(MethodInvoker invoker) throws Exception{ try { invoker.prepare(); } catch (ClassNotFoundException e) { throw new DynamicMethodInvocationException(e); } catch (NoSuchMethodException e) { throw new DynamicMethodInvocationException(e); } try { return invoker.invoke(); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } else { throw new InvocationTargetThrowableWrapper(e.getCause()); } } catch (IllegalAccessException e) { throw new DynamicMethodInvocationException(e); } }
methodInvoker.setArguments(arguments); methodInvoker.prepare(); return methodInvoker.invoke();
@Test public void testInvokeWithNullArgument() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetClass(TestClass1.class); methodInvoker.setTargetMethod("nullArgument"); methodInvoker.setArguments(new Object[] {null}); methodInvoker.prepare(); methodInvoker.invoke(); }
mi.setTargetMethod("method1"); mi.prepare(); Integer i = (Integer) mi.invoke(); assertEquals(1, i.intValue()); mi.setArguments((Object[]) null); mi.prepare(); i = (Integer) mi.invoke(); assertEquals(1, i.intValue()); mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello"); mi.prepare(); assertEquals("hello", mi.invoke()); mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", "bogus"); mi.prepare(); assertEquals("hello", mi.invoke());
@Test public void salesmanWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new Salesman()); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("greetable: how are sales?", greeting); }
@Test public void purchaserWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new Purchaser()); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("purchaser: hello", greeting); }
@Test public void shopperWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new Shopper()); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("purchaser: may I help you?", greeting); }
@Test public void customerWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new Customer()); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("customer: good day", greeting); }
@Test public void regularWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new Regular("Kotter")); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("regular: welcome back Kotter", greeting); }
@Test public void vipWithMethodInvoker() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(new Greeter()); methodInvoker.setTargetMethod("greet"); methodInvoker.setArguments(new VIP("Fonzie")); methodInvoker.prepare(); String greeting = (String) methodInvoker.invoke(); assertEquals("regular: whassup dude?", greeting); }
@Override public void execute(QuartzJobContext quartzJobContext, Job job) throws Throwable { methodInvoker.invoke(); } }
private Object invoke(CachedInvocation invocation) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { final MethodInvoker invoker = new MethodInvoker(); invoker.setTargetObject(invocation.getTargetBean()); invoker.setArguments(invocation.getArguments()); invoker.setTargetMethod(invocation.getTargetMethod().getName()); invoker.prepare(); return invoker.invoke(); }