public static <T> T executeGroovyScript(final GroovyObject groovyObject,
                                            final String methodName,
                                            final Object[] args,
                                            final Class<T> clazz,
                                            final boolean failOnError) throws Throwable {
        try {
            LOGGER.trace("Executing groovy script's [{}] method, with parameters [{}]", methodName, args);
            val result = groovyObject.invokeMethod(methodName, args);
            LOGGER.trace("Results returned by the groovy script are [{}]", result);
            if (!clazz.equals(Void.class)) {
                return getGroovyScriptExecutionResultOrThrow(clazz, result);
            }
        } catch (final Throwable throwable) {
            val cause = throwable instanceof InvokerInvocationException ? throwable.getCause() : throwable;
            if (failOnError) {
                throw cause;
            }
            if (cause instanceof MissingMethodException) {
                LOGGER.debug(cause.getMessage(), cause);
            } else {
                LoggingUtils.error(LOGGER, cause);
            }
        }
        return null;
    }
Execute groovy script t.

@param <T>          the type parameter
@param groovyObject the groovy object
@param methodName   the method name
@param args         the args
@param clazz        the clazz
@param failOnError  the fail on error
@return the t
@throws Throwable the throwable
core/cas-server-core-scripting/src/main/java/org/apereo/cas/util/scripting/ScriptingUtils.java