Search in sources :

Example 1 with InterceptorException

use of jp.ossc.nimbus.service.aspect.interfaces.InterceptorException 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 2 with InterceptorException

use of jp.ossc.nimbus.service.aspect.interfaces.InterceptorException 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)

Example 3 with InterceptorException

use of jp.ossc.nimbus.service.aspect.interfaces.InterceptorException in project nimbus by nimbus-org.

the class DefaultAsynchCallInterceptorService method invokeInternal.

protected Object invokeInternal(Object inputObj, jp.ossc.nimbus.service.aspect.interfaces.InterceptorChain interceptChain, jp.ossc.nimbus.service.aop.InterceptorChain chain) throws Throwable {
    Object ret = null;
    Object input = inputObj;
    if (chain != null) {
        input = ((MethodInvocationContext) input).getParameters()[0];
    }
    if (input instanceof ObjectMessage) {
        ObjectMessage msg = (ObjectMessage) input;
        FacadeValue in = null;
        if (isIgnoreRedelivery) {
            try {
                if (msg.getJMSRedelivered()) {
                    return ret;
                }
            } catch (JMSException e) {
                throw new InterceptorException("getJMSRedelivered JMSException", e);
            }
        }
        if (redeliveryInterval > 0) {
            try {
                if (msg.getJMSRedelivered()) {
                    Thread.sleep(redeliveryInterval);
                }
            } catch (InterruptedException e) {
            } catch (JMSException e) {
                throw new InterceptorException("getJMSRedelivered JMSException", e);
            }
        }
        try {
            in = (FacadeValue) msg.getObject();
        } catch (JMSException e) {
            throw new InterceptorException("getObject JMSException", e);
        }
        try {
            if (interceptChain != null) {
                ret = interceptChain.invokeChain(in);
            } else {
                final MethodInvocationContext context = (MethodInvocationContext) inputObj;
                context.setParameters(new Object[] { in });
                ret = chain.invokeNext(context);
            }
        } catch (TargetUncheckedException e) {
            Throwable th = e.getCause();
            if (th instanceof RuntimeException) {
                if (queueSessionFactory != null) {
                    try {
                        Queue replyQueue = (Queue) msg.getJMSReplyTo();
                        if (replyQueue == null) {
                            throw e;
                        }
                    } catch (JMSException e2) {
                        throw new InterceptorException("Unexpected Exception", e2);
                    }
                }
                ret = th;
            } else {
                throw new InterceptorException("Unexpected Exception", th);
            }
        } catch (TargetCheckedException e) {
            // ここに飛んでくることはない。
            // コマンド層でキャッチされ処理済みのはず。
            e.printStackTrace();
        }
        if (queueSessionFactory != null) {
            try {
                Queue replyQueue = (Queue) msg.getJMSReplyTo();
                if (replyQueue != null) {
                    QueueTransanctionResource resource = null;
                    try {
                        resource = (QueueTransanctionResource) queueSessionFactory.makeResource(null);
                        QueueSession session = (QueueSession) resource.getObject();
                        QueueSender sender = session.createSender(replyQueue);
                        sender.send(session.createObjectMessage((Serializable) ret), deliveryMode, priority, timeToLive);
                    } finally {
                        if (resource != null) {
                            resource.close();
                        }
                    }
                }
            } catch (Exception e) {
                throw new InterceptorException("Unexpected Exception", e);
            }
        }
    } else {
        if (interceptChain != null) {
            ret = interceptChain.invokeChain(input);
        } else {
            ret = chain.invokeNext((InvocationContext) inputObj);
        }
    }
    return ret;
}
Also used : MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) 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) QueueTransanctionResource(jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException)

Aggregations

InterceptorException (jp.ossc.nimbus.service.aspect.interfaces.InterceptorException)3 TargetCheckedException (jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException)3 TargetUncheckedException (jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException)3 RemoteException (java.rmi.RemoteException)2 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)2 InterceptorChainInvoker (jp.ossc.nimbus.service.aspect.interfaces.InterceptorChainInvoker)2 CreateException (javax.ejb.CreateException)1 EJBException (javax.ejb.EJBException)1 NamingException (javax.naming.NamingException)1 IOCException (jp.ossc.nimbus.ioc.IOCException)1 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)1 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)1 QueueTransanctionResource (jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource)1