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;
}
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;
}
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;
}
Aggregations