List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:org.hyperic.hq.monitor.aop.aspects.PerformanceMonitor.java
License:Open Source License
/** * We could bind the @Transactional annotation to the context but there's no * way to know if the method or the type is annotated, causing a false * negative.//from ww w . j a va2 s.c om * @see org.hyperic.hq.monitor.aop.MonitorArchitecture * @param pjp */ @Around("org.hyperic.hq.monitor.aop.MonitorArchitecture.serviceLayerOperationDuration()") public Object monitorServiceMethod(ProceedingJoinPoint pjp) throws Throwable { Object invocation = null; final StopWatch timer = new StopWatch(pjp.getSignature() + Thread.currentThread().getName()); try { timer.start(); invocation = pjp.proceed(); } finally { timer.stop(); } long duration = timer.getTotalTimeMillis(); if (duration > maximumDuration) { logger.warn(new StringBuilder(warningMessage).append(pjp.getSignature()).append(" executed in ") .append(timer.getTotalTimeMillis()).append(":ms").toString()); } return invocation; }
From source file:org.imsglobal.aspect.LtiLaunchVerifier.java
@Around("@annotation(launch)") public Object verifyLtiLaunch(ProceedingJoinPoint pjp, Lti launch) throws Throwable { HttpServletRequest request = null;/*from w w w. j a v a 2 s . c o m*/ for (Object arg : pjp.getArgs()) { if (HttpServletRequest.class.isInstance(arg)) { request = (HttpServletRequest) arg; } } if (request == null) { throw new IllegalStateException( getErrorMessageForArgumentClass("HttpServletRequest", pjp.getSignature().toLongString())); } String oauthSecret = keyService.getSecretForKey(request.getParameter("oauth_consumer_key")); LtiVerificationResult ltiResult = ltiVerifier.verify(request, oauthSecret);//BasicLTIUtil.validateMessage(request, request.getRequestURL().toString(), oauthSecret); Boolean ltiVerificationResultExists = false; //This array will hold the arguments to the join point, so we can pass them along to the advised function. List<Object> args = new ArrayList<>(pjp.getArgs().length); for (Object arg : pjp.getArgs()) { if (arg.getClass().equals(LtiVerificationResult.class)) { args.add(ltiResult); ltiVerificationResultExists = true; } else { args.add(arg); } } if (!ltiVerificationResultExists) { throw new IllegalStateException( getErrorMessageForArgumentClass("LtiVerificationResult", pjp.getSignature().toLongString())); } return pjp.proceed(args.toArray()); }
From source file:org.iobserve.monitoring.probe.aspectj.AbstractOperationExecutionWithParameterAspect.java
License:Apache License
@Around("monitoredOperation() && this(thisObject) && notWithinKieker()") public Object operation(final Object thisObject, final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS // (Throwable) if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); }// w w w . j a v a 2 s . c o m final String operationSignature = this.signatureToLongString(thisJoinPoint.getSignature()); if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isProbeActivated(operationSignature)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.registerTrace(); AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); final String clazz = thisObject.getClass().getName(); /** extension over the original routine. */ final String[] names = ((MethodSignature) thisJoinPoint.getSignature()).getParameterNames(); final Object[] arguments = thisJoinPoint.getArgs(); final String[] values = new String[arguments.length]; int i = 0; for (final Object argument : arguments) { values[i++] = argument.toString(); } /** exchanged return type. */ // measure before execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new EntryLevelBeforeOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, names, values, 0)); // execution of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } catch (final Throwable th) { // NOPMD NOCS (catch throw might ok here) // measure after failed execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new AfterOperationFailedEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString())); throw th; } finally { if (newTrace) { // close the trace AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.unregisterTrace(); } } // measure after successful execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new AfterOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz)); return retval; }
From source file:org.iobserve.monitoring.probe.aspectj.AbstractOperationExecutionWithParameterAspect.java
License:Apache License
@Around("monitoredOperation() && !this(java.lang.Object) && notWithinKieker()") public Object staticOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // NOCS // (Throwable) if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isMonitoringEnabled()) { return thisJoinPoint.proceed(); }//from ww w . j a v a2s . co m final Signature sig = thisJoinPoint.getSignature(); final String operationSignature = this.signatureToLongString(sig); if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isProbeActivated(operationSignature)) { return thisJoinPoint.proceed(); } // common fields TraceMetadata trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.getTrace(); final boolean newTrace = trace == null; if (newTrace) { trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.registerTrace(); AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(trace); } final long traceId = trace.getTraceId(); final String clazz = sig.getDeclaringTypeName(); // measure before execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new BeforeOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz)); // execution of the called method final Object retval; try { retval = thisJoinPoint.proceed(); } catch (final Throwable th) { // NOPMD NOCS (catch throw might ok here) // measure after failed execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new AfterOperationFailedEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString())); throw th; } finally { if (newTrace) { // close the trace AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.unregisterTrace(); } } // measure after successful execution AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord( new AfterOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz)); return retval; }
From source file:org.iternine.jeppetto.dao.mongodb.MongoDBSessionAspect.java
License:Apache License
public Object manageMongoDBSession(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { try {//from www .ja v a2 s .c om Logger logger = LoggerFactory.getLogger(proceedingJoinPoint.getSourceLocation().getWithinType()); MongoDBSession.create(logger, proceedingJoinPoint.getSignature().toShortString()); Object result = proceedingJoinPoint.proceed(); MongoDBSession.flush(); return result; } finally { MongoDBSession.remove(); } }
From source file:org.jasig.cas.aspect.LogAspect.java
License:Apache License
/** * Added TRACE-level log entries for the executing target. * * @param proceedingJoinPoint the proceeding join point * @return the object/* www . j a v a 2 s . com*/ * @throws Throwable the throwable */ @Around("(execution (public * org.jasig.cas..*.*(..))) && !(execution( * org.jasig.cas..*.set*(..)))") public Object traceMethod(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable { Object returnVal = null; final Logger logger = this.getLog(proceedingJoinPoint); final String methodName = proceedingJoinPoint.getSignature().getName(); try { if (logger.isTraceEnabled()) { final Object[] args = proceedingJoinPoint.getArgs(); final String arguments; if (args == null || args.length == 0) { arguments = ""; } else { arguments = Arrays.deepToString(args); } logger.trace("Entering method [{}] with arguments [{}]", methodName, arguments); } returnVal = proceedingJoinPoint.proceed(); return returnVal; } finally { logger.trace("Leaving method [{}] with return value [{}].", methodName, (returnVal != null ? returnVal.toString() : "null")); } }
From source file:org.jbb.lib.properties.encrypt.PropertiesEncryptionAspect.java
License:Apache License
@Around("this(org.jbb.lib.properties.ModuleProperties)") public Object decryptIfApplicable(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Config.Key key = method.getAnnotation(Config.Key.class); if (key != null) { ModuleProperties properties = (ModuleProperties) joinPoint.getThis(); String value = properties.getProperty(key.value()); if (isInDecPlaceholder(value)) { String decryptedString = propertiesEncryption.decryptIfNeeded(value); Class returnType = ((MethodSignature) joinPoint.getSignature()).getReturnType(); return typeCasting.resolve(decryptedString, returnType); }//from ww w.j av a2 s. c o m } return joinPoint.proceed(); }
From source file:org.jbb.lib.properties.SafeBlankPropertyAspect.java
License:Apache License
@Around("this(org.jbb.lib.properties.ModuleProperties)") public Object makeSafeBlankProperty(ProceedingJoinPoint joinPoint) throws Throwable { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Config.Key key = method.getAnnotation(Config.Key.class); if (key != null) { ModuleProperties properties = (ModuleProperties) joinPoint.getThis(); String value = properties.getProperty(key.value()); if (StringUtils.isBlank(value)) { return null; }/*from w w w. jav a 2s . co m*/ } return joinPoint.proceed(); }
From source file:org.jdal.log.MethodTracer.java
License:Apache License
/** * Simple Around Advice for trace in/out method execution * //ww w .j a v a 2 s . c o m * @param pjp the joint point * @return returned object. * @throws Throwable for the method */ public Object traceMethod(ProceedingJoinPoint pjp) throws Throwable { log.debug("Enter method: " + pjp.getSignature().toLongString()); Object result = pjp.proceed(); log.debug("Exit method: " + pjp.toShortString()); return result; }
From source file:org.kaleidofoundry.core.context.AnnotationContexInjectorAspect.java
License:Apache License
/** * @param jp// ww w . j av a 2s . c o m * @param esjp * @param thisJoinPoint * @param annotation * @return <code>true / false</code> to enable poincut * @throws Throwable */ // track field with ProceedingJoinPoint and annotation information with @annotation(annotation) @SuppressWarnings("unchecked") @Around("trackRuntimeContextField(jp, esjp) && @annotation(annotation)") public Object trackRuntimeContextFieldToInject(final JoinPoint jp, final JoinPoint.EnclosingStaticPart esjp, final ProceedingJoinPoint thisJoinPoint, final Context annotation) throws Throwable { if (thisJoinPoint.getSignature() instanceof FieldSignature) { final FieldSignature fs = (FieldSignature) thisJoinPoint.getSignature(); final Object target = thisJoinPoint.getTarget(); final Field field = fs.getField(); field.setAccessible(true); final Object currentValue = field.get(target); if (currentValue == null) { final RuntimeContext<?> runtimeContext = RuntimeContext.createFrom(annotation, fs.getName(), fs.getFieldType()); field.set(target, runtimeContext); return runtimeContext; } else { return thisJoinPoint.proceed(); } } else { throw new IllegalStateException("aspect advise handle only field, please check your pointcut"); } }