Search in sources :

Example 11 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class AsyncResponseImpl method initContinuation.

private void initContinuation() {
    ContinuationProvider provider = (ContinuationProvider) inMessage.get(ContinuationProvider.class.getName());
    if (provider == null) {
        throw new IllegalArgumentException("Continuation not supported. " + "Please ensure that all servlets and servlet filters support async operations");
    }
    cont = provider.getContinuation();
    initialSuspend = true;
}
Also used : ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider)

Example 12 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider 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)

Example 13 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project jbossws-cxf by jbossws.

the class EndpointImpl method echo.

public String echo(String user) {
    final ContinuationProvider cp = (ContinuationProvider) ctx.getMessageContext().get(ContinuationProvider.class.getName());
    final Continuation c = cp.getContinuation();
    synchronized (c) {
        if (c.isNew()) {
            FutureTask<String> task = new FutureTask<String>(new MyCallable(user, c));
            c.setObject(task);
            executor.execute(task);
        } else {
            @SuppressWarnings("unchecked") FutureTask<String> task = (FutureTask<String>) c.getObject();
            if (task.isDone()) {
                try {
                    return task.get();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        c.suspend(TIMEOUT);
    }
    return null;
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) FutureTask(java.util.concurrent.FutureTask)

Aggregations

ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)13 Continuation (org.apache.cxf.continuations.Continuation)9 URL (java.net.URL)3 Endpoint (javax.xml.ws.Endpoint)3 Bus (org.apache.cxf.Bus)3 SOAPService (org.apache.hello_world_soap_http.SOAPService)3 Message (org.apache.cxf.message.Message)2 HTTPConduitFactory (org.apache.cxf.transport.http.HTTPConduitFactory)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Method (java.lang.reflect.Method)1 FutureTask (java.util.concurrent.FutureTask)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 UriInfo (javax.ws.rs.core.UriInfo)1 MessageContext (javax.xml.ws.handler.MessageContext)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 UseAsyncMethod (org.apache.cxf.annotations.UseAsyncMethod)1 UseNio (org.apache.cxf.annotations.UseNio)1 SuspendedInvocationException (org.apache.cxf.continuations.SuspendedInvocationException)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1