@Override public Object proceed() throws Throwable { return this.methodInvocation.invocableClone().proceed(); }
/** * Returns the Spring AOP proxy. Cannot be {@code null}. */ @Override public Object getThis() { return this.methodInvocation.getProxy(); }
@Override public Object proceed(Object[] arguments) throws Throwable { Assert.notNull(arguments, "Argument array passed to proceed cannot be null"); if (arguments.length != this.methodInvocation.getArguments().length) { throw new IllegalArgumentException("Expecting " + this.methodInvocation.getArguments().length + " arguments to proceed, " + "but was passed " + arguments.length + " arguments"); } this.methodInvocation.setArguments(arguments); return this.methodInvocation.invocableClone(arguments).proceed(); }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }
@Override public Method getMethod() { return methodInvocation.getMethod(); }
@Override public Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName); return mi.proceed(); } }
Object entity = methodInvocation.getArguments()[0]; entity = lock(entity); ((ProxyMethodInvocation)methodInvocation).setArguments(entity); rc = methodInvocation.proceed(); Object entity = methodInvocation.getArguments()[0]; entity = lock(entity); ((ProxyMethodInvocation)methodInvocation).setArguments(entity, methodInvocation.getArguments()[1]); methodInvocation.proceed(); touch(entity, Version.class); Object entity = methodInvocation.getArguments()[0]; entity = lock(entity); ((ProxyMethodInvocation)methodInvocation).setArguments(entity); methodInvocation.proceed(); touch(entity, Version.class);
@Override public Object[] getArgs() { if (this.args == null) { this.args = this.methodInvocation.getArguments().clone(); } return this.args; }
@Override public Class<?> getReturnType() { return methodInvocation.getMethod().getReturnType(); }
@Override public Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName); return super.invoke(mi); }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }
/** * Returns the Spring AOP target. May be {@code null} if there is no target. */ @Override @Nullable public Object getTarget() { return this.methodInvocation.getThis(); }
@Override public Object[] getArgs() { if (this.args == null) { this.args = this.methodInvocation.getArguments().clone(); } return this.args; }
/** * Subclasses may need to override this if they want to perform custom * behaviour in around advice. However, subclasses should invoke this * method, which handles introduced interfaces and forwarding to the target. */ @Override @Nullable public Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { // Using the following method rather than direct reflection, we // get correct handling of InvocationTargetException // if the introduced method throws an exception. Object retVal = AopUtils.invokeJoinpointUsingReflection(this.delegate, mi.getMethod(), mi.getArguments()); // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. if (retVal == this.delegate && mi instanceof ProxyMethodInvocation) { Object proxy = ((ProxyMethodInvocation) mi).getProxy(); if (mi.getMethod().getReturnType().isInstance(proxy)) { retVal = proxy; } } return retVal; } return doProceed(mi); }
public Object doWithRetry(RetryContext context) throws Exception { context.setAttribute(RetryContext.NAME, label); /* * If we don't copy the invocation carefully it won't keep a reference to * the other interceptors in the chain. We don't have a choice here but to * specialise to ReflectiveMethodInvocation (but how often would another * implementation come along?). */ if (invocation instanceof ProxyMethodInvocation) { try { return ((ProxyMethodInvocation) invocation).invocableClone().proceed(); } catch (Exception e) { throw e; } catch (Error e) { throw e; } catch (Throwable e) { throw new IllegalStateException(e); } } else { throw new IllegalStateException( "MethodInvocation of the wrong type detected - this should not happen with Spring AOP, " + "so please raise an issue if you see this exception"); } }
@Override public Object proceed(Object[] arguments) throws Throwable { Assert.notNull(arguments, "Argument array passed to proceed cannot be null"); if (arguments.length != this.methodInvocation.getArguments().length) { throw new IllegalArgumentException("Expecting " + this.methodInvocation.getArguments().length + " arguments to proceed, " + "but was passed " + arguments.length + " arguments"); } this.methodInvocation.setArguments(arguments); return this.methodInvocation.invocableClone(arguments).proceed(); }
@Override public Class<?>[] getExceptionTypes() { return methodInvocation.getMethod().getExceptionTypes(); }
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm) { // Note: Can't use JoinPointMatch.getClass().getName() as the key, since // Spring AOP does all the matching at a join point, and then all the invocations // under this scenario, if we just use JoinPointMatch as the key, then // 'last man wins' which is not what we want at all. // Using the expression is guaranteed to be safe, since 2 identical expressions // are guaranteed to bind in exactly the same way. invocation.setUserAttribute(resolveExpression(), jpm); }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }