Continuations API

CXF offers Continuations API to manage asynchronous (suspended) invocations.

ContinuationProvider represents a transport capable of suspending and resuming the invocations on request.

CXF offers Servlet3 and legacy Jetty Continuations HTTP as well as JMS ContinuationProvider implementations.
ContinuationProvider can be used to get Continuation which represents a current active or suspended invocation.

The provider and continuations can be obtained from the current CXF message like this:

import org.apache.cxf.continuations.ContinuationProvider;
import org.apache.cxf.continuations.Continuation;

ContinuationProvider provider = (ContinuationProvider)message.get(ContinuationProvider.class.getName())
Continuation continuation = provider.getContinuation();

The continuation can be suspended and resumed.

Calling Continuation.suspend() and returning from the current method/code is enough to get CXF suspending the request. Additionally throwing SuspendedInvocationException was required originally but is no longer required/recommended.

Resuming the continuation will get the suspended thread returning, this is typically done by a thread which has completed an asynchronous task.

Advanced applications can register ContinuationCallback with the current exchange in order to get the notifications that a given Continuation has completed its work by returning the data to the client.

The custom applications can interact directly with Continuations API. CXF also offers higher-level support for asynchronous invocations built on top of Continuations API.


JAX-WS frontend supports this annotation, please check the CXF Annotations page for more information.

JAX-RS 2.0 AsyncResponse

JAX-RS 2.0 AsyncResponse is implemented in terms of Continuations API. Please see this section for more information.

Suspending invocations from CXF interceptors

Advanced custom CXF interceptors can suspend the incoming requests and resume them when needed.


Enabling HTTP continuations

Make sure CXFServlet is supporting the asynchronous requests, check the Servlet Transport page for more information.