Java Code Examples for net.sf.cglib.proxy.MethodProxy#invoke()

The following examples show how to use net.sf.cglib.proxy.MethodProxy#invoke() . 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: LibCGDecoratorGenerator.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    if(isDecorated(method)) {
        // Decorated method
        return proxy.invokeSuper(obj, args);
    } else {
        final T t = ((Decorator<T>) obj).delegate();
        if(method.getDeclaringClass().isInstance(t)) {
            // Forwarded method
            return proxy.invoke(t, args);
        } else {
            // Forwarded method shadowed by an interface method in the decorator.
            //
            // This can happen if the decorator implements an interface that the
            // base class doesn't, and that interface contains a method that shadows
            // one on the base class. Java would allow the method to be called on the
            // base anyway, but MethodProxy refuses to invoke it on something that
            // is not assignable to the method's declaring type. So, unfortunately,
            // we have to fall back to the JDK to handle this case.
            return methodHandles.get(method, () ->
                resolver.virtualHandle(t.getClass(), method).bindTo(t)
            ).invokeWithArguments(args);
        }
    }
}
 
Example 2
Source File: RealSubjectIntercept.java    From Java-Interview with MIT License 5 votes vote down vote up
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

    LOGGER.info("before");

    Object invoke = methodProxy.invoke(o, objects);
    LOGGER.info("after");
    return invoke;
}
 
Example 3
Source File: CGLIBProxy.java    From Mykit with Apache License 2.0 5 votes vote down vote up
/**
 * 在代理实例上处理方法调用并返回结果
 * @param object : 代理类
 * @param method  :被代理的方法
 * @param args :该方法的参数数组
 * @param methodProxy : 方法代理
 */
@Override
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodproxy) throws Throwable {
	Object result = null;
	try {
		System.out.println("前置处理开始 ...");
		result = methodproxy.invoke(targetObject, args);// 执行目标对象的方法
		System.out.println("后置处理开始  ...");
	} catch (Exception e) {
		System.out.println(" 异常处理 ...");
	} finally {
		System.out.println(" 调用结束 ...");
	}
	return result;
}
 
Example 4
Source File: RealSubjectIntercept.java    From Java-Interview with MIT License 5 votes vote down vote up
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

    LOGGER.info("before");

    Object invoke = methodProxy.invoke(o, objects);
    LOGGER.info("after");
    return invoke;
}
 
Example 5
Source File: EagleRpcCglibRemoteInvoke.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Override
protected Object invoke(Request request, MethodProxy method) throws Throwable {
    return method.invoke(invokeImpl, request.getParameters());
}
 
Example 6
Source File: RefreshableProxy.java    From config-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
public Object intercept(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable {
	return proxy.invoke(target, args);
}
 
Example 7
Source File: CglibThrowableRendererTest.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    return proxy.invoke(new SampleClass(), args);
}