Search in sources :

Example 6 with MethodInvocationContext

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

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

Aggregations

InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)7 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)7 DefaultInterceptorChain (jp.ossc.nimbus.service.aop.DefaultInterceptorChain)5 DefaultInterceptorChainList (jp.ossc.nimbus.service.aop.DefaultInterceptorChainList)5 DefaultMethodInvocationContext (jp.ossc.nimbus.service.aop.DefaultMethodInvocationContext)5 Context (jp.ossc.nimbus.service.context.Context)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Interceptor (jp.ossc.nimbus.service.aop.Interceptor)3 InterceptorChain (jp.ossc.nimbus.service.aop.InterceptorChain)3 Invoker (jp.ossc.nimbus.service.aop.Invoker)3 Method (java.lang.reflect.Method)2 AttributeMetaData (jp.ossc.nimbus.core.AttributeMetaData)2 MockFactory (jp.ossc.nimbus.service.aop.MockFactory)2 MethodReflectionCallInvokerService (jp.ossc.nimbus.service.aop.invoker.MethodReflectionCallInvokerService)2 MethodCallJournalData (jp.ossc.nimbus.service.journal.editor.MethodCallJournalData)2 MethodReturnJournalData (jp.ossc.nimbus.service.journal.editor.MethodReturnJournalData)2 WritableElement (jp.ossc.nimbus.service.writer.WritableElement)2 Iterator (java.util.Iterator)1 ServiceName (jp.ossc.nimbus.core.ServiceName)1