Search in sources :

Example 46 with DefaultInterceptorChainList

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChainList in project nimbus by nimbus-org.

the class ExceptionThrowInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ExceptionThrowInterceptorService interceptor = new ExceptionThrowInterceptorService();
    ServiceManagerFactory.registerService("Test", "ExceptionThrowInterceptor", interceptor);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setExceptionClassName("java.lang.IllegalArgumentException");
        interceptor.setMessageKey("NIMBUS000");
        ServiceManagerFactory.findManager("Test").startAllService();
        try {
            new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

                public Object invoke(InvocationContext context) throws Throwable {
                    return "test";
                }
            }).invokeNext(new DefaultMethodInvocationContext());
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(ServiceManagerFactory.getMessageRecordFactory().findMessage("NIMBUS000"), e.getMessage());
        }
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) Invoker(jp.ossc.nimbus.service.aop.Invoker) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 47 with DefaultInterceptorChainList

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChainList in project nimbus by nimbus-org.

the class ExceptionThrowInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ExceptionThrowInterceptorService interceptor = new ExceptionThrowInterceptorService();
    ServiceManagerFactory.registerService("Test", "ExceptionThrowInterceptor", interceptor);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setExceptionClassName("java.lang.IllegalArgumentException");
        ServiceManagerFactory.findManager("Test").startAllService();
        try {
            new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

                public Object invoke(InvocationContext context) throws Throwable {
                    return "test";
                }
            }).invokeNext(new DefaultMethodInvocationContext());
            fail();
        } catch (IllegalArgumentException e) {
            assertNull(e.getMessage());
        }
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) Invoker(jp.ossc.nimbus.service.aop.Invoker) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 48 with DefaultInterceptorChainList

use of jp.ossc.nimbus.service.aop.DefaultInterceptorChainList in project nimbus by nimbus-org.

the class ExceptionWrapInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    ExceptionWrapInterceptorService interceptor1 = new ExceptionWrapInterceptorService();
    ServiceManagerFactory.registerService("Test", "ExceptionWrapInterceptor", interceptor1);
    Interceptor interceptor2 = new Interceptor() {

        public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
            throw new IllegalArgumentException();
        }
    };
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        Properties mapping = new Properties();
        mapping.setProperty("java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException");
        interceptor1.setWrapExceptionMapping(mapping);
        ServiceManagerFactory.findManager("Test").startAllService();
        try {
            new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {

                public Object invoke(InvocationContext context) throws Throwable {
                    return "test";
                }
            }).invokeNext(new DefaultMethodInvocationContext());
            fail();
        } catch (UnsupportedOperationException e) {
            assertTrue(e.getMessage() == null || "java.lang.IllegalArgumentException".equals(e.getMessage()));
        }
    } finally {
        ServiceManagerFactory.findManager("Test").stopAllService();
        ServiceManagerFactory.findManager("Test").destroyAllService();
        ServiceManagerFactory.unregisterManager("Test");
    }
}
Also used : InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain) DefaultInterceptorChainList(jp.ossc.nimbus.service.aop.DefaultInterceptorChainList) Invoker(jp.ossc.nimbus.service.aop.Invoker) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) Properties(java.util.Properties) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)48 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)46 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)45 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)43 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)37 Invoker (jp.ossc.nimbus.service.aop.Invoker)36 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)31 HashMap (java.util.HashMap)20 Map (java.util.Map)10 ServiceName (jp.ossc.nimbus.core.ServiceName)9 Context (jp.ossc.nimbus.service.context.Context)9 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)8 Random (java.util.Random)7 Properties (java.util.Properties)6 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)6 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)6 Method (java.lang.reflect.Method)5 DefaultInvocationContext (jp.ossc.nimbus.service.aop.DefaultInvocationContext)5 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)5 MethodReflectionCallInvokerService (jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService)4