Search in sources :

Example 21 with InterceptorData

use of org.apache.openejb.core.interceptor.InterceptorData in project tomee by apache.

the class StatelessContainer method invokeWebService.

private Object invokeWebService(final Object[] args, final BeanContext beanContext, final Method runMethod, final Instance instance) throws Exception {
    if (args.length < 2) {
        throw new IllegalArgumentException("WebService calls must follow format {messageContext, interceptor, [arg...]}.");
    }
    final Object messageContext = args[0];
    // This object will be used as an interceptor in the stack and will be responsible
    // for unmarshalling the soap message parts into an argument list that will be
    // used for the actual method invocation.
    //
    // We just need to make it an interceptor in the OpenEJB sense and tack it on the end
    // of our stack.
    final Object interceptor = args[1];
    final Class<?> interceptorClass = interceptor.getClass();
    //  Add the webservice interceptor to the list of interceptor instances
    final Map<String, Object> interceptors = new HashMap<String, Object>(instance.interceptors);
    interceptors.put(interceptor.getClass().getName(), interceptor);
    //  Create an InterceptorData for the webservice interceptor to the list of interceptorDatas for this method
    final List<InterceptorData> interceptorDatas = new ArrayList<InterceptorData>();
    final InterceptorData providerData = new InterceptorData(interceptorClass);
    providerData.getAroundInvoke().addAll(retrieveAroundInvokes(interceptorClass));
    interceptorDatas.add(0, providerData);
    interceptorDatas.addAll(beanContext.getMethodInterceptors(runMethod));
    final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.BUSINESS_WS, interceptorDatas, interceptors);
    final Object[] params = new Object[runMethod.getParameterTypes().length];
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    Object returnValue = null;
    if (messageContext instanceof javax.xml.rpc.handler.MessageContext) {
        threadContext.set(javax.xml.rpc.handler.MessageContext.class, (javax.xml.rpc.handler.MessageContext) messageContext);
        returnValue = interceptorStack.invoke((javax.xml.rpc.handler.MessageContext) messageContext, params);
    } else if (messageContext instanceof javax.xml.ws.handler.MessageContext) {
        AddressingSupport wsaSupport = NoAddressingSupport.INSTANCE;
        for (int i = 2; i < args.length; i++) {
            if (args[i] instanceof AddressingSupport) {
                wsaSupport = (AddressingSupport) args[i];
            }
        }
        threadContext.set(AddressingSupport.class, wsaSupport);
        threadContext.set(javax.xml.ws.handler.MessageContext.class, (javax.xml.ws.handler.MessageContext) messageContext);
        returnValue = interceptorStack.invoke((javax.xml.ws.handler.MessageContext) messageContext, params);
    }
    return returnValue;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ThreadContext(org.apache.openejb.core.ThreadContext) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) NoAddressingSupport(org.apache.openejb.core.webservices.NoAddressingSupport) AddressingSupport(org.apache.openejb.core.webservices.AddressingSupport)

Aggregations

InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)21 InterceptorStack (org.apache.openejb.core.interceptor.InterceptorStack)16 Method (java.lang.reflect.Method)14 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)10 BeanContext (org.apache.openejb.BeanContext)9 ThreadContext (org.apache.openejb.core.ThreadContext)9 SystemInstance (org.apache.openejb.loader.SystemInstance)8 BeanTransactionPolicy (org.apache.openejb.core.transaction.BeanTransactionPolicy)6 JtaTransactionPolicy (org.apache.openejb.core.transaction.JtaTransactionPolicy)6 HashMap (java.util.HashMap)5 SessionBean (javax.ejb.SessionBean)5 ArrayList (java.util.ArrayList)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 InstanceContext (org.apache.openejb.core.InstanceContext)4 EJBLocalObject (javax.ejb.EJBLocalObject)3 EJBObject (javax.ejb.EJBObject)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 LoginException (javax.security.auth.login.LoginException)3 ApplicationException (org.apache.openejb.ApplicationException)3 SuspendedTransaction (org.apache.openejb.core.transaction.BeanTransactionPolicy.SuspendedTransaction)3