Java Code Examples for org.aopalliance.intercept.MethodInvocation#proceed()

The following examples show how to use org.aopalliance.intercept.MethodInvocation#proceed() . 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: CompletionRegisteringBeanPostProcessor.java    From spring-domain-events with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {

	Object result = invocation.proceed();
	Method method = invocation.getMethod();

	// Mark publication complete if the method is a transactional event listener.
	if (!isCompletingMethod(method)) {
		return result;
	}

	PublicationTargetIdentifier identifier = PublicationTargetIdentifier.forMethod(method);
	registry.get().markCompleted(invocation.getArguments()[0], identifier);

	return result;
}
 
Example 2
Source File: DigestLogger.java    From AnyMock with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Method method = invocation.getMethod();
    Class<?> clazz = method.getDeclaringClass();
    Object retValue = null;
    String result = "N";
    long beginTime = System.currentTimeMillis();

    try {
        retValue = invocation.proceed();
        result = "Y";
    } finally {
        long endTime = System.currentTimeMillis();
        logger.info("[({}.{},{},{}ms)({})({})]", clazz.getSimpleName(), method.getName(),
                result, endTime - beginTime, getArgumentsString(invocation),
                getResultsString(retValue));
    }

    return retValue;
}
 
Example 3
Source File: JamonPerformanceMonitorInterceptor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Wraps the invocation with a JAMon Monitor and writes the current
 * performance statistics to the log (if enabled).
 * @see com.jamonapi.MonitorFactory#start
 * @see com.jamonapi.Monitor#stop
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = createInvocationTraceName(invocation);
	MonKey key = new MonKeyImp(name, name, "ms.");

	Monitor monitor = MonitorFactory.start(key);
	try {
		return invocation.proceed();
	}
	catch (Throwable ex) {
		trackException(key, ex);
		throw ex;
	}
	finally {
		monitor.stop();
		if (!this.trackAllInvocations || isLogEnabled(logger)) {
			writeToLog(logger, "JAMon performance statistics for method [" + name + "]:\n" + monitor);
		}
	}
}
 
Example 4
Source File: ReactivePersistenceExceptionTranslationInterceptor.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {

	// Invoke the method potentially returning a reactive type
	Object m = mi.proceed();

	PersistenceExceptionTranslator translator = getPersistenceExceptionTranslator();
	if (translator == null) {
		return m;
	} else {
		// Add the translation. Nothing will happen if no-one subscribe the reactive result.
		Function<RuntimeException, Throwable> errorMappingFunction =
			t -> t instanceof DataAccessException ? t : DataAccessUtils.translateIfNecessary(t, translator);
		if (m instanceof Mono) {
			return ((Mono<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction);
		} else if (m instanceof Flux) {
			return ((Flux<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction);
		} else {
			return m;
		}
	}
}
 
Example 5
Source File: PermissionCheckInterceptor.java    From boubei-tss with Apache License 2.0 6 votes vote down vote up
public Object invoke(MethodInvocation invocation) throws Throwable {
    Method targetMethod = invocation.getMethod(); /* 获取目标方法 */
    Object[] args = invocation.getArguments(); /* 获取目标方法的参数 */
    Object returnVal = invocation.proceed(); /* 调用目标方法的返回值 */

    PermissionTag tag = targetMethod.getAnnotation(PermissionTag.class); // 取得注释对象
    if (tag != null) {
    	IPermissionFilter filter = (IPermissionFilter)BeanUtil.newInstance(tag.filter());
    	
    	log.debug("对方法:" + targetMethod + " 进行权限检查(或过滤)开始。");
    	filter.doFilter(args, returnVal, tag, PermissionHelper.getInstance());
    	log.debug("对方法:" + targetMethod + " 权限检查(或过滤)结束。");
    }

    return returnVal;
}
 
Example 6
Source File: ApiBootDataSourceSwitchAnnotationInterceptor.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    try {
        Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
        Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
        Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
        // get class declared DataSourceSwitch annotation
        DataSourceSwitch dataSourceSwitch = targetClass.getDeclaredAnnotation(DataSourceSwitch.class);
        if (dataSourceSwitch == null) {
            // get declared DataSourceSwitch annotation
            dataSourceSwitch = userDeclaredMethod.getDeclaredAnnotation(DataSourceSwitch.class);
        }
        if (dataSourceSwitch != null) {
            // setting current thread use data source pool name
            DataSourceContextHolder.set(dataSourceSwitch.value());
        }
        return invocation.proceed();
    } finally {
        // remove current thread use datasource pool name
        DataSourceContextHolder.remove();
    }

}
 
Example 7
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	Object proxy = AopContext.currentProxy();
	Object ret = mi.proceed();
	assertEquals(proxy, AopContext.currentProxy());
	return ret;
}
 
Example 8
Source File: TestHandlerInterception.java    From ja-micro with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
    beforeExecuted = true;
    Object result = invocation.proceed();
    afterExecuted = true;

    return result;
}
 
Example 9
Source File: DelayQueueInterceptor.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation arg) throws Throwable {
    Delay delayAnnotation = arg.getMethod().getAnnotation(Delay.class);
    if (delayAnnotation != null) {
        this.setDelay(delayAnnotation.queue(), delayAnnotation.interval());
        return arg.proceed();
    } else {
        return arg.proceed();
    }
}
 
Example 10
Source File: EventPublicationInterceptor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
	Object retVal = invocation.proceed();

	Assert.state(this.applicationEventClassConstructor != null, "No ApplicationEvent class set");
	ApplicationEvent event = (ApplicationEvent)
			this.applicationEventClassConstructor.newInstance(invocation.getThis());

	Assert.state(this.applicationEventPublisher != null, "No ApplicationEventPublisher available");
	this.applicationEventPublisher.publishEvent(event);

	return retVal;
}
 
Example 11
Source File: LimiterAspectSupport.java    From Limiter with Apache License 2.0 5 votes vote down vote up
/**
 * @param invocation
 * @param target
 * @param method
 * @param args
 * @return
 * @throws Throwable
 */
protected Object execute(final MethodInvocation invocation, Object target, Method method, Object[] args) throws Throwable {

    if (this.initialized) {
        Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
        LimitedResourceSource limitedResourceSource = getLimitedResourceSource();
        if (limitedResourceSource != null) {
            Collection<LimitedResource> limitedResources = limitedResourceSource.getLimitedResource(targetClass, method);
            if (!CollectionUtils.isEmpty(limitedResources)) {
                Collection<LimiterExecutionContext> contexts = getLimiterOperationContexts(limitedResources, method, args, target, targetClass);
                LimitContextsValueWrapper limitContextsValueWrapper = limitContexts(contexts);
                if (limitContextsValueWrapper.value()) {
                    try {
                        return invocation.proceed();
                    } catch (Throwable e) {
                        throw e;
                    } finally {
                        releaseContexts(contexts);
                    }
                } else {
                    return limitContextsValueWrapper.getLimiterFailResolveResult();
                }

            }
        }
    }
    return invocation.proceed();
}
 
Example 12
Source File: QuickPerfProxyBeanPostProcessor.java    From quickperf with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
    Method proxyMethod = ReflectionUtils.findMethod( this.datasourceProxy.getClass()
                                                          ,invocation.getMethod().getName());
    if (proxyMethod != null) {
        return proxyMethod.invoke(this.datasourceProxy, invocation.getArguments());
    }
    return invocation.proceed();
}
 
Example 13
Source File: OperateInfoInterceptor.java    From boubei-tss with Apache License 2.0 4 votes vote down vote up
public Object invoke(MethodInvocation invocation) throws Throwable {
	Object target = invocation.getThis();
	Object[] args = invocation.getArguments();
	args = (Object[]) EasyUtils.checkNull(args, new Object[]{});
	
       for (int i = 0; i < args.length; i++) {
           int manipulateKind = judgeManipulateKind(invocation.getMethod().getName());
           if (args[i] instanceof IOperatable 
           		&& (manipulateKind == SAVE || manipulateKind == UPDATE)) {
              
               IOperatable opObj = (IOperatable) args[i];
               Serializable pk = ((IEntity)opObj).getPK();
               
			if( pk == null ) { // ID为null,说明是新建
                   opObj.setCreateTime(new Date());
                   opObj.setCreatorId(Environment.getUserId());
                   opObj.setCreatorName(Environment.getUserName());  
                   
                   // 定时器写数据时,域信息已经指定
                   String domain = (String) EasyUtils.checkNull( opObj.getDomain(), Environment.getDomainOrign() );
                   opObj.setDomain(domain);
               } 
               else {
                   opObj.setUpdateTime(new Date());
                   opObj.setUpdatorId(Environment.getUserId());
                   opObj.setUpdatorName(Environment.getUserName());  
                   
                   /* 修改后,createTime的时分秒没了(日期传递到前台时截去了时分秒,保存后就没有了),
                    * update时不要前台传入的createTime,而是从DB查出来复制回去
                    */
                   @SuppressWarnings("unchecked")
                   IDao<IEntity> dao = (IDao<IEntity>) target;
                   IOperatable old = (IOperatable) dao.getEntity( opObj.getClass(), pk);
                   old = (IOperatable) EasyUtils.checkNull(old, opObj); // 可能修改时记录已被其它人[删除]
                   opObj.setCreateTime(old.getCreateTime());
               }
           }
       }
		
       return invocation.proceed();
}
 
Example 14
Source File: AlwaysProceedMethodInterceptor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Object invoke(MethodInvocation mi) throws Throwable
{
    return mi.proceed();
}
 
Example 15
Source File: XssResolveAdviceInterceptor.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
@Override
public Object invoke(MethodInvocation invc) throws Throwable {
	Object controller = invc.getThis();
	Method md = invc.getMethod();
	try {
		// Type or method exist @UnsafeXss ignore?
		if (controller.getClass().isAnnotationPresent(UnsafeXss.class) || md.isAnnotationPresent(UnsafeXss.class)) {
			return invc.proceed();
		}

		Object[] args = invc.getArguments();
		if (!isNull(args)) {
			next: for (int i = 0; i < args.length; i++) {
				if (args[i] == null)
					continue;

				// Parameter ignore?
				for (Annotation[] anns : md.getParameterAnnotations()) {
					for (Annotation an : anns) {
						if (an.annotationType() == UnsafeXss.class) {
							continue next;
						}
					}
				}

				// Parameter declared type ignore?
				if (args[i].getClass().isAnnotationPresent(UnsafeXss.class)) {
					continue next;
				}

				// Processing HttpServlet request(if necessary)
				args[i] = processHttpRequestIfNecessary(args[i]);

				if (args[i] instanceof String) {
					args[i] = stringXssEncode(controller, md, i, (String) args[i]);
				} else {
					objectXssEnode(controller, md, i, args[i]);
				}
			}
		}
	} catch (Throwable e) {
		log.error("XSS resolving failure. causes at: ", e);
	}

	// Sets XSS protection headers.
	setXssProtectionHeadersIfNecessary(controller, md);

	return invc.proceed();
}
 
Example 16
Source File: AspectJExpressionPointcutAdvisorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
	count++;
	return methodInvocation.proceed();
}
 
Example 17
Source File: PrototypeTargetTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
	invocationCount++;
	return methodInvocation.proceed();
}
 
Example 18
Source File: DatasourceInterceptor.java    From icure-backend with GNU General Public License v2.0 4 votes vote down vote up
public Object invoke(MethodInvocation inv) throws Throwable {
	drugsDAO.openDataStoreSession();
	Object result = inv.proceed();
	drugsDAO.closeDataStoreSession();
	return result;
}
 
Example 19
Source File: AfterReturningAdviceInterceptor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	Object retVal = mi.proceed();
	this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
	return retVal;
}
 
Example 20
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
	this.target = invocation.getThis();
	return invocation.proceed();
}