Java Code Examples for org.springframework.aop.interceptor.ExposeInvocationInterceptor#currentInvocation()

The following examples show how to use org.springframework.aop.interceptor.ExposeInvocationInterceptor#currentInvocation() . 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: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	String task = "get invocation on way IN";
	try {
		MethodInvocation current = ExposeInvocationInterceptor.currentInvocation();
		assertEquals(mi.getMethod(), current.getMethod());
		Object retval = mi.proceed();
		task = "get invocation on way OUT";
		assertEquals(current, ExposeInvocationInterceptor.currentInvocation());
		return retval;
	}
	catch (IllegalStateException ex) {
		System.err.println(task + " for " + mi.getMethod());
		ex.printStackTrace();
		throw ex;
	}
}
 
Example 2
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	String task = "get invocation on way IN";
	try {
		MethodInvocation current = ExposeInvocationInterceptor.currentInvocation();
		assertEquals(mi.getMethod(), current.getMethod());
		Object retval = mi.proceed();
		task = "get invocation on way OUT";
		assertEquals(current, ExposeInvocationInterceptor.currentInvocation());
		return retval;
	}
	catch (IllegalStateException ex) {
		System.err.println(task + " for " + mi.getMethod());
		ex.printStackTrace();
		throw ex;
	}
}
 
Example 3
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	String task = "get invocation on way IN";
	try {
		MethodInvocation current = ExposeInvocationInterceptor.currentInvocation();
		assertEquals(mi.getMethod(), current.getMethod());
		Object retval = mi.proceed();
		task = "get invocation on way OUT";
		assertEquals(current, ExposeInvocationInterceptor.currentInvocation());
		return retval;
	}
	catch (IllegalStateException ex) {
		System.err.println(task + " for " + mi.getMethod());
		ex.printStackTrace();
		throw ex;
	}
}
 
Example 4
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 5
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Throw an exception if there is an Invocation.
 */
private void assertNoInvocationContext() {
	try {
		ExposeInvocationInterceptor.currentInvocation();
		fail("Expected no invocation context");
	}
	catch (IllegalStateException ex) {
		// ok
	}
}
 
Example 6
Source File: AbstractAspectJAdvice.java    From spring-analysis-note with MIT License 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 7
Source File: AbstractAspectJAdvice.java    From java-technology-stack with MIT License 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 8
Source File: AbstractAspectJAdvice.java    From java-technology-stack 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 9
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Throw an exception if there is an Invocation.
 */
private void assertNoInvocationContext() {
	try {
		ExposeInvocationInterceptor.currentInvocation();
		fail("Expected no invocation context");
	}
	catch (IllegalStateException ex) {
		// ok
	}
}
 
Example 10
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Throw an exception if there is an Invocation.
 */
private void assertNoInvocationContext() {
	try {
		ExposeInvocationInterceptor.currentInvocation();
		fail("Expected no invocation context");
	}
	catch (IllegalStateException ex) {
		// ok
	}
}
 
Example 11
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 12
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 13
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 14
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 15
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void absquatulate() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	super.absquatulate();
}
 
Example 16
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public String getName() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	return super.getName();
}
 
Example 17
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void absquatulate() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	super.absquatulate();
}
 
Example 18
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String getName() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	return super.getName();
}
 
Example 19
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void absquatulate() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	super.absquatulate();
}
 
Example 20
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public String getName() {
	MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
	assertions(invocation);
	return super.getName();
}