Search in sources :

Example 6 with AsyncResponseImpl

use of org.apache.cxf.jaxrs.impl.AsyncResponseImpl in project cxf by apache.

the class JAXRSUtils method processParameter.

private static Object processParameter(Class<?> parameterClass, Type parameterType, Annotation[] parameterAnns, Parameter parameter, MultivaluedMap<String, String> values, Message message, OperationResourceInfo ori) throws IOException, WebApplicationException {
    InputStream is = message.getContent(InputStream.class);
    if (is == null) {
        Reader reader = message.getContent(Reader.class);
        if (reader != null) {
            is = new ReaderInputStream(reader);
        }
    }
    if (parameter.getType() == ParameterType.REQUEST_BODY) {
        if (parameterClass == AsyncResponse.class) {
            return new AsyncResponseImpl(message);
        }
        String contentType = (String) message.get(Message.CONTENT_TYPE);
        if (contentType == null) {
            String defaultCt = (String) message.getContextualProperty(DEFAULT_CONTENT_TYPE);
            contentType = defaultCt == null ? MediaType.APPLICATION_OCTET_STREAM : defaultCt;
        }
        return readFromMessageBody(parameterClass, parameterType, parameterAnns, is, toMediaType(contentType), ori, message);
    } else if (parameter.getType() == ParameterType.CONTEXT) {
        return createContextValue(message, parameterType, parameterClass);
    } else if (parameter.getType() == ParameterType.BEAN) {
        return createBeanParamValue(message, parameterClass, ori);
    } else {
        return createHttpParameterValue(parameter, parameterClass, parameterType, parameterAnns, message, values, ori);
    }
}
Also used : ReaderInputStream(org.apache.cxf.io.ReaderInputStream) ReaderInputStream(org.apache.cxf.io.ReaderInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) AsyncResponseImpl(org.apache.cxf.jaxrs.impl.AsyncResponseImpl)

Example 7 with AsyncResponseImpl

use of org.apache.cxf.jaxrs.impl.AsyncResponseImpl in project cxf by apache.

the class JAXRSInvoker method checkFutureResponse.

protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) {
    if (result instanceof CompletionStage) {
        final CompletionStage<?> stage = (CompletionStage<?>) result;
        final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
        stage.whenComplete((v, t) -> {
            if (t instanceof CancellationException) {
                asyncResponse.cancel();
            } else {
                asyncResponse.resume(v != null ? v : t);
            }
        });
        return asyncResponse;
    }
    return null;
}
Also used : CancellationException(java.util.concurrent.CancellationException) AsyncResponseImpl(org.apache.cxf.jaxrs.impl.AsyncResponseImpl) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

AsyncResponseImpl (org.apache.cxf.jaxrs.impl.AsyncResponseImpl)7 Message (org.apache.cxf.message.Message)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 CancellationException (java.util.concurrent.CancellationException)1 CompletionStage (java.util.concurrent.CompletionStage)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1 ResourceContext (javax.ws.rs.container.ResourceContext)1 Application (javax.ws.rs.core.Application)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 Fault (org.apache.cxf.interceptor.Fault)1 ReaderInputStream (org.apache.cxf.io.ReaderInputStream)1 ResourceContextImpl (org.apache.cxf.jaxrs.impl.ResourceContextImpl)1