@Override public Object[] getArgs() { return jp.getArgs(); }
public void captureFloatArgument(JoinPoint tjp, float arg) { float tjpArg = ((Float) tjp.getArgs()[0]).floatValue(); if (Math.abs(tjpArg - arg) > 0.000001) { throw new IllegalStateException( "argument is '" + arg + "', " + "but args array has '" + tjpArg + "'" ); } this.lastBeforeFloatValue = arg; }
public static Map<String, Object> getArgsMap(JoinPoint pjp) { MethodSignature signature = (MethodSignature) pjp.getSignature(); Map<String, Object> args = new LinkedHashMap<>(); String names[] = signature.getParameterNames(); for (int i = 0, len = names.length; i < len; i++) { args.put(names[i], pjp.getArgs()[i]); } return args; } }
@Before("webLog()") public void doBefore(JoinPoint joinPoint) { // 接收到请求,记录请求内容 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); // 记录下请求内容 LOGGER.info("URL : " + request.getRequestURL().toString() + ",IP : " + request.getRemoteAddr() + ",CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName() + ",ARGS : " + Arrays.toString(joinPoint.getArgs())); }
private static void enterMethod(JoinPoint joinPoint) { if (!enabled) return; CodeSignature codeSignature = (CodeSignature) joinPoint.getSignature(); Class<?> cls = codeSignature.getDeclaringType(); String methodName = codeSignature.getName(); String[] parameterNames = codeSignature.getParameterNames(); Object[] parameterValues = joinPoint.getArgs(); StringBuilder builder = new StringBuilder("\u21E2 "); builder.append(methodName).append('('); for (int i = 0; i < parameterValues.length; i++) { if (i > 0) { builder.append(", "); } builder.append(parameterNames[i]).append('='); builder.append(Strings.toString(parameterValues[i])); } builder.append(')'); if (Looper.myLooper() != Looper.getMainLooper()) { builder.append(" [Thread:\"").append(Thread.currentThread().getName()).append("\"]"); } Log.v(asTag(cls), builder.toString()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { final String section = builder.toString().substring(2); Trace.beginSection(section); } }
@After("onViewCreated()") public void onViewCreatedProcess(JoinPoint joinPoint) throws Throwable { Object puppet = joinPoint.getTarget(); //Only inject the class that marked by Puppet annotation. Object[] args = joinPoint.getArgs(); Method onCreate = getRiggerMethod("onViewCreated", Object.class, View.class, Bundle.class); onCreate.invoke(getRiggerInstance(), puppet, args[0], args[1]); }
public void doBasicLogging(JoinPoint pjp) throws Throwable { Object[] args = pjp.getArgs(); StringBuilder output = new StringBuilder(); output.append(pjp.getTarget().getClass().getName()).append(": "); output.append(pjp.toShortString()).append(": "); for (Object arg : args) { output.append(arg).append(" "); } log.info("Basic: " + output.toString()); }
@AfterReturning(value = "anyPublicOperation() && execCommandOperation()", returning = "result") public void logAfter(JoinPoint joinPoint, boolean result) { Object[] args = joinPoint.getArgs(); OperationRecord record = new OperationRecord(); record.setOperator(getUsername()); record.setType(joinPoint.getSignature().getName()); record.setGroupName(args[0].toString()); record.setCommand(JSON.toJSONString(args[1])); int status = result ? 1 : 0; record.setStatus((byte) status); if (recordMapper == null) { LoggerUtil.accessLog(JSON.toJSONString(record)); } else { recordMapper.insertSelective(record); } }
/** * Factory method that creates a new {@link BeforeAdviceMethodInvocationAdapter} instance * using the AspectJ {@link JoinPoint} provided. If the joint point passed in is not * a method joint point, this method throws an {@link IllegalArgumentException}. * * @param aJoinPoint The AspectJ {@link JoinPoint} to use to adapt the advice. * @return The created instance. * @throws IllegalArgumentException If the join point passed in does not involve a method call. */ public static BeforeAdviceMethodInvocationAdapter createFrom(JoinPoint aJoinPoint) { if (aJoinPoint.getSignature() instanceof MethodSignature) { return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(), ((MethodSignature) aJoinPoint.getSignature()).getMethod(), aJoinPoint.getArgs()); } else if (aJoinPoint.getSignature() instanceof AdviceSignature) { return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(), ((AdviceSignature) aJoinPoint.getSignature()).getAdvice(), aJoinPoint.getArgs()); } else { throw new IllegalArgumentException("The joint point signature is invalid: expected a MethodSignature or an AdviceSignature but was " + aJoinPoint.getSignature()); } }
@SuppressWarnings("unchecked") private <T> T castArgument(JoinPoint joinPoint, int argIndex) { return (T) joinPoint.getArgs()[argIndex]; }
@Before(EXECUTION_NAVIGATION_TO) public void beforeNavigateTo(JoinPoint joinPoint) throws Throwable { try { listener.beforeNavigateTo(String.valueOf(joinPoint.getArgs()[0]), driver); } catch (Throwable t) { throw getRootCause(t); } }
@Before(EXECUTION_SCRIPT) public void beforeScript(JoinPoint joinPoint) throws Throwable { try { listener.beforeScript(String.valueOf(joinPoint.getArgs()[0]), driver); } catch (Throwable t) { throw getRootCause(t); } }
@Before(EXECUTION_CONTEXT) public void beforeSwitchingToContext(JoinPoint joinPoint) throws Throwable { try { listener.beforeSwitchingToContext(driver, String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); } }
@Before(EXECUTION_ALERT_SEND_KEYS) public void beforeAlertSendKeys(JoinPoint joinPoint) throws Throwable { try { listener.beforeAlertSendKeys(driver, castTarget(joinPoint), String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); } }
@After(EXECUTION_SCRIPT) public void afterScript(JoinPoint joinPoint) throws Throwable { try { listener.afterScript(String.valueOf(joinPoint.getArgs()[0]), driver); } catch (Throwable t) { throw getRootCause(t); } }
@After(EXECUTION_CONTEXT) public void afterSwitchingToContextn(JoinPoint joinPoint) throws Throwable { try { listener.afterSwitchingToContext(driver, String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); } }
@After(EXECUTION_NAVIGATION_TO) public void afterNavigateTo(JoinPoint joinPoint) throws Throwable { try { listener.afterNavigateTo(String.valueOf(joinPoint.getArgs()[0]), driver); } catch (Throwable t) { throw getRootCause(t); } }
@After(EXECUTION_ALERT_SEND_KEYS) public void afterAlertSendKeys(JoinPoint joinPoint) throws Throwable { try { listener.afterAlertSendKeys(driver, castTarget(joinPoint), String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); } }
@Test public void testModelAspect() { Assume.assumeThat(springContext.isServletRequestContext(), is(false)); JoinPoint joinPoint = mock(JoinPoint.class); @SuppressWarnings("unchecked") BaseModel<Object> baseModel = mock(BaseModel.class); when(joinPoint.getArgs()).thenReturn(new Object[] { baseModel }); modelAspect.beforeSave(joinPoint); verify(baseModel, times(1)).setCreatedDate(any(Date.class)); }