日期:2014-05-17 浏览次数:20768 次
protected String invokeAction(Object action, ActionConfig actionConfig) throws Exception { String methodName = proxy.getMethod(); if (LOG.isDebugEnabled()) { LOG.debug("Executing action method = " + actionConfig.getMethodName()); } String timerKey = "invokeAction: "+proxy.getActionName(); try { UtilTimerStack.push(timerKey); Method method; try { method = getAction().getClass().getMethod(methodName, new Class[0]); } catch (NoSuchMethodException e) { // hmm -- OK, try doXxx instead try { String altMethodName = "do" + methodName.substring(0, 1).toUpperCase() + methodName.substring(1); method = getAction().getClass().getMethod(altMethodName, new Class[0]); } catch (NoSuchMethodException e1) { // throw the original one throw e; } } Object methodResult = null; if (action instanceof Proxy) { try { methodResult = Proxy.getInvocationHandler(action).invoke(action, method, new Object[0]); } catch (Throwable throwable) { throwable.printStackTrace(); throw new Exception("Error invoking on proxy: " + throwable.getMessage()); } } else { methodResult = method.invoke(action, new Object[0]); } if (methodResult instanceof Result) { this.result = (Result) methodResult; return null; } else { return (String) methodResult; } } catch (NoSuchMethodException e) { throw new IllegalArgumentException("The " + methodName + "() is not defined in action " + getAction().getClass() + ""); } catch (InvocationTargetException e) { // We try to return the source exception. Throwable t = e.getTargetException(); if (actionEventListener != null) { String result = actionEventListener.handleException(t, getStack()); if (result != null) { return result; } } if (t instanceof Exception) { throw(Exception) t; } else { throw e; } } finally { UtilTimerStack.pop(timerKey); } }