use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class InvocationCheckExposedInvocationTestBean method getName.
@Override
public String getName() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
return super.getName();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class InvocationCheckExposedInvocationTestBean method absquatulate.
@Override
public void absquatulate() {
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
assertions(invocation);
super.absquatulate();
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testUndeclaredUnheckedException.
@Test
public void testUndeclaredUnheckedException() throws Throwable {
final RuntimeException unexpectedException = new RuntimeException();
// Test return value
MethodInterceptor mi = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
throw unexpectedException;
}
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
pc.addAdvice(mi);
// We don't care about the object
pc.setTarget(new TestBean());
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
try {
// Note: exception param below isn't used
tb.getAge();
fail("Should have wrapped exception raised by interceptor");
} catch (RuntimeException thrown) {
assertEquals("exception matches", unexpectedException, thrown);
}
}
use of org.aopalliance.intercept.MethodInvocation in project leopard by tanhaichao.
the class TopnbInterceptorTest method invoke.
// @Test
// public void getContext() {
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml"));
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml", false));
// Assert.assertNotNull(TopnbInterceptor.getContext("applicationContext.xml", true));
// }
@Test
public void invoke() throws Throwable {
MethodInvocation invocation = new MethodInvocation() {
@Override
public Object[] getArguments() {
return null;
}
@Override
public AccessibleObject getStaticPart() {
return null;
}
@Override
public Object getThis() {
return TopnbInterceptorTest.this;
}
@Override
public Object proceed() throws Throwable {
return "ok";
}
@Override
public Method getMethod() {
try {
return TopnbInterceptorTest.class.getMethod("invoke");
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
};
Object result = new MethodTimeInterceptor().invoke(invocation);
Assert.assertEquals("ok", result);
}
use of org.aopalliance.intercept.MethodInvocation in project dubbo by alibaba.
the class RmiProtocol method doRefer.
@SuppressWarnings("unchecked")
protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException {
final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
// RMI needs extra parameter since it uses customized remote invocation object
if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getVersion()).equals(Version.getVersion())) {
// Check dubbo version on provider, this feature only support
rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
return new RmiRemoteInvocation(methodInvocation);
}
});
}
rmiProxyFactoryBean.setServiceUrl(url.toIdentityString());
rmiProxyFactoryBean.setServiceInterface(serviceType);
rmiProxyFactoryBean.setCacheStub(true);
rmiProxyFactoryBean.setLookupStubOnStartup(true);
rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true);
rmiProxyFactoryBean.afterPropertiesSet();
return (T) rmiProxyFactoryBean.getObject();
}
Aggregations