Search in sources :

Example 11 with MethodInvocation

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();
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation)

Example 12 with MethodInvocation

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();
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation)

Example 13 with MethodInvocation

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);
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 14 with MethodInvocation

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);
}
Also used : MethodTimeInterceptor(io.leopard.topnb.methodtime.MethodTimeInterceptor) MethodInvocation(org.aopalliance.intercept.MethodInvocation) AccessibleObject(java.lang.reflect.AccessibleObject) Test(org.junit.Test) PerformanceUtilTest(io.leopard.topnb.methodtime.PerformanceUtilTest)

Example 15 with MethodInvocation

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();
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationFactory(org.springframework.remoting.support.RemoteInvocationFactory) MethodInvocation(org.aopalliance.intercept.MethodInvocation) RmiProxyFactoryBean(org.springframework.remoting.rmi.RmiProxyFactoryBean)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)117 Test (org.junit.jupiter.api.Test)50 Test (org.junit.Test)35 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)25 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)22 Method (java.lang.reflect.Method)21 ArrayList (java.util.ArrayList)11 Log (org.apache.commons.logging.Log)11 Authentication (org.springframework.security.core.Authentication)10 EvaluationContext (org.springframework.expression.EvaluationContext)9 Expression (org.springframework.expression.Expression)9 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 List (java.util.List)7 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 MyThrowsHandler (org.springframework.aop.testfixture.advice.MyThrowsHandler)7 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)5 Promise (ratpack.exec.Promise)5