List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:io.starter.security.securefield.SecureFieldAspect.java
@Around(FIELD_GET) public Object getSecureField(ProceedingJoinPoint pjp) throws Throwable { String cnm = Thread.currentThread().getStackTrace()[8].getClassName(); // System.err.println("Calling: " + cnm); // if iBatis is calling, do not decrypt if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) { return pjp.proceed(pjp.getArgs()); }/*www .j av a 2 s .co m*/ Logger.debug("Get Secure Field for: " + pjp.toLongString()); Object targetObject = pjp.getTarget(); String secureFieldName = pjp.getSignature().getName(); Field secureField = targetObject.getClass().getDeclaredField(secureFieldName); secureField.setAccessible(true); Object encryptedObject = secureField.get(targetObject); secureField.setAccessible(false); return SecureEncrypter.decrypt(String.valueOf(encryptedObject)); }
From source file:io.starter.security.securefield.SecureFieldAspect.java
@Around(FIELD_SET) public Object setSecureField(ProceedingJoinPoint pjp) throws Throwable { String cnm = Thread.currentThread().getStackTrace()[8].getClassName(); // System.err.println("Calling: " + cnm); // if iBatis is calling, do not encrypt if (cnm.toLowerCase().contains("ibatis") && SKIP_IBATIS_CALLER) { return pjp.proceed(pjp.getArgs()); }//from w ww .jav a 2s. c om Logger.debug("Set Secure Field for: " + pjp.toLongString()); String clearTextValue = String.valueOf(pjp.getArgs()[0]); String encryptedValue = SecureEncrypter.encrypt(clearTextValue); Object targetObject = pjp.getTarget(); String secureFieldName = pjp.getSignature().getName(); Field secureField = targetObject.getClass().getDeclaredField(secureFieldName); secureField.setAccessible(true); secureField.set(targetObject, encryptedValue); secureField.setAccessible(false); return null; }
From source file:it.tidalwave.northernwind.aspect.DebugProfilingAspect.java
License:Apache License
@Around("execution(* it.tidalwave.northernwind.frontend.media.impl.EmbeddedMediaMetadataProvider.getMetadataString(..))") public Object advice(final @Nonnull ProceedingJoinPoint pjp) throws Throwable { log.debug("getMetadataString({})", pjp.getArgs()); final long time = System.currentTimeMillis(); final Object result = pjp.proceed(); if (log.isDebugEnabled()) { final DebugProfiling annotation = getAnnotation(pjp, DebugProfiling.class); log.debug(">>>> {} in {} msec", annotation.message(), System.currentTimeMillis() - time); }/*w ww . j a v a 2 s . c o m*/ return result; }
From source file:it.tidalwave.northernwind.frontend.springmvc.ThreadNameChangerAspect.java
License:Apache License
@Around("execution(* it.tidalwave.northernwind.frontend.springmvc.SpringMvcRestController.get(..))") public Object advice(final @Nonnull ProceedingJoinPoint pjp) throws Throwable { final Thread thread = Thread.currentThread(); final String saveName = thread.getName(); try {/*ww w . ja v a 2 s . co m*/ final HttpServletRequest request = (HttpServletRequest) pjp.getArgs()[0]; thread.setName(String.format("%s-%d", request.getRemoteAddr(), counter++)); return pjp.proceed(); } finally { thread.setName(saveName); } }
From source file:it.tidalwave.northernwind.profiling.RequestProfilerAspect.java
License:Apache License
@Around("execution(* it.tidalwave.northernwind.frontend.ui.spi.DefaultSiteViewController.processRequest(..))") public Object advice(final @Nonnull ProceedingJoinPoint pjp) throws Throwable { final Request request = (Request) pjp.getArgs()[0]; statisticsCollector.onRequestBegin(request); final Object result = pjp.proceed(); statisticsCollector.onRequestEnd(request); return result; }
From source file:jenergy.agent.aop.aspectj.aspects.FileOutputStreamAspect.java
License:Apache License
/** * //from w w w. ja va 2s .c o m * @param thisJoinPoint * The joint point reference. * @return Returns <code>null</code> since the return type of the advice method is {@link Void}. * @throws Throwable * May throw any exceptions declared by the joinpoint itself. If this exception is not declared and is not a runtime exception, it * will be encapsulated in a {@link RuntimeException} before being thrown to the basis system. */ @Around(value = "execution(void jenergy.agent.common.io.FileOutputStreamDelegate.write(..))") public Object aroundFileOutputStreamWriteOperation(final ProceedingJoinPoint thisJoinPoint) throws Throwable { Object[] args = thisJoinPoint.getArgs(); Subject observable = (Subject) thisJoinPoint.getTarget(); Object methodReturn = thisJoinPoint.proceed(args); for (Observer obs : observable.getObservers()) { int value; if (args.length == 3) { value = (Integer) args[2] - (Integer) args[1]; } else { if (args[0].getClass().isArray()) { value = ((byte[]) args[0]).length * 4; } else if (Integer.class.isAssignableFrom(args[0].getClass())) { value = (Integer) args[0]; } else { throw new RuntimeException("Unknown FileOuputStream's write method!"); } } obs.update(observable, value); } return methodReturn; }
From source file:jenergy.agent.aop.aspectj.util.AspectjUtils.java
License:Apache License
/** * //from w w w . ja v a 2 s .co m * @param thisJoinPoint * The reference to the constructor joinpoint. * @param clazz * The class to invoke the same constructor of the joinpoint. * @param newArgs * The arguments to be passed to the constructor call. In this case, the constructor arguments will be: the arguments of the original * constructor defined by the joinpoint, and the newArgs. * @param <T> * The type returned by the constructor call. * @return A new object created by calling the constructor of the given class. * @throws NoSuchMethodException * If a matching method is not found. * @throws SecurityException * If a security manager, <em>s</em>, is present and any of the following conditions is met: * <ul> * <li>invocation of s.checkMemberAccess(this, Member.PUBLIC) denies access to the constructor</li> * <li>the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of * s.checkPackageAccess() denies access to the package of this class.</li> * </ul> * @throws InstantiationException * If the class that declares the underlying constructor represents an abstract class. * @throws IllegalAccessException * If the Constructor object is enforcing Java language access control and the underlying constructor is inaccessible. * @throws IllegalArgumentException * If the number of actual and formal parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after * possible unwrapping, a parameter value cannot be converted to the corresponding formal parameter type by a method invocation * conversion; if this constructor pertains to an {@link Enum} type. * @throws InvocationTargetException * If the underlying constructor throws an exception. * @throws ClassCastException * If it is not a constructor joinpoint. * @see ConstructorSignature */ public static <T> T newInstance(ProceedingJoinPoint thisJoinPoint, Class<T> clazz, Object... newArgs) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { ConstructorSignature signature = (ConstructorSignature) thisJoinPoint.getSignature(); Class<?>[] parameterTypes = new Class[signature.getParameterTypes().length + (newArgs != null ? newArgs.length : 0)]; Object[] newConstructorArgs = new Object[parameterTypes.length]; for (int i = 0; i < signature.getParameterTypes().length; i++) { parameterTypes[i] = signature.getParameterTypes()[i]; newConstructorArgs[i] = thisJoinPoint.getArgs()[i]; } for (int i = 0, j = newConstructorArgs.length - newArgs.length; i < newArgs.length; i++, j++) { parameterTypes[j] = newArgs[i].getClass(); newConstructorArgs[j] = newArgs[i]; } Constructor<T> constructor = clazz.getConstructor(parameterTypes); constructor.setAccessible(true); return constructor.newInstance(newConstructorArgs); }
From source file:joinery.impl.Metrics.java
License:Open Source License
@Around("execution(@com.codahale.metrics.annotation.Timed * *(..))") public Object injectTimer(final ProceedingJoinPoint point) throws Throwable { final Signature signature = point.getSignature(); final Annotation annotation = getAnnotation(signature, Timed.class); final Timed timed = Timed.class.cast(annotation); final String name = name(signature, timed.name(), "timer", timed.absolute()); final Timer timer = registry.timer(name); final Timer.Context context = timer.time(); try {//w w w .j ava2 s.c o m return point.proceed(point.getArgs()); } finally { context.stop(); } }
From source file:jp.co.ctc_g.jse.core.framework.PostBackAroundAdvice.java
License:Apache License
/** * ????????//from w w w. j av a 2 s . c o m * @param joinPoint ? * @return ? * @throws Throwable ??? */ @Around("execution(@org.springframework.web.bind.annotation.RequestMapping * *(..)) && (execution(@jp.co.ctc_g.jse.core.framework.PostBack.Action * *(..)) || execution(@jp.co.ctc_g.jse.core.framework.PostBack.Action.List * *(..)))") public Object processPostBackAction(ProceedingJoinPoint joinPoint) throws Throwable { Object result = null; Object model = null; try { PostBackManager manager = PostBackManager.getCurrentPostBackManager(); Class<?> modelAttributeType = manager.getModelAttributeType(); if (modelAttributeType != null) { for (Object o : joinPoint.getArgs()) { if (o.getClass().getName().equals(modelAttributeType.getName())) { model = o; } } } result = joinPoint.proceed(); } catch (Throwable t) { result = build(t, model); } return result; }
From source file:jp.co.opentone.bsol.framework.core.MethodTraceAdvice.java
License:Apache License
private Object[] getArguments(ProceedingJoinPoint jp) { return jp.getArgs(); }