Search in sources :

Example 31 with InterceptorChain

use of jp.ossc.nimbus.service.aop.InterceptorChain 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)

Example 32 with InterceptorChain

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

the class EJBDriveDispatcher method invokeInterceptor.

/**
 * インターセプタを通してUnitOfWorkを実行する。
 * インターセプタが指定されていなければ直接UnitOfWorkを実行する。
 * @param input
 * @return 出力オブジェクト
 * @throws InterceptorException
 * @throws TargetCheckedException
 * @throws TargetUncheckedException
 */
public Object invokeInterceptor(Object input) throws InterceptorException, TargetCheckedException, TargetUncheckedException {
    Object ret = null;
    if (mFactory == null && chainFactory == null) {
        try {
            ret = (UnitOfWork) invokeUnitOfWorkBase((UnitOfWork) input);
        } catch (IOCException e) {
            throw new TargetUncheckedException(e.getCause());
        } catch (Throwable e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00018", e);
            }
            throw new TargetUncheckedException(e);
        }
    } else {
        if (this.getLogger() != null) {
            this.getLogger().write("IOC__00004", this.getInterceptorKey());
        }
        if (mFactory != null) {
            InterceptorChainInvoker ici = this.mFactory.createInterceptorInvoker(this.getInterceptorKey());
            ret = ici.invokeChain(this, input);
        } else if (chainFactory != null) {
            try {
                InterceptorChain chain = chainFactory.getInterceptorChain(getInterceptorKey());
                ret = chain.invokeNext(createInvocationContext(input));
            } catch (TargetUncheckedException e) {
                throw e;
            } catch (TargetCheckedException e) {
                throw e;
            } catch (InterceptorException e) {
                throw e;
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new IOCException(e);
            } catch (Throwable th) {
                if (th instanceof Error) {
                    throw (Error) th;
                }
            }
        }
    }
    return ret;
}
Also used : InterceptorChainInvoker(jp.ossc.nimbus.service.aspect.interfaces.InterceptorChainInvoker) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) IOCException(jp.ossc.nimbus.ioc.IOCException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException) NamingException(javax.naming.NamingException) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException) IOCException(jp.ossc.nimbus.ioc.IOCException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException)

Example 33 with InterceptorChain

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

the class SLSBCommandBean method invokeCommand.

/**
 * コマンドを実行する。
 * @param cmd コマンド
 * @return 実行後のコマンド
 */
public Command invokeCommand(Command cmd) {
    if (this.getLogger() != null) {
        this.getLogger().write("IOC__00006");
    }
    // インターセプタで実行した際にも同じフローキーで実行させるため保持しておく。
    String key = cmd.getFlowKey();
    InterceptorChainInvoker ici = null;
    InterceptorChain ic = null;
    if (this.getIciFactory() != null) {
        ici = this.getIciFactory().createInterceptorInvoker(key);
    } else if (this.getIcFactory() != null) {
        ic = this.getIcFactory().getInterceptorChain(key);
    }
    Object ret = null;
    if (ici == null && ic == null) {
        // 直接実行
        if (this.getLogger() != null) {
            this.getLogger().write("IOC__00007");
        }
        try {
            ret = invokeBeanFlow(cmd);
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                cmd.setException(e);
            }
        } catch (Throwable e) {
            throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
        }
    } else if (ici != null) {
        // インターセプタを通して実行
        try {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00008");
            }
            ret = ici.invokeChain(this, cmd);
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00012");
            }
        } catch (InterceptorException e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00009", e);
            }
            throw new IOCException("SLSBCommandBean invokeCommand InterceptorException", e);
        } catch (TargetCheckedException e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00010", e);
            }
            cmd.setException(e.getCause());
            return cmd;
        } catch (TargetUncheckedException e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00011", e.getCause());
            }
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else {
                throw new IOCException("SLSBCommandBean invokeCommand TargetUncheckedException", e.getCause());
            }
        } catch (Throwable e) {
            throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
        }
    } else {
        // インターセプタを通して実行
        try {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00008");
            }
            ret = ic.invokeNext(createInvocationContext(cmd));
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00012");
            }
        } catch (RuntimeException e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00011", e);
            }
            throw e;
        } catch (Exception e) {
            if (this.getLogger() != null) {
                this.getLogger().write("IOC__00010", e);
            }
            cmd.setException(e);
            return cmd;
        } catch (Throwable e) {
            throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
        }
    }
    cmd.setOutObject(ret);
    return cmd;
}
Also used : InterceptorChainInvoker(jp.ossc.nimbus.service.aspect.interfaces.InterceptorChainInvoker) InterceptorChain(jp.ossc.nimbus.service.aop.InterceptorChain) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException) RemoteException(java.rmi.RemoteException)

Aggregations

InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)33 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)31 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)31 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)29 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)28 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)26 Invoker (jp.ossc.nimbus.service.aop.Invoker)20 HashMap (java.util.HashMap)10 ServiceName (jp.ossc.nimbus.core.ServiceName)7 ServiceMetaData (jp.ossc.nimbus.core.ServiceMetaData)6 Method (java.lang.reflect.Method)5 Map (java.util.Map)5 Properties (java.util.Properties)5 DefaultInvocationContext (jp.ossc.nimbus.service.aop.DefaultInvocationContext)5 Context (jp.ossc.nimbus.service.context.Context)5 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)4 MethodReflectionCallInvokerService (jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService)4 DefaultContextService (jp.ossc.nimbus.service.context.DefaultContextService)4 ArrayList (java.util.ArrayList)3 DefaultThreadLocalInterceptorChain (jp.ossc.nimbus.service.aop.DefaultThreadLocalInterceptorChain)3