protected AsyncResponseImpl handleSingle(Message inMessage, Single<?> single) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); Disposable d = single.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } return asyncResponse; }
protected AsyncResponseImpl handleObservable(Message inMessage, Observable<?> obs) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); Disposable d = obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } return asyncResponse; }
protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof Observable) { final Observable<?> obs = (Observable<?>)result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse, t)); return asyncResponse; } return null; }
protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof Observable) { final Observable<?> obs = (Observable<?>)result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse, t)); return asyncResponse; } return null; }
protected AsyncResponseImpl handleFlowable(Message inMessage, Flowable<?> f) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); if (!isStreamingSubscriberUsed(f, asyncResponse, inMessage)) { Disposable d = f.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } } return asyncResponse; }
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; }
@Override public SseEventSink createContext(Message message) { final HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST); if (request == null) { throw new IllegalStateException("Unable to retrieve HTTP request from the context"); } final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter( ServerProviderFactory.getInstance(message), message.getExchange()); final AsyncResponse async = new AsyncResponseImpl(message); return new SseEventSinkImpl(writer, async, request.getAsyncContext()); } }
@Override public SseEventSink createContext(Message message) { final HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST); if (request == null) { throw new IllegalStateException("Unable to retrieve HTTP request from the context"); } final MessageBodyWriter<OutboundSseEvent> writer = new OutboundSseEventBodyWriter( ServerProviderFactory.getInstance(message), message.getExchange()); final AsyncResponse async = new AsyncResponseImpl(message); return new SseEventSinkImpl(writer, async, request.getAsyncContext()); } }
@Override protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof Flux) { final Flux<?> flux = (Flux<?>) result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); if (!isStreamingSubscriberUsed(flux, asyncResponse, inMessage)) { flux.doOnNext(asyncResponse::resume) .doOnError(t -> handleThrowable(asyncResponse, t)) .subscribe(); } return asyncResponse; } else if (result instanceof Mono) { final Mono<?> mono = (Mono<?>) result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); mono.doOnNext(asyncResponse::resume) .doOnError(t -> handleThrowable(asyncResponse, t)) .subscribe(); return asyncResponse; } return null; }
@Override protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof Flux) { final Flux<?> flux = (Flux<?>) result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); if (!isStreamingSubscriberUsed(flux, asyncResponse, inMessage)) { flux.doOnNext(asyncResponse::resume) .doOnError(t -> handleThrowable(asyncResponse, t)) .subscribe(); } return asyncResponse; } else if (result instanceof Mono) { final Mono<?> mono = (Mono<?>) result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); mono.doOnNext(asyncResponse::resume) .doOnError(t -> handleThrowable(asyncResponse, t)) .subscribe(); return asyncResponse; } return null; }
private static Object processRequestBodyParameter(Class<?> parameterClass, Type parameterType, Annotation[] parameterAnns, 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 (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); }
return new AsyncResponseImpl(message);