private RewriteMatch invokeRunMethod(Object classInstanceToRun,HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,FilterChain chain,Object[] matchObjs) throws ServletException, InvocationTargetException {
  if (log.isDebugEnabled()) {
    log.debug("running " + classStr + "."+ getMethodSignature()+ " ");
  }
  if (classInstanceToRun == null || runMethod == null)   return null;
  RewriteMatch returned=null;
  Object[] params=null;
  if (runMethodParams != null && runMethodParams.length > 0) {
    params=new Object[runMethodParams.length];
    int paramMatchCounter=0;
    for (int i=0; i < runMethodParams.length; i++) {
      Class runMethodParam=runMethodParams[i];
      String runMethodParamName=null;
      if (runMethodParamNames != null && runMethodParamNames.length > i) {
        runMethodParamName=runMethodParamNames[i];
      }
      Object param;
      if (runMethodParamName != null) {
        log.debug("need parameter from request called " + runMethodParamName);
        Object matchObj=httpServletRequest.getParameter(runMethodParamName);
        param=TypeUtils.getConvertedParam(runMethodParam,matchObj);
      }
 else       if (runMethodParam.isAssignableFrom(HttpServletRequest.class)) {
        param=httpServletRequest;
      }
 else       if (runMethodParam.isAssignableFrom(HttpServletResponse.class)) {
        param=httpServletResponse;
      }
 else       if (runMethodParam.isAssignableFrom(FilterChain.class)) {
        param=chain;
      }
 else {
        Object matchObj=null;
        if (matchObjs != null && matchObjs.length > paramMatchCounter) {
          matchObj=matchObjs[paramMatchCounter];
        }
        param=TypeUtils.getConvertedParam(runMethodParam,matchObj);
        paramMatchCounter++;
      }
      params[i]=param;
      if (log.isDebugEnabled()) {
        log.debug("argument " + i + " ("+ runMethodParam.getName()+ "): "+ param);
      }
    }
  }
  try {
    Object objReturned=runMethod.invoke(classInstanceToRun,(Object[])params);
    if (jsonHandler) {
      returned=new JsonRewriteMatch(objReturned);
    }
 else     if (objReturned != null && objReturned instanceof RewriteMatch) {
      returned=(RewriteMatch)objReturned;
    }
  }
 catch (  IllegalAccessException e) {
    if (log.isDebugEnabled())     log.debug(e);
    throw new ServletException(e);
  }
  return returned;
}

private RewriteMatch invokeRunMethod ( Object classInstanceToRun , HttpServletRequest httpServletRequest , HttpServletResponse httpServletResponse , FilterChain chain , Object [ ] matchObjs ) throws ServletException , InvocationTargetException { if ( log . isDebugEnabled ( ) ) { log . debug ( "running " + classStr + "." + getMethodSignature ( ) + " " ) ; } if ( classInstanceToRun == null || runMethod == null ) return null ; RewriteMatch returned = null ; Object [ ] params = null ; if ( runMethodParams != null && runMethodParams . length > 0 ) { params = new Object [ runMethodParams . length ] ; int paramMatchCounter = 0 ; for ( int i = 0 ; i < runMethodParams . length ; i ++ ) { Class runMethodParam = runMethodParams [ i ] ; String runMethodParamName = null ; if ( runMethodParamNames != null && runMethodParamNames . length > i ) { runMethodParamName = runMethodParamNames [ i ] ; } Object param ; if ( runMethodParamName != null ) { log . debug ( "need parameter from request called " + runMethodParamName ) ; Object matchObj = httpServletRequest . getParameter ( runMethodParamName ) ; param = TypeUtils . getConvertedParam ( runMethodParam , matchObj ) ; } else if ( runMethodParam . isAssignableFrom ( HttpServletRequest . class ) ) { param = httpServletRequest ; } else if ( runMethodParam . isAssignableFrom ( HttpServletResponse . class ) ) { param = httpServletResponse ; } else if ( runMethodParam . isAssignableFrom ( FilterChain . class ) ) { param = chain ; } else { Object matchObj = null ; if ( matchObjs != null && matchObjs . length > paramMatchCounter ) { matchObj = matchObjs [ paramMatchCounter ] ; } param = TypeUtils . getConvertedParam ( runMethodParam , matchObj ) ; paramMatchCounter ++ ; } params [ i ] = param ; if ( log . isDebugEnabled ( ) ) { log . debug ( "argument " + i + " (" + runMethodParam . getName ( ) + "): " + param ) ; } } } try { Object objReturned = runMethod . invoke ( classInstanceToRun , ( Object [ ] ) params ) ; if ( jsonHandler ) { returned = new JsonRewriteMatch ( objReturned ) ; } else if ( objReturned != null && objReturned instanceof RewriteMatch ) { returned = ( RewriteMatch ) objReturned ; } } catch ( IllegalAccessException e ) { if ( log . isDebugEnabled ( ) ) log . debug ( e ) ; throw new ServletException ( e ) ; } return returned ; }
invokes the run method . < p / > exceptions at invocation time are either rethrown as a servletexception or as thr original exception if we can manage to do it . < p / > we don ' t log exceptions here , the container can do that .
