Java Code Examples for com.jfinal.aop.Invocation#getArgs()

The following examples show how to use com.jfinal.aop.Invocation#getArgs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSentinelProccesser.java    From jboot with Apache License 2.0 6 votes vote down vote up
protected Object handleBlockException(Invocation inv, SentinelResource annotation, BlockException ex)
        throws Throwable {

    // Execute block handler if configured.
    Method blockHandlerMethod = extractBlockHandlerMethod(inv, annotation.blockHandler(),
            annotation.blockHandlerClass());
    if (blockHandlerMethod != null) {
        Object[] originArgs = inv.getArgs();
        // Construct args.
        Object[] args = Arrays.copyOf(originArgs, originArgs.length + 1);
        args[args.length - 1] = ex;
        try {
            if (isStatic(blockHandlerMethod)) {
                return blockHandlerMethod.invoke(null, args);
            }
            return blockHandlerMethod.invoke(inv.getTarget(), args);
        } catch (InvocationTargetException e) {
            // throw the actual exception
            throw e.getTargetException();
        }
    }

    // If no block handler is present, then go to fallback.
    return handleFallback(inv, annotation, ex);
}
 
Example 2
Source File: AbstractSentinelProccesser.java    From jboot with Apache License 2.0 5 votes vote down vote up
protected Object handleFallback(Invocation inv, String fallback, String defaultFallback,
                                Class<?>[] fallbackClass, Throwable ex) throws Throwable {
    Object[] originArgs = inv.getArgs();

    // Execute fallback function if configured.
    Method fallbackMethod = extractFallbackMethod(inv, fallback, fallbackClass);
    if (fallbackMethod != null) {
        // Construct args.
        int paramCount = fallbackMethod.getParameterTypes().length;
        Object[] args;
        if (paramCount == originArgs.length) {
            args = originArgs;
        } else {
            args = Arrays.copyOf(originArgs, originArgs.length + 1);
            args[args.length - 1] = ex;
        }

        try {
            if (isStatic(fallbackMethod)) {
                return fallbackMethod.invoke(null, args);
            }
            return fallbackMethod.invoke(inv.getTarget(), args);
        } catch (InvocationTargetException e) {
            // throw the actual exception
            throw e.getTargetException();
        }
    }
    // If fallback is absent, we'll try the defaultFallback if provided.
    return handleDefaultFallback(inv, defaultFallback, fallbackClass, ex);
}