Search in sources :

Example 1 with UseAsyncMethod

use of org.apache.cxf.annotations.UseAsyncMethod in project cxf by apache.

the class AbstractJAXWSMethodInvoker method adjustMethodAndParams.

@Override
protected Method adjustMethodAndParams(Method mOriginal, Exchange ex, List<Object> params, Class<?> serviceObjectClass) {
    // If class implements Provider<T> interface, use overriden method from service object class
    // to check UseAsyncMethod annotation
    Method mso = getProviderServiceObjectMethod(mOriginal, serviceObjectClass);
    UseAsyncMethod uam = mso.getAnnotation(UseAsyncMethod.class);
    if (uam != null) {
        BindingOperationInfo bop = ex.getBindingOperationInfo();
        Method ret = bop.getProperty(ASYNC_METHOD, Method.class);
        if (ret == null) {
            Class<?>[] ptypes = new Class<?>[mso.getParameterTypes().length + 1];
            System.arraycopy(mso.getParameterTypes(), 0, ptypes, 0, mso.getParameterTypes().length);
            ptypes[mso.getParameterTypes().length] = AsyncHandler.class;
            try {
                ret = mso.getDeclaringClass().getMethod(mso.getName() + "Async", ptypes);
                bop.setProperty(ASYNC_METHOD, ret);
            } catch (Throwable t) {
            // ignore
            }
        }
        if (ret != null) {
            JaxwsServerHandler h = ex.get(JaxwsServerHandler.class);
            if (h != null) {
                return ret;
            }
            ContinuationProvider cp = ex.getInMessage().get(ContinuationProvider.class);
            // Check for decoupled endpoints: if partial response already was sent, ignore continuation
            boolean decoupledEndpoints = MessageUtils.getContextualBoolean(ex.getInMessage(), PARTIAL_RESPONSE_SENT_PROPERTY, false);
            if ((cp == null) && uam.always() || decoupledEndpoints) {
                JaxwsServerHandler handler = new JaxwsServerHandler(null);
                ex.put(JaxwsServerHandler.class, handler);
                params.add(handler);
                return ret;
            } else if (cp != null && cp.getContinuation() != null) {
                final Continuation c = cp.getContinuation();
                c.suspend(0);
                JaxwsServerHandler handler = new JaxwsServerHandler(c);
                ex.put(JaxwsServerHandler.class, handler);
                params.add(handler);
                return ret;
            }
        }
    }
    return mOriginal;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) UseAsyncMethod(org.apache.cxf.annotations.UseAsyncMethod) UseAsyncMethod(org.apache.cxf.annotations.UseAsyncMethod) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)1 UseAsyncMethod (org.apache.cxf.annotations.UseAsyncMethod)1 Continuation (org.apache.cxf.continuations.Continuation)1 ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1