@Override public Map<Class<?>, Object> install(Map<Class<?>, Object> state) { ResteasyContext.pushContextDataMap(state); return null; }
@Override public synchronized void resume(Throwable t) { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // not suspended, or suspend/abortWith within filter, same thread: collect and move on throwable = t; suspended = false; } else { ResteasyContext.pushContextDataMap(contextDataMap); writeException(t); } }
@Override public synchronized void resume(Throwable t) { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // not suspended, or suspend/abortWith within filter, same thread: collect and move on throwable = t; suspended = false; } else { ResteasyContext.pushContextDataMap(contextDataMap); writeException(t); } }
protected void internalResume(Throwable t, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class); HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); try { dispatcher.writeException(httpRequest, httpResponse, t, onComplete); }catch(Throwable t2) { // ignore t2 and report the original exception without going through filters dispatcher.unhandledAsynchronousException(httpResponse, t); onComplete.accept(t); } }
protected boolean internalResume(Throwable exc, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); dispatcher.asynchronousExceptionDelivery(request, response, exc, t -> { onComplete.accept(t); completionCallbacks(exc); }); return true; }
@Override public synchronized void resume() { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // suspend/resume within filter, same thread: just ignore and move on suspended = false; return; } ResteasyContext.pushContextDataMap(contextDataMap); // go on, but with proper exception handling try { filter(); }catch(Throwable t) { // don't throw to client writeException(t); } }
@Override public synchronized void resume() { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // suspend/resume within filter, same thread: just ignore and move on suspended = false; return; } ResteasyContext.pushContextDataMap(contextDataMap); // go on, but with proper exception handling try { filter(); }catch(Throwable t) { // don't throw to client writeException(t); } }
protected void internalResume(Object entity, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class); HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); BuiltResponse builtResponse = createResponse(entity, httpRequest); try { sendBuiltResponse(builtResponse, httpRequest, httpResponse, e -> { if(e != null) { exceptionWhileResuming(e); } onComplete.accept(e); }); } catch (Throwable e) { exceptionWhileResuming(e); onComplete.accept(e); } }
@Override public synchronized void abortWith(Response response) { if(suspended && !inFilter) { ResteasyContext.pushContextDataMap(contextDataMap); httpRequest.getAsyncContext().getAsyncResponse().resume(response); } else { // not suspended, or suspend/abortWith within filter, same thread: collect and move on this.response = response; suspended = false; } }
private CompletionStage<Object> unwrapIfRequired(HttpRequest request, Object contextData, boolean unwrapAsync) { if(unwrapAsync && rawType != CompletionStage.class && contextData instanceof CompletionStage) { // FIXME: do not unwrap if we have no request? if(request != null ) { boolean resolved = ((CompletionStage<Object>) contextData).toCompletableFuture().isDone(); if(!resolved) { // make request async if(!request.getAsyncContext().isSuspended()) request.getAsyncContext().suspend(); Map<Class<?>, Object> contextDataMap = ResteasyContext.getContextDataMap(); // Don't forget to restore the context return ((CompletionStage<Object>) contextData).thenApply(value -> { ResteasyContext.pushContextDataMap(contextDataMap); return value; }); } } return (CompletionStage<Object>) contextData; } return CompletableFuture.completedFuture(contextData); }
protected boolean internalResume(Object entity, Consumer<Throwable> onComplete) ResteasyContext.pushContextDataMap(contextDataMap); Response response = null; if (entity == null)
ResteasyContext.pushContextDataMap(contextDataMap); try
@Override public Map<Class<?>, Object> install(Map<Class<?>, Object> state) { ResteasyContext.pushContextDataMap(state); return null; }
@Override public synchronized void resume(Throwable t) { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // not suspended, or suspend/abortWith within filter, same thread: collect and move on throwable = t; suspended = false; } else { ResteasyContext.pushContextDataMap(contextDataMap); writeException(t); } }
@Override public synchronized void resume(Throwable t) { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // not suspended, or suspend/abortWith within filter, same thread: collect and move on throwable = t; suspended = false; } else { ResteasyContext.pushContextDataMap(contextDataMap); writeException(t); } }
protected void internalResume(Throwable t, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class); HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); try { dispatcher.writeException(httpRequest, httpResponse, t, onComplete); }catch(Throwable t2) { // ignore t2 and report the original exception without going through filters dispatcher.unhandledAsynchronousException(httpResponse, t); onComplete.accept(t); } }
protected boolean internalResume(Throwable exc, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); dispatcher.asynchronousExceptionDelivery(request, response, exc, t -> { onComplete.accept(t); completionCallbacks(exc); }); return true; }
@Override public synchronized void resume() { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // suspend/resume within filter, same thread: just ignore and move on suspended = false; return; } ResteasyContext.pushContextDataMap(contextDataMap); // go on, but with proper exception handling try { filter(); }catch(Throwable t) { // don't throw to client writeException(t); } }
protected void internalResume(Object entity, Consumer<Throwable> onComplete) { ResteasyContext.pushContextDataMap(contextDataMap); HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class); HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); BuiltResponse builtResponse = createResponse(entity, httpRequest); try { sendBuiltResponse(builtResponse, httpRequest, httpResponse, e -> { if(e != null) { exceptionWhileResuming(e); } onComplete.accept(e); }); } catch (Throwable e) { exceptionWhileResuming(e); onComplete.accept(e); } }
@Override public synchronized void abortWith(Response response) { if(suspended && !inFilter) { ResteasyContext.pushContextDataMap(contextDataMap); httpRequest.getAsyncContext().getAsyncResponse().resume(response); } else { // not suspended, or suspend/abortWith within filter, same thread: collect and move on this.response = response; suspended = false; } }