Package org.springframework.util

Examples of org.springframework.util.MethodInvoker


      // expected
    }
  }

  public void testInvokeWithNullArgument() throws Exception {
    MethodInvoker methodInvoker = new MethodInvoker();
    methodInvoker.setTargetClass(MethodInvokerTests.TestClass1.class);
    methodInvoker.setTargetMethod("nullArgument");
    methodInvoker.setArguments(new Object[] {null});
    methodInvoker.prepare();
    methodInvoker.invoke();
  }
View Full Code Here


   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof JMSException) {
        throw (JMSException) targetEx;
View Full Code Here

  public static <T> T invokeMethod(Object target, String name, Object... args) {
    Assert.notNull(target, "Target object must not be null");
    Assert.hasText(name, "Method name must not be empty");

    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(target);
      methodInvoker.setTargetMethod(name);
      methodInvoker.setArguments(args);
      methodInvoker.prepare();

      if (logger.isDebugEnabled()) {
        logger.debug("Invoking method [" + name + "] on target [" + target + "] with arguments ["
            + ObjectUtils.nullSafeToString(args) + "]");
      }

      return (T) methodInvoker.invoke();
    }
    catch (Exception e) {
      ReflectionUtils.handleReflectionException(e);
    }
View Full Code Here

        logger.debug("arguments array is "+arguments);
       
        Object bean = applicationContext.getBean(targetBean);
        logger.debug("applicationContext resolved bean name/id '"+targetBean+"' to "+bean);
       
        MethodInvoker beanMethod = new MethodInvoker();
        beanMethod.setTargetObject(bean);
        beanMethod.setTargetMethod(targetMethod);
        beanMethod.setArguments(arguments);
        beanMethod.prepare();
       
        logger.debug("Invoking Bean: "+targetBean+"; Method: "+targetMethod+"; arguments: "+arguments+";");
       
        beanMethod.invoke();
      }catch(JobExecutionException e){
        throw e;
      }catch(Exception e){
        logger.error("定时任务[bean="+targetBean
            +",method="+targetMethod+"]执行异常:",e);
View Full Code Here

   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof JMSException) {
        throw (JMSException) targetEx;
View Full Code Here

   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      throw new ListenerExecutionFailedException(
          "Listener method '" + methodName + "' threw exception", ex.getTargetException());
    }
View Full Code Here

   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    } catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof DataAccessException) {
        throw (DataAccessException) targetEx;
      }
View Full Code Here

        }

    }

    private Runnable createTask(TaskDefinition td) {
        final MethodInvoker methodInvoker = new MethodInvoker();
        final Long taskId = td.getId();
        try {
            methodInvoker.setTargetMethod(td.getMethodName());
            Object bean = null;
            if(StringUtils.isNotEmpty(td.getBeanName())) {
                bean = applicationContext.getBean(td.getBeanName());
            } else {
                bean = applicationContext.getAutowireCapableBeanFactory().createBean(Class.forName(td.getBeanClass()));
            }
            methodInvoker.setTargetObject(bean);
            methodInvoker.prepare();
        } catch (Exception e) {
            throw new DynamicTaskException("create task runnable error, task id is : " + taskId, e);
        }
        return new Runnable() {
            @Override
            public void run() {
                try {
                    methodInvoker.invoke();
                } catch (Exception e) {
                    logger.error("run dynamic task error, task id is:" + taskId, e);
                    throw new DynamicTaskException("run dynamic task error, task id is:" + taskId, e);
                }
            }
View Full Code Here

    }
  }

  @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();
  }
View Full Code Here

   * @see #getListenerMethodName
   * @see #buildListenerArguments
   */
  protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
    try {
      MethodInvoker methodInvoker = new MethodInvoker();
      methodInvoker.setTargetObject(getDelegate());
      methodInvoker.setTargetMethod(methodName);
      methodInvoker.setArguments(arguments);
      methodInvoker.prepare();
      return methodInvoker.invoke();
    }
    catch (InvocationTargetException ex) {
      Throwable targetEx = ex.getTargetException();
      if (targetEx instanceof JMSException) {
        throw (JMSException) targetEx;
View Full Code Here

TOP

Related Classes of org.springframework.util.MethodInvoker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.