List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:com.visural.domo.spring.TransactionInterceptor.java
License:Apache License
@Around("execution(@com.visural.domo.spring.Transactional * *(..))") public Object transactional(ProceedingJoinPoint mi) throws Throwable { MethodSignature signature = (MethodSignature) mi.getSignature(); Method method = signature.getMethod(); String connectionSource = method.getAnnotation(Transactional.class).connectionSource(); boolean alreadyTxForSource = scope.isInScope(connectionSource); scope.enter(connectionSource);// w w w . java2 s .c om try { if (scope.getSeed(connectionSource, ConnectionSource.class) == null) { GeneratorProvider gp = transactionConfig.getConnectionProvider() .getGeneratorProvider(connectionSource); scope.seed(GeneratorProvider.class, gp); ConnectionSource con = transactionConfig.getConnectionProvider().get(connectionSource); scope.seed(ConnectionSource.class, con); } if (alreadyTxForSource) { Savepoint savepoint = null; if (transactionConfig.isSavepointAndRollbackNested()) { try { savepoint = tx.savepoint(); } catch (SQLFeatureNotSupportedException ns) { // TODO: log // not supported feature } } try { return mi.proceed(); } catch (Throwable t) { if (savepoint != null) { tx.rollbackToSavepoint(savepoint); } throw t; } } else { try { Object o = mi.proceed(); tx.commit(); return o; } catch (Throwable t) { try { tx.rollback(); } catch (SQLException se) { // prefer to bubble the original error, but log Logger.getLogger(TransactionInterceptor.class.getName()).log(Level.SEVERE, "Failed rolling back transaction after prior error.", se); } throw t; } } } finally { // close connection if we are the outermost tx for this source if (!alreadyTxForSource) { IOUtil.silentClose(TransactionInterceptor.class, tx.getConnection()); } scope.exit(connectionSource); } }
From source file:com.vladmihalcea.util.ReflectionUtils.java
License:Apache License
public static <T extends Annotation> T getAnnotation(ProceedingJoinPoint pjp, Class<T> annotationClass) throws NoSuchMethodException { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); T annotation = AnnotationUtils.findAnnotation(method, annotationClass); if (annotation != null) { return annotation; }/*ww w . j a v a2 s . c o m*/ Class[] argClasses = new Class[pjp.getArgs().length]; for (int i = 0; i < pjp.getArgs().length; i++) { argClasses[i] = pjp.getArgs()[i].getClass(); } method = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), argClasses); return AnnotationUtils.findAnnotation(method, annotationClass); }
From source file:com.vmware.bdd.aop.software.DefaultPreStartServicesAdvice.java
License:Open Source License
@Around("@annotation(com.vmware.bdd.software.mgmt.plugin.aop.PreConfiguration)") public Object preClusterConfiguration(ProceedingJoinPoint pjp) throws Throwable { MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); PreConfiguration beforeConfig = AnnotationUtils.findAnnotation(method, PreConfiguration.class); String nameParam = beforeConfig.clusterNameParam(); String[] paramNames = signature.getParameterNames(); Object[] args = pjp.getArgs(); String clusterName = null;//from www . j ava 2s . c o m for (int i = 0; i < paramNames.length; i++) { if (paramNames[i].equals(nameParam)) { clusterName = (String) args[i]; } } if (clusterName == null) { logger.error("Cluster name is not specified in method"); throw BddException.INTERNAL(null, "Wrong annotation usage. Cluster name must be specified in method."); } ClusterEntity cluster = clusterEntityMgr.findByName(clusterName); if (cluster == null) { throw BddException.NOT_FOUND("Cluster", clusterName); } preStartServices(clusterName); return pjp.proceed(); }
From source file:com.vmware.bdd.aop.tx.RetryTransactionAdvice.java
License:Open Source License
public void retry(ProceedingJoinPoint pjp) throws Throwable { logger.info("retry transaction"); int retriesLeft = 5; String methodName = pjp.getSignature().getName(); MethodSignature signature = (MethodSignature) pjp.getSignature(); Method method = signature.getMethod(); if (method.getDeclaringClass().isInterface()) { method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes()); }/* www . ja v a 2 s . c om*/ Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation a : annotations) { if (a instanceof RetryTransaction) { RetryTransaction retryAnno = (RetryTransaction) a; retriesLeft = retryAnno.value(); } } RetryTransaction retryTrx = AnnotationUtils.findAnnotation(method, RetryTransaction.class); retriesLeft = retryTrx.value(); Throwable rootCause = null; boolean success = false; while (!success) { try { pjp.proceed(); success = true; } catch (Throwable ex) { rootCause = (ex instanceof BddException) ? ex.getCause() : ex; if (isRetryable(rootCause)) { if (retriesLeft > 0) { retriesLeft--; } else { throw TxRetryException.wrap(rootCause, false); } } else if (isUniqViolation(rootCause)) { throw UniqueConstraintViolationException.wrap((ConstraintViolationException) rootCause); } else { throw BddException.wrapIfNeeded(ex, "Exception in a DAL transaction."); } } } if (!success) { if (rootCause != null) { logger.warn("retry transaction failed.", rootCause); throw rootCause; } else { logger.warn("retry transction failed."); throw new Exception("retry transaction failed"); } } else { if (rootCause != null) { logger.warn("retry transaction completed. Failure root cause:" + rootCause.getMessage()); } else { logger.info("normal operation"); } } }
From source file:com.vsct.supervision.notification.log.LoggingAspect.java
License:Open Source License
@Around(value = "@within(com.vsct.supervision.notification.log.Loggable) || @annotation(com.vsct.supervision.notification.log.Loggable)") public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { final MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature(); final Method method = signature.getMethod(); final Class clazz = signature.getClass(); final Loggable loggableMethod = method.getAnnotation(Loggable.class); final Loggable loggableClass = proceedingJoinPoint.getTarget().getClass().getAnnotation(Loggable.class); //get current log level final LogLevel logLevel = loggableMethod != null ? loggableMethod.value() : loggableClass.value(); final String service = StringUtils.isNotBlank(loggableClass.service()) ? loggableClass.service() : clazz.getName();// ww w. ja v a2s . c om final String methodName = StringUtils.isNotBlank(loggableClass.method()) ? loggableClass.method() : method.getName(); final String star = "**********"; //before LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, star + service + "." + methodName + "() start execution" + star); //show traceParams final boolean showParams = loggableMethod != null ? loggableMethod.traceParams() : loggableClass.traceParams(); if (showParams) { if (proceedingJoinPoint.getArgs() != null && proceedingJoinPoint.getArgs().length > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < proceedingJoinPoint.getArgs().length; i++) { sb.append(method.getParameterTypes()[i].getName() + ":" + proceedingJoinPoint.getArgs()[i]); if (i < proceedingJoinPoint.getArgs().length - 1) sb.append(", "); } LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, service + "." + methodName + "() args " + sb); } } final long startTime = System.currentTimeMillis(); //start method execution final Object result = proceedingJoinPoint.proceed(); final long endTime = System.currentTimeMillis(); //show results if (result != null) { boolean showResults = loggableMethod != null ? loggableMethod.traceResult() : loggableClass.traceResult(); if (showResults) { LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, service + "." + methodName + "() Result : " + result); } } //show after LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, star + service + "." + methodName + "() finished execution and takes " + (endTime - startTime) + " millis time to execute " + star); return result; }
From source file:com.wms.studio.service.handler.GenericAopHandler.java
License:Apache License
private String getHandlerName(ProceedingJoinPoint point) throws NoSuchMethodException { // Object object = point.getTarget(); // Signature signature = point.getSignature(); // String name = signature.getName(); // Class<?>[] parameterTypes = ((MethodSignature) point.getSignature()) // .getMethod().getParameterTypes(); try {/*from w w w .ja v a 2 s. c o m*/ // Method method = object.getClass().getMethod(name, // parameterTypes); Method method = ((MethodSignature) point.getSignature()).getMethod(); HandlerPoint handlerPoint = method.getAnnotation(HandlerPoint.class); if (handlerPoint != null) { return handlerPoint.handlerName(); } } catch (SecurityException e) { } return null; }
From source file:com.wshsoft.springmvc.common.aop.LogAspect.java
License:Apache License
/** * ??/* w w w . j av a 2 s. c o m*/ * * @param joinPoint * * @return * @throws Throwable * */ @Around(value = "@annotation(com.wshsoft.springmvc.common.annotations.Log)") public Object saveLog(ProceedingJoinPoint joinPoint) throws Throwable { /** * ?Log */ String methodName = joinPoint.getSignature().getName(); Method method = currentMethod(joinPoint, methodName); Log log = method.getAnnotation(Log.class); /** * */ if (log != null) { logPoint.saveLog(joinPoint, methodName, log.value(), null); } /** * */ return (joinPoint).proceed(); }
From source file:com.wuxiansen.beehive.core.security.SecurityAspect.java
License:Open Source License
public Object execute(ProceedingJoinPoint pjp) throws Throwable { // ?//from ww w . jav a 2 s .c o m MethodSignature methodSignature = (MethodSignature) pjp.getSignature(); Method method = methodSignature.getMethod(); // if (method.isAnnotationPresent(IgnoreSecurity.class)) { return pjp.proceed(); } // request header ?? token String token = WebContext.getRequest().getHeader(tokenName); // token if (!tokenManager.checkToken(token)) { String message = String.format("token [%s] is invalid", token); throw new TokenException(message); } // return pjp.proceed(); }
From source file:com.yoho.core.trace.instrument.async.TraceAsyncAspect.java
License:Apache License
@Around("execution (@org.springframework.scheduling.annotation.Async * *.*(..))") public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable { Span span = this.tracer.createSpan(pjp.getSignature().getName()); this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT); this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName()); this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName()); try {//from ww w. j a va2 s. c om return pjp.proceed(); } finally { this.tracer.close(span); } }
From source file:com.yoho.core.trace.instrument.scheduling.TraceSchedulingAspect.java
License:Apache License
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))") public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable { String spanName = pjp.getSignature().getName(); Span span = this.tracer.createSpan(spanName); this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, SCHEDULED_COMPONENT); this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName()); this.tracer.addTag(this.traceKeys.getAsync().getPrefix() + this.traceKeys.getAsync().getMethodNameKey(), pjp.getSignature().getName()); try {// w w w. j a v a2 s. com return pjp.proceed(); } finally { this.tracer.close(span); } }