List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java
License:Apache License
@Around("set(* *.*) && encryptAnnotatedDomainObjectField()") public Object setFieldAccess(ProceedingJoinPoint pjp) throws Throwable { FieldSignature signature = (FieldSignature) pjp.getSignature(); EncryptAttribute ea = getFieldEncryptAttribute(signature); Object[] args = pjp.getArgs(); // exchange original value with encrypted value args[0] = encrypt(ea, pjp.getTarget(), args[0]); // perform field access with encrypted value return pjp.proceed(args); }
From source file:net.sourceforge.safr.core.interceptor.SecurityAspect.java
License:Apache License
@Around("get(* *.*) && encryptAnnotatedDomainObjectField()") public Object getFieldAccess(ProceedingJoinPoint pjp) throws Throwable { FieldSignature signature = (FieldSignature) pjp.getSignature(); EncryptAttribute ea = getFieldEncryptAttribute(signature); // obtain encrypted value from field Object value = pjp.proceed(); // decrypt encrypted field value and return it return decrypt(ea, pjp.getTarget(), value); }
From source file:net.sourceforge.safr.core.invocation.AspectJProceedingInvocation.java
License:Apache License
public AspectJProceedingInvocation(ProceedingJoinPoint pjp) { super(getMethod(pjp), pjp.getTarget(), pjp.getArgs()); this.pjp = pjp; }
From source file:nl.nn.ibistesttool.IbisDebuggerAdvice.java
License:Apache License
public Object debugSenderInputOutputAbort(ProceedingJoinPoint proceedingJoinPoint, String correlationId, String message) throws Throwable { ISender sender = (ISender) proceedingJoinPoint.getTarget(); if (!sender.isSynchronous() && sender instanceof JmsSender) { // Ignore JmsSenders within JmsListeners (calling JmsSender without // ParameterResolutionContext) within Receivers. return proceedingJoinPoint.proceed(); } else {/* w w w. j a v a 2 s. c o m*/ Object result = debugSenderInputAbort(proceedingJoinPoint, sender, correlationId, message); return ibisDebugger.senderOutput(sender, correlationId, result); } }
From source file:nl.nn.ibistesttool.IbisDebuggerAdvice.java
License:Apache License
public Object debugSenderWithParametersInputOutputAbort(ProceedingJoinPoint proceedingJoinPoint, String correlationId, String message, ParameterResolutionContext parameterResolutionContext) throws Throwable { ISender sender = (ISender) proceedingJoinPoint.getTarget(); Object preservedObject = message; Object result = debugSenderInputAbort(proceedingJoinPoint, sender, correlationId, message); if (sender instanceof SenderWrapperBase) { SenderWrapperBase senderWrapperBase = (SenderWrapperBase) sender; if (senderWrapperBase.isPreserveInput()) { result = (String) ibisDebugger.preserveInput(correlationId, preservedObject); }/*from ww w . ja v a2 s. c o m*/ } return ibisDebugger.senderOutput(sender, correlationId, result); }
From source file:nl.nn.ibistesttool.IbisDebuggerAdvice.java
License:Apache License
public Object debugParameterResolvedTo(ProceedingJoinPoint proceedingJoinPoint, ParameterValueList alreadyResolvedParameters, ParameterResolutionContext parameterResolutionContext) throws Throwable { Object result = proceedingJoinPoint.proceed(); Parameter parameter = (Parameter) proceedingJoinPoint.getTarget(); return ibisDebugger.parameterResolvedTo(parameter, parameterResolutionContext.getSession().getMessageId(), result);//ww w. j a v a2s . co m }
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(); }//w w w. j av a2s.c o m // 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; }//w w w. j av a 2 s .c om } // 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.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/* ww w. jav a 2s . c o 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.ignite.compute.gridify.aop.aspectj.GridifyAspectJAspect.java
License:Apache License
/** * Aspect implementation which executes grid-enabled methods on remote * nodes.//from w ww . jav a 2s . co m * * @param joinPnt Join point provided by AspectJ AOP. * @return Method execution result. * @throws Throwable If execution failed. */ @SuppressWarnings({ "ProhibitedExceptionDeclared", "ProhibitedExceptionThrown", "CatchGenericClass", "unchecked" }) @Around("execution(@org.apache.ignite.compute.gridify.Gridify * *(..)) && !cflow(call(* org.apache.ignite.compute.ComputeJob.*(..)))") public Object gridify(ProceedingJoinPoint joinPnt) throws Throwable { Method mtd = ((MethodSignature) joinPnt.getSignature()).getMethod(); Gridify ann = mtd.getAnnotation(Gridify.class); assert ann != null : "Intercepted method does not have gridify annotation."; // Since annotations in Java don't allow 'null' as default value // we have accept an empty string and convert it here. // NOTE: there's unintended behavior when user specifies an empty // string as intended grid name. // NOTE: the 'ann.gridName() == null' check is added to mitigate // annotation bugs in some scripting languages (e.g. Groovy). String gridName = F.isEmpty(ann.gridName()) ? null : ann.gridName(); if (G.state(gridName) != STARTED) throw new IgniteCheckedException("Grid is not locally started: " + gridName); // Initialize defaults. GridifyArgument arg = new GridifyArgumentAdapter(mtd.getDeclaringClass(), mtd.getName(), mtd.getParameterTypes(), joinPnt.getArgs(), joinPnt.getTarget()); if (!ann.interceptor().equals(GridifyInterceptor.class)) { // Check interceptor first. if (!ann.interceptor().newInstance().isGridify(ann, arg)) return joinPnt.proceed(); } if (!ann.taskClass().equals(GridifyDefaultTask.class) && !ann.taskName().isEmpty()) { throw new IgniteCheckedException("Gridify annotation must specify either Gridify.taskName() or " + "Gridify.taskClass(), but not both: " + ann); } try { Ignite ignite = G.ignite(gridName); // If task class was specified. if (!ann.taskClass().equals(GridifyDefaultTask.class)) { return ignite.compute().withTimeout(ann.timeout()) .execute((Class<? extends ComputeTask<GridifyArgument, Object>>) ann.taskClass(), arg); } // If task name was not specified. if (ann.taskName().isEmpty()) { return ignite.compute().withTimeout(ann.timeout()) .execute(new GridifyDefaultTask(joinPnt.getSignature().getDeclaringType()), arg); } // If task name was specified. return ignite.compute().withTimeout(ann.timeout()).execute(ann.taskName(), arg); } catch (Throwable e) { for (Class<?> ex : ((MethodSignature) joinPnt.getSignature()).getMethod().getExceptionTypes()) { // Descend all levels down. Throwable cause = e.getCause(); while (cause != null) { if (ex.isAssignableFrom(cause.getClass())) throw cause; cause = cause.getCause(); } if (ex.isAssignableFrom(e.getClass())) throw e; } throw new GridifyRuntimeException("Undeclared exception thrown: " + e.getMessage(), e); } }