List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:nl.strohalm.cyclos.aop.TraceAspect.java
License:Open Source License
/** * Execute the trace/* w w w. jav a 2s . co m*/ */ private Object doTrace(final ProceedingJoinPoint joinPoint) throws Throwable { // Retrieve the method reference final Signature signature = joinPoint.getSignature(); final Method method = ((MethodSignature) signature).getMethod(); // Retrieve the permission descriptor for that method final ServicePermissionsDescriptor descriptor = getPermissionDescriptor(method); if (descriptor.isSkipPermissionCheck() || (descriptor.isForSystem() && CurrentInvocationData.isSystemInvocation())) { // only log client invocations not annotated with the DontEnforcePermission annotation or marked as traceable. if ((!descriptor.isSkipPermissionCheck() || descriptor.isTraceableAction()) && !CurrentInvocationData.isSystemInvocation()) { return executeAndLogAction(null, joinPoint); } else { // This is not an action, proceed normally return joinPoint.proceed(); } } else if (descriptor.isOnlyForSystem() && !CurrentInvocationData.isSystemInvocation()) { throw new PermissionDeniedException(); } else if (!descriptor.isAnnotated()) { throw new IllegalArgumentException("The method '" + method + "' is not secured correctly. It must be annotated using some of the security annotations."); } else { // This is an action - verify related member permission final Object[] args = joinPoint.getArgs(); final PermissionCheck check = descriptor.checkPermission(args.length == 0 ? null : args[0]); if (!check.isGranted()) { // Determine if log is being generated final boolean generateLog = loggingHandler.isTraceEnabled() && LoggedUser.isValid(); if (generateLog) { loggingHandler.logPermissionDenied(LoggedUser.user(), method, args); } throw new PermissionDeniedException(); } // Log the action execution return executeAndLogAction(check, joinPoint); } }
From source file:nl.strohalm.cyclos.aop.TraceAspect.java
License:Open Source License
private Object executeAndLogAction(final PermissionCheck check, final ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = null;//from www . j a v a 2 s . c om Signature signature = null; Method method = null; Permission permission = null; // Determine if log is being generated final boolean generateLog = loggingHandler.isTraceEnabled() && LoggedUser.isValid(); if (generateLog) { args = joinPoint.getArgs(); signature = joinPoint.getSignature(); method = ((MethodSignature) signature).getMethod(); permission = check == null ? null : check.getPermission(); } try { final Object retVal = joinPoint.proceed(); if (generateLog) { loggingHandler.trace(LoggedUser.remoteAddress(), LoggedUser.user(), permission, method, args, retVal); } return retVal; } catch (final Throwable t) { if (generateLog) { loggingHandler.traceError(LoggedUser.user(), permission, method, args, t); } throw t; } }
From source file:nl.thehyve.podium.common.aop.logging.LoggingAspect.java
License:Apache License
/** * Advice that logs when a method is entered and exited. * * @param joinPoint The binding joinpoint * @throws Throwable Throws IllegalArgumentException * @return Object The result object// w ww . jav a2 s.c om */ @Around("loggingPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { if (log.isDebugEnabled()) { log.debug("Enter: {}.{}() with argument[s] = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs())); } try { Object result = joinPoint.proceed(); if (log.isDebugEnabled()) { log.debug("Exit: {}.{}() with result = {}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), result); } return result; } catch (IllegalArgumentException e) { log.error("Illegal argument: {} in {}.{}()", Arrays.toString(joinPoint.getArgs()), joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); throw e; } }
From source file:org.a3badran.platform.logging.aspect.LogClassAspect.java
License:MIT License
@Around("within(@org.a3badran.platform.logging.annotation.LogClassRequests *)") public Object log(ProceedingJoinPoint joinPoint) throws Throwable { // if method non-public skip if (!Modifier.isPublic(joinPoint.getSignature().getModifiers())) { return joinPoint.proceed(); }//from w w w . ja v a2 s . com // use method name String name = joinPoint.getSignature().getName(); if (joinPoint.getTarget() != null && joinPoint.getTarget().getClass() != null) { name = joinPoint.getTarget().getClass().getSimpleName() + "." + name; } // start the scope RequestScope scope = RequestLogger.startScope(name); try { return joinPoint.proceed(); } catch (Throwable t) { if (RequestLogger.getRequestErrorHandler() != null) { RequestLogger.getRequestErrorHandler().handleError(t); } else { RequestLogger.addError(t.toString()); } throw t; } finally { // close the scope no matter what RequestLogger.endScope(scope); } }
From source file:org.a3badran.platform.logging.aspect.LogRequestAspect.java
License:MIT License
@Around(value = "@annotation(LogRequest)", argNames = "joinPoint,LogRequest") public Object log(ProceedingJoinPoint joinPoint, LogRequest logRequest) throws Throwable { String name = logRequest.value(); // use method name if @LogRequest(name) is null if (name == null || name.isEmpty()) { name = joinPoint.getSignature().getName(); if (joinPoint.getTarget() != null && joinPoint.getTarget().getClass() != null) { name = joinPoint.getTarget().getClass().getSimpleName() + "." + name; }/*from w w w . j a v a2s. co m*/ } // start the scope RequestScope scope = RequestLogger.startScope(name); try { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); String methodName = signature.getMethod().getName(); Class<?>[] parameterTypes = signature.getMethod().getParameterTypes(); Annotation[][] annotations; annotations = joinPoint.getTarget().getClass().getMethod(methodName, parameterTypes) .getParameterAnnotations(); int i = 0; for (Object arg : joinPoint.getArgs()) { for (Annotation annotation : annotations[i]) { if (annotation.annotationType() == LogParam.class) { String string = arg == null ? "null" : arg.toString(); RequestLogger.addInfo(((LogParam) annotation).value(), string); } } i++; } // run the method // NOTE: exceptions thrown before the actual method is called will result in failure. // TODO: configure the ability to bypass exception prior to method calling. return joinPoint.proceed(); } catch (Throwable t) { if (RequestLogger.getRequestErrorHandler() != null) { RequestLogger.getRequestErrorHandler().handleError(t); } else { RequestLogger.addError(t.toString()); } throw t; } finally { // close the scope no matter what RequestLogger.endScope(scope); } }
From source file:org.alfresco.traitextender.RouteExtensions.java
License:Open Source License
@Around("execution(@org.alfresco.traitextender.Extend * *(..)) && (@annotation(extendAnnotation))") public Object intercept(ProceedingJoinPoint pjp, Extend extendAnnotation) throws Throwable { boolean ajPointsEnabled = AJExtender.areAJPointsEnabled(); try {//from ww w . j ava 2s. co m AJExtender.enableAJPoints(); if (ajPointsEnabled) { Object extensibleObject = pjp.getThis(); if (!(extensibleObject instanceof Extensible)) { throw new InvalidExtension( "Invalid extension point for non extensible class : " + extensibleObject.getClass()); } Extensible extensible = (Extensible) extensibleObject; @SuppressWarnings({ "rawtypes", "unchecked" }) ExtensionPoint point = new ExtensionPoint(extendAnnotation.extensionAPI(), extendAnnotation.traitAPI()); @SuppressWarnings("unchecked") Object extension = Extender.getInstance().getExtension(extensible, point); if (extension != null) { return AJExtender.extendAroundAdvice(pjp, extensible, extendAnnotation, extension); } else if (logger.isDebugEnabled()) { MethodSignature ms = (MethodSignature) pjp.getSignature(); Method traitMethod = ms.getMethod(); AJExtender.oneTimeLiveLog(logger, new ExtensionRoute(extendAnnotation, traitMethod)); } } return pjp.proceed(); } finally { AJExtender.revertAJPoints(); } }
From source file:org.ameba.aop.IntegrationLayerAspect.java
License:Apache License
/** * Around intercepted methods do some logging and exception translation. <p> <ul> <li> Set log level of {@link * LoggingCategories#INTEGRATION_LAYER_ACCESS} to INFO to enable method tracing. <li>Set log level of {@link * LoggingCategories#INTEGRATION_LAYER_EXCEPTION} to ERROR to enable exception logging. </ul> </p> * * @param pjp The joinpoint/*from www .ja v a 2 s .co m*/ * @return Method return value * @throws Throwable in case of errors */ @Around("org.ameba.aop.Pointcuts.integrationPointcut()") public Object measure(ProceedingJoinPoint pjp) throws Throwable { StopWatch sw = null; if (P_LOGGER.isInfoEnabled()) { sw = new StopWatch(); sw.start(); P_LOGGER.info("[I]>> {}#{}", pjp.getTarget().getClass().getSimpleName(), pjp.getSignature().getName()); } try { return pjp.proceed(); } catch (Exception ex) { throw translateException(ex); } finally { if (P_LOGGER.isInfoEnabled() && sw != null) { sw.stop(); P_LOGGER.info("[I]<< {}#{} took {} [ms]", pjp.getTarget().getClass().getSimpleName(), pjp.getSignature().getName(), sw.getTotalTimeMillis()); } } }
From source file:org.apache.atlas.aspect.AtlasAspect.java
License:Apache License
@Around("@annotation(org.apache.atlas.aspect.Monitored) && execution(* *(..))") public Object collectMetricsForMonitored(ProceedingJoinPoint joinPoint) throws Throwable { Signature methodSign = joinPoint.getSignature(); Metrics metrics = RequestContext.getMetrics(); String metricName = methodSign.getDeclaringType().getSimpleName() + "." + methodSign.getName(); long start = System.currentTimeMillis(); try {//from w w w .j av a2s . com Object response = joinPoint.proceed(); return response; } finally { metrics.record(metricName, (System.currentTimeMillis() - start)); } }
From source file:org.apache.atlas.aspect.AtlasAspect.java
License:Apache License
@Around("@annotation(org.apache.atlas.aspect.Loggable) && execution(* *(..))") public Object logAroundLoggable(ProceedingJoinPoint joinPoint) throws Throwable { Signature methodSign = joinPoint.getSignature(); String methodName = methodSign.getDeclaringType().getSimpleName() + "." + methodSign.getName(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("==> %s(%s)", methodName, Arrays.toString(joinPoint.getArgs()))); }//from ww w.j a v a2s. c om Object response = joinPoint.proceed(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("<== %s(%s): %s", methodName, Arrays.toString(joinPoint.getArgs()), response instanceof List ? ((List) response).size() : response)); } return response; }
From source file:org.apache.cloudstack.storage.test.AopTestAdvice.java
License:Apache License
public Object AopTestMethod(ProceedingJoinPoint call) throws Throwable { Transaction txn = Transaction.open(call.getSignature().getName()); Object ret = null;/* ww w. jav a 2s.c om*/ try { ret = call.proceed(); } finally { txn.close(); } return ret; }