Search in sources :

Example 1 with AddressingSupport

use of org.apache.openejb.core.webservices.AddressingSupport in project tomee by apache.

the class EjbWsContext method getAddressingSupport.

private AddressingSupport getAddressingSupport() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final AddressingSupport wsaSupport = threadContext.get(AddressingSupport.class);
    if (wsaSupport == null) {
        throw new IllegalStateException("Only calls on the service-endpoint can get the EndpointReference.");
    }
    return wsaSupport;
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) AddressingSupport(org.apache.openejb.core.webservices.AddressingSupport)

Example 2 with AddressingSupport

use of org.apache.openejb.core.webservices.AddressingSupport in project tomee by apache.

the class EjbWsContext method getAddressingSupport.

private AddressingSupport getAddressingSupport() {
    final ThreadContext threadContext = ThreadContext.getThreadContext();
    final AddressingSupport wsaSupport = threadContext.get(AddressingSupport.class);
    if (wsaSupport == null) {
        throw new IllegalStateException("Only calls on the service-endpoint can get the EndpointReference.");
    }
    return wsaSupport;
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) AddressingSupport(org.apache.openejb.core.webservices.AddressingSupport)

Example 3 with AddressingSupport

use of org.apache.openejb.core.webservices.AddressingSupport in project tomee by apache.

the class SingletonContainer 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];
    if (messageContext == null) {
        throw new IllegalArgumentException("MessageContext is null.");
    }
    // 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];
    if (interceptor == null) {
        throw new IllegalArgumentException("Interceptor instance is null.");
    }
    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(interceptorClass.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);
        List<Method> aroundInvokes = interceptorCache.get(interceptorClass);
        if (aroundInvokes == null) {
            aroundInvokes = new ClassFinder(interceptorClass).findAnnotatedMethods(AroundInvoke.class);
            if (SingletonContainer.class.getClassLoader() == interceptorClass.getClassLoader()) {
                // use cache only for server classes
                final List<Method> value = new CopyOnWriteArrayList<Method>(aroundInvokes);
                // ensure it to be thread safe
                aroundInvokes = interceptorCache.putIfAbsent(interceptorClass, value);
                if (aroundInvokes == null) {
                    aroundInvokes = value;
                }
            }
        }
        providerData.getAroundInvoke().addAll(aroundInvokes);
        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];
    if (messageContext instanceof javax.xml.rpc.handler.MessageContext) {
        ThreadContext.getThreadContext().set(javax.xml.rpc.handler.MessageContext.class, (javax.xml.rpc.handler.MessageContext) messageContext);
        return 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.getThreadContext().set(AddressingSupport.class, wsaSupport);
        ThreadContext.getThreadContext().set(javax.xml.ws.handler.MessageContext.class, (javax.xml.ws.handler.MessageContext) messageContext);
        return interceptorStack.invoke((javax.xml.ws.handler.MessageContext) messageContext, params);
    }
    throw new IllegalArgumentException("Uknown MessageContext type: " + messageContext.getClass().getName());
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Method(java.lang.reflect.Method) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) ClassFinder(org.apache.xbean.finder.ClassFinder) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NoAddressingSupport(org.apache.openejb.core.webservices.NoAddressingSupport) AddressingSupport(org.apache.openejb.core.webservices.AddressingSupport)

Example 4 with AddressingSupport

use of org.apache.openejb.core.webservices.AddressingSupport 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

AddressingSupport (org.apache.openejb.core.webservices.AddressingSupport)4 ThreadContext (org.apache.openejb.core.ThreadContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)2 InterceptorStack (org.apache.openejb.core.interceptor.InterceptorStack)2 NoAddressingSupport (org.apache.openejb.core.webservices.NoAddressingSupport)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 EJBObject (javax.ejb.EJBObject)1 ClassFinder (org.apache.xbean.finder.ClassFinder)1