/** * Returns a lambda function (for use in spEL). * * @param instance Object instance that is target of method invocation. * @param methodName Name of the method to invoke. * @param args Optional additional arguments. * @return The lambda function. */ public Function<?, ?> lambda(Object instance, String methodName, Object... args) { int last = args == null ? 0 : args.length; Object[] realArgs = args == null ? new Object[] { null } : Arrays.copyOf(args, last + 1); return arg -> { try { realArgs[last] = arg; return MethodUtils.invokeMethod(instance, methodName, realArgs, MiscUtil.getParameterTypes(realArgs)); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }; }
/** * Invoke the request on the target. * * @param request The request to invoke. */ private void invokeRequest(InvocationRequest request) { try { MethodUtils.invokeMethod(target, request.getMethodName(), request.getArgs(), MiscUtil.getParameterTypes(request.getArgs())); } catch (Exception e) { log.error("Remote invocation error.", e); } }