Search in sources :

Example 21 with InvocationContext

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

the class ExceptionWrapInterceptorServiceTest method test2.

public void test2() 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 IOException("test");
        }
    };
    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 (IOException e) {
            assertEquals("test", 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) IOException(java.io.IOException) 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)

Example 22 with InvocationContext

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

the class ExceptionWrapInterceptorServiceTest method test3.

public void test3() 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.RuntimeException", "java.lang.UnsupportedOperationException");
        interceptor1.setWrapExceptionMapping(mapping);
        interceptor1.setMessage("例外が発生しました。ラップします。");
        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) {
            assertEquals("例外が発生しました。ラップします。", 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)

Example 23 with InvocationContext

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

the class ExceptionWrapInterceptorServiceTest method test4.

public void test4() 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);
        interceptor1.setMessageKey("WARN");
        interceptor1.setMessageArgs(new String[] { "例外が発生しました。ラップします。" });
        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) {
            assertEquals("例外が発生しました。ラップします。", 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)

Example 24 with InvocationContext

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

the class MethodAsynchronousInterceptorServiceTest method test3.

public void test3() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MethodAsynchronousInterceptorService interceptor = new MethodAsynchronousInterceptorService();
    ServiceManagerFactory.registerService("Test", "MethodAsynchronousInterceptor", interceptor);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        interceptor.setResponseTimeout(200);
        interceptor.setFailToWaitResponseTimeout(false);
        ServiceManagerFactory.findManager("Test").startAllService();
        assertNull(new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                Thread.sleep(500);
                return "test";
            }
        }).invokeNext(new DefaultMethodInvocationContext(new Integer(100), Integer.class.getMethod("toString", (Class[]) null), null)));
    } 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) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Example 25 with InvocationContext

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

the class MethodAsynchronousInterceptorServiceTest method test1.

public void test1() throws Throwable {
    ServiceManagerFactory.registerManager("Test");
    MethodAsynchronousInterceptorService interceptor = new MethodAsynchronousInterceptorService();
    ServiceManagerFactory.registerService("Test", "MethodAsynchronousInterceptor", interceptor);
    try {
        ServiceManagerFactory.findManager("Test").createAllService();
        ServiceManagerFactory.findManager("Test").startAllService();
        final Date invokeTime = new Date();
        assertNull(new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {

            public Object invoke(InvocationContext context) throws Throwable {
                Thread.sleep(500);
                invokeTime.setTime(System.currentTimeMillis());
                return "test";
            }
        }).invokeNext(new DefaultMethodInvocationContext(new Integer(100), Integer.class.getMethod("toString", (Class[]) null), null)));
        Date returnTime = new Date();
        Thread.sleep(1000);
        assertTrue(returnTime.before(invokeTime));
    } 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) Interceptor(jp.ossc.nimbus.service.aop.Interceptor) Date(java.util.Date) DefaultInterceptorChain(jp.ossc.nimbus.service.aop.DefaultInterceptorChain)

Aggregations

InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)48 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)45 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)42 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)41 Invoker (jp.ossc.nimbus.service.aop.Invoker)36 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)34 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)29 HashMap (java.util.HashMap)19 Map (java.util.Map)10 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)9 Context (jp.ossc.nimbus.service.context.Context)9 ServiceName (jp.ossc.nimbus.core.ServiceName)8 Random (java.util.Random)7 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)7 Properties (java.util.Properties)6 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)5 DefaultInvocationContext (jp.ossc.nimbus.service.aop.DefaultInvocationContext)5 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3