Search in sources :

Example 46 with InvocationContext

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

Example 47 with InvocationContext

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

the class ThreadContextImportInterceptorService 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 input = inputObj;
    if (chain != null) {
        input = ((MethodInvocationContext) input).getParameters()[0];
    }
    FacadeValue in = (FacadeValue) input;
    if (threadContextServiceName != null) {
        final Context context = (Context) ServiceManagerFactory.getServiceObject(threadContextServiceName);
        if (headerKeys == null) {
            final Iterator keys = in.getHederKeys().iterator();
            while (keys.hasNext()) {
                final String key = (String) keys.next();
                context.put(key, in.getHeader(key));
            }
        } else {
            for (int i = 0; i < headerKeys.length; i++) {
                final String key = headerKeys[i];
                context.put(key, in.getHeader(key));
            }
        }
    }
    if (interceptChain != null) {
        return interceptChain.invokeChain(inputObj);
    } else {
        return chain.invokeNext((InvocationContext) inputObj);
    }
}
Also used : MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) Context(jp.ossc.nimbus.service.context.Context) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) Iterator(java.util.Iterator)

Example 48 with InvocationContext

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

the class AOPInterceptorAdaptorInterceptorService method invokeChain.

public Object invokeChain(Object inputObj, InterceptorChain interceptChain) throws InterceptorException, TargetCheckedException, TargetUncheckedException {
    InterceptorChainInvokerAccessImpl invoker = (InterceptorChainInvokerAccessImpl) interceptChain;
    InvocationContext context = new DefaultMethodInvocationContext(invoker.mCallBackObject, invoker.mCallBackmethod, new Object[] { inputObj });
    context.setAttribute(CHAIN_ATTRIBUTE_NAME, interceptChain);
    try {
        return chain.invokeNext(context);
    } catch (TargetUncheckedException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (TargetCheckedException e) {
        throw e;
    } catch (InterceptorException e) {
        throw e;
    } catch (Exception e) {
        throw new InterceptorException(e);
    } catch (Throwable th) {
        throw (Error) th;
    }
}
Also used : DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) DefaultMethodInvocationContext(jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)

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