private void writeException(Throwable t) { /* * Here we cannot call AsyncResponse.resume(t) because that would invoke the response filters * and we should not invoke them because we're already in them. */ HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); SynchronousDispatcher dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class); ResteasyAsynchronousResponse asyncResponse = request.getAsyncContext().getAsyncResponse(); RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request); tracingLogger.flush(httpResponse.getOutputHeaders()); dispatcher.unhandledAsynchronousException(httpResponse, t); onComplete.accept(t); asyncResponse.complete(); asyncResponse.completionCallbacks(t); }
private void writeException(Throwable t) { /* * Here, contrary to ContainerResponseContextImpl.writeException, we can use the async response * to write the exception, because it calls the right response filters, complete() and callbacks */ httpRequest.getAsyncContext().getAsyncResponse().resume(t); }
public void initializeAsync(ResteasyAsynchronousResponse asyncResponse) { asyncResponse.setAnnotations(method.getAnnotatedMethod().getAnnotations()); asyncResponse.setWriterInterceptors(writerInterceptors); asyncResponse.setResponseFilters(responseFilters); if (asyncResponse instanceof ResourceMethodInvokerAwareResponse) { ((ResourceMethodInvokerAwareResponse)asyncResponse).setMethod(this); } }
public void initializeAsync(ResteasyAsynchronousResponse asyncResponse) { asyncResponse.setAnnotations(method.getAnnotatedMethod().getAnnotations()); asyncResponse.setWriterInterceptors(writerInterceptors); asyncResponse.setResponseFilters(responseFilters); asyncResponse.setMethod(this); }
request.getAsyncContext().getAsyncResponse().completionCallbacks(ex); throw x; request.getAsyncContext().getAsyncResponse().resume(ex);
protected void doComplete() { asyncResponse.complete(); }
request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
@Override public ResteasyAsynchronousResponse suspend(long time, TimeUnit unit) throws IllegalStateException { wasSuspended = true; asynchronousResponse = new SynchronousAsynchronousResponse(dispatcher, request, response); asynchronousResponse.setTimeout(time, unit); return asynchronousResponse; }
public final synchronized void complete(Throwable t) { if (!isComplete) { isComplete = true; doComplete(); asyncResponse.completionCallbacks(t); ResteasyContext.removeContextDataLevel(); } }
@Override public void aroundRequest(HttpRequest req, RunnableWithException<IOException> continuation) throws IOException { BoundRequestContext cdiContext = CDI.current().select(BoundRequestContext.class).get(); Map<String,Object> contextMap = new HashMap<String,Object>(); cdiContext.associate(contextMap); cdiContext.activate(); try { // FIXME: associate CDI thread context on thread change, like Resteasy context? continuation.run(); }finally { if(req.getAsyncContext().isSuspended()) { req.getAsyncContext().getAsyncResponse().register((CompletionCallback)(t) -> { cdiContext.invalidate(); cdiContext.deactivate(); cdiContext.dissociate(contextMap); }); }else { cdiContext.invalidate(); cdiContext.deactivate(); cdiContext.dissociate(contextMap); } } } }
request.getAsyncContext().getAsyncResponse().completionCallbacks(ex); throw x; request.getAsyncContext().getAsyncResponse().resume(ex);
@Override public void close() { synchronized (lock) { closed = true; if (asyncContext.isSuspended()) { ResteasyAsynchronousResponse asyncResponse = asyncContext.getAsyncResponse(); if (asyncResponse != null) { asyncResponse.complete(); } } } }
request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
@Override public ResteasyAsynchronousResponse suspend(long time, TimeUnit unit) throws IllegalStateException { wasSuspended = true; asynchronousResponse = new SynchronousAsynchronousResponse(dispatcher, request, response); asynchronousResponse.setTimeout(time, unit); return asynchronousResponse; }
synchronized final public void complete(Throwable t) { if (!isComplete) { isComplete = true; doComplete(); asyncResponse.completionCallbacks(t); ResteasyProviderFactory.removeContextDataLevel(); } }
public void initializeAsync(ResteasyAsynchronousResponse asyncResponse) { asyncResponse.setAnnotations(method.getAnnotatedMethod().getAnnotations()); asyncResponse.setWriterInterceptors(writerInterceptors); asyncResponse.setResponseFilters(responseFilters); if (asyncResponse instanceof ResourceMethodInvokerAwareResponse) { ((ResourceMethodInvokerAwareResponse)asyncResponse).setMethod(this); } }
request.getAsyncContext().getAsyncResponse().completionCallbacks(ex); throw x; request.getAsyncContext().getAsyncResponse().resume(ex); return null; request.getAsyncContext().getAsyncResponse().resume(rtn); return null;
@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 void writeException(Throwable t) { /* * Here we cannot call AsyncResponse.resume(t) because that would invoke the response filters * and we should not invoke them because we're already in them. */ HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class); SynchronousDispatcher dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class); ResteasyAsynchronousResponse asyncResponse = request.getAsyncContext().getAsyncResponse(); RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request); tracingLogger.flush(httpResponse.getOutputHeaders()); dispatcher.unhandledAsynchronousException(httpResponse, t); onComplete.accept(t); asyncResponse.complete(); asyncResponse.completionCallbacks(t); }
protected void doComplete() { asyncResponse.complete(); }