org.springframework.aop.ProxyMethodInvocation Java Examples

The following examples show how to use org.springframework.aop.ProxyMethodInvocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanIdentifierImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Do the look up by interface type.
 * 
 * @return              Returns the name of the service or <tt>null</tt> if not found
 */
private String getBeanNameImpl(MethodInvocation mi) throws BeansException
{
    if (mi instanceof ProxyMethodInvocation)
    {
        Object proxy = ((ProxyMethodInvocation) mi).getProxy();
        Map beans = beanFactory.getBeansOfType(proxy.getClass());
        Iterator iter = beans.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry entry = (Map.Entry) iter.next();
            String name = (String) entry.getKey();
            if (proxy == entry.getValue() && !name.equals("DescriptorService"))
            {
                return name;
            }
        }
    }
    return null;
}
 
Example #2
Source File: DelegatePerTargetObjectIntroductionInterceptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
public Object invoke(MethodInvocation mi) throws Throwable {
	if (isMethodOnIntroducedInterface(mi)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());

		// 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(delegate, mi.getMethod(), mi.getArguments());

		// Massage return value if possible: if the delegate returned itself,
		// we really want to return the proxy.
		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
Example #3
Source File: DelegatingIntroductionInterceptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
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);
}
 
Example #4
Source File: DelegatingIntroductionInterceptor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: DelegatePerTargetObjectIntroductionInterceptor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());

		// 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(delegate, mi.getMethod(), mi.getArguments());

		// Massage return value if possible: if the delegate returned itself,
		// we really want to return the proxy.
		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
Example #6
Source File: DelegatePerTargetObjectIntroductionInterceptor.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());

		// 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(delegate, mi.getMethod(), mi.getArguments());

		// Massage return value if possible: if the delegate returned itself,
		// we really want to return the proxy.
		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
Example #7
Source File: DelegatingIntroductionInterceptor.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #8
Source File: DelegatePerTargetObjectIntroductionInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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
public Object invoke(MethodInvocation mi) throws Throwable {
	if (isMethodOnIntroducedInterface(mi)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());

		// 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(delegate, mi.getMethod(), mi.getArguments());

		// Massage return value if possible: if the delegate returned itself,
		// we really want to return the proxy.
		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
Example #9
Source File: DelegatingIntroductionInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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
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);
}
 
Example #10
Source File: RetryPolicyInvocationHandler.java    From Ratel with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public Object invokeWithRetry(MethodInvocation methodInvocation, int count) throws Throwable {
    MethodInvocation methodInvocationCopy = ((ProxyMethodInvocation) methodInvocation).invocableClone();
    try {
        return methodInvocationCopy.proceed();
    } catch (Throwable thrownException) {
        LOGGER.warn("Ratel - Retry Policy was triggered for service {} because: {} ", methodInvocation.getMethod(),
                thrownException.getMessage());
        final List<Class<? extends Throwable>> retryOnExceptions = config.getRetryOnExceptions();
        if (shouldRetry(count, thrownException, retryOnExceptions)) {
            Thread.sleep(config.getWaitingTime());

            return invokeWithRetry(methodInvocation, count + 1);
        }

        throw thrownException;
    }
}
 
Example #11
Source File: RdbmsRetryOperationsInterceptorTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void testRetryContextIsNotAvailable() throws Throwable {

	ProxyMethodInvocation methodInvocation = mock(ProxyMethodInvocation.class);

	when(methodInvocation.invocableClone()).thenReturn(methodInvocation);
	when(methodInvocation.proceed()).then(invocation -> {
		assertThat(RetrySynchronizationManager.getContext()).isNotNull();
		return "foo";
	});

	RdbmsRetryOperationsInterceptor interceptor = new RdbmsRetryOperationsInterceptor();
	interceptor.setLabel("mylabel"); // Avoids NPE in
										// RetryOperationsInterceptor.invoke
	interceptor.invoke(methodInvocation);

	verify(methodInvocation, times(1)).invocableClone();
}
 
Example #12
Source File: AspectJExpressionPointcut.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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(getExpression(), jpm);
}
 
Example #13
Source File: AbstractAspectJAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: AbstractAspectJAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the current join point match at the join point we are being dispatched on.
 */
protected JoinPointMatch getJoinPointMatch() {
	MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	return getJoinPointMatch((ProxyMethodInvocation) mi);
}
 
Example #15
Source File: ExposeBeanNameAdvisors.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor
 * has been included in the interceptor chain.
 * @param mi MethodInvocation that should contain the bean name as an attribute
 * @return the bean name (never {@code null})
 * @throws IllegalStateException if the bean name has not been exposed
 */
public static String getBeanName(MethodInvocation mi) throws IllegalStateException {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE);
	if (beanName == null) {
		throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi);
	}
	return beanName;
}
 
Example #16
Source File: ExposeBeanNameAdvisors.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example #17
Source File: AspectJExpressionPointcut.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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(getExpression(), jpm);
}
 
Example #18
Source File: ExposeBeanNameAdvisors.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: AspectJAroundAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
	ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
	JoinPointMatch jpm = getJoinPointMatch(pmi);
	return invokeAdviceMethod(pjp, jpm, null, null);
}
 
Example #20
Source File: AspectJAroundAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
	ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
	JoinPointMatch jpm = getJoinPointMatch(pmi);
	return invokeAdviceMethod(pjp, jpm, null, null);
}
 
Example #21
Source File: AbstractAspectJAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: AbstractAspectJAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get the current join point match at the join point we are being dispatched on.
 */
protected JoinPointMatch getJoinPointMatch() {
	MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	return getJoinPointMatch((ProxyMethodInvocation) mi);
}
 
Example #23
Source File: ExposeBeanNameAdvisors.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor
 * has been included in the interceptor chain.
 * @param mi MethodInvocation that should contain the bean name as an attribute
 * @return the bean name (never {@code null})
 * @throws IllegalStateException if the bean name has not been exposed
 */
public static String getBeanName(MethodInvocation mi) throws IllegalStateException {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE);
	if (beanName == null) {
		throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi);
	}
	return beanName;
}
 
Example #24
Source File: ExposeBeanNameAdvisors.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #25
Source File: ExposeBeanNameAdvisors.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: DelegateFactoryIntroductionInterceptor.java    From jdal with Apache License 2.0 5 votes vote down vote up
public Object invoke(MethodInvocation mi) throws Throwable {
	if (isMethodOnIntroducedInterface(mi)) {
		Object delegate = getIntroductionDelegateFor(mi.getThis());
		Object retVal = AopUtils.invokeJoinpointUsingReflection(delegate, mi.getMethod(), mi.getArguments());

		if (retVal == delegate && mi instanceof ProxyMethodInvocation) {
			retVal = ((ProxyMethodInvocation) mi).getProxy();
		}
		return retVal;
	}

	return doProceed(mi);
}
 
Example #27
Source File: AspectJAroundAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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;
	ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
	JoinPointMatch jpm = getJoinPointMatch(pmi);
	return invokeAdviceMethod(pjp, jpm, null, null);
}
 
Example #28
Source File: AbstractAspectJAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Get the current join point match at the join point we are being dispatched on.
 */
@Nullable
protected JoinPointMatch getJoinPointMatch() {
	MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	return getJoinPointMatch((ProxyMethodInvocation) mi);
}
 
Example #29
Source File: ExposeBeanNameAdvisors.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor
 * has been included in the interceptor chain.
 * @param mi the MethodInvocation that should contain the bean name as an attribute
 * @return the bean name (never {@code null})
 * @throws IllegalStateException if the bean name has not been exposed
 */
public static String getBeanName(MethodInvocation mi) throws IllegalStateException {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE);
	if (beanName == null) {
		throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi);
	}
	return beanName;
}
 
Example #30
Source File: ExposeBeanNameAdvisors.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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();
}