org.jboss.resteasy.spi.HttpRequest.getAsyncContext()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.jboss.resteasy.spi.HttpRequest.getAsyncContext()方法的一些代码示例,展示了HttpRequest.getAsyncContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getAsyncContext()方法的具体详情如下:
包路径:org.jboss.resteasy.spi.HttpRequest
类名称:HttpRequest
方法名:getAsyncContext

HttpRequest.getAsyncContext介绍

暂无

代码示例

代码示例来源:origin: resteasy/Resteasy

@Override
public ResteasyAsynchronousContext getAsyncContext()
{
 return delegate.getAsyncContext();
}

代码示例来源:origin: resteasy/Resteasy

public AsyncResponseConsumer(final ResourceMethodInvoker method)
{
 this.method = method;
 contextDataMap = ResteasyContext.getContextDataMap();
 dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class);
 HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class);
 if(httpRequest.getAsyncContext().isSuspended())
   asyncResponse = httpRequest.getAsyncContext().getAsyncResponse();
 else
   asyncResponse = httpRequest.getAsyncContext().suspend();
}

代码示例来源:origin: resteasy/Resteasy

@Override
  public CompletionStage<Object> inject(HttpRequest request, HttpResponse response, boolean unwrapAsync)
  {
   ResteasyAsynchronousResponse asynchronousResponse = null;
   if (timeout == -1)
   {
     asynchronousResponse = request.getAsyncContext().suspend();
   }
   else
   {
     asynchronousResponse = request.getAsyncContext().suspend(timeout, unit);
   }
   ResourceMethodInvoker invoker =  (ResourceMethodInvoker)request.getAttribute(ResourceMethodInvoker.class.getName());
   invoker.initializeAsync(asynchronousResponse);

   return CompletableFuture.completedFuture(asynchronousResponse);
  }
}

代码示例来源:origin: resteasy/Resteasy

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

代码示例来源:origin: resteasy/Resteasy

public void pushContextObjects(final HttpRequest request, final HttpResponse response)
{
 Map contextDataMap = ResteasyContext.getContextDataMap();
 contextDataMap.put(HttpRequest.class, request);
 contextDataMap.put(HttpResponse.class, response);
 contextDataMap.put(HttpHeaders.class, request.getHttpHeaders());
 contextDataMap.put(UriInfo.class, request.getUri());
 contextDataMap.put(Request.class, new RequestImpl(request, response));
 contextDataMap.put(ResteasyAsynchronousContext.class, request.getAsyncContext());
 ResourceContext resourceContext = new ResourceContext()
 {
   @Override
   public <T> T getResource(Class<T> resourceClass)
   {
    return providerFactory.injectedInstance(resourceClass, request, response);
   }
   @Override
   public <T> T initResource(T resource)
   {
    providerFactory.injectProperties(resource, request, response);
    return resource;
   }
 };
 contextDataMap.put(ResourceContext.class, resourceContext);
 contextDataMap.putAll(defaultContextObjects);
 contextDataMap.put(Cleanables.class, new Cleanables());
 contextDataMap.put(PostResourceMethodInvokers.class, new PostResourceMethodInvokers());
}

代码示例来源:origin: resteasy/Resteasy

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

代码示例来源:origin: resteasy/Resteasy

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

代码示例来源:origin: resteasy/Resteasy

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

代码示例来源:origin: resteasy/Resteasy

request.getAsyncContext().getAsyncResponse().completionCallbacks(ex);
   throw x;
else if (request.getAsyncContext().isSuspended())
   request.getAsyncContext().getAsyncResponse().resume(ex);

代码示例来源:origin: resteasy/Resteasy

public SseEventOutputImpl(final MessageBodyWriter<OutboundSseEvent> writer)
{
 this.writer = writer;
 contextDataMap = ResteasyContext.getContextDataMap();
 request = ResteasyContext.getContextData(org.jboss.resteasy.spi.HttpRequest.class);
 asyncContext = request.getAsyncContext();
 if (!asyncContext.isSuspended())
 {
   try
   {
    asyncContext.suspend();
   }
   catch (IllegalStateException ex)
   {
    LogMessages.LOGGER.failedToSetRequestAsync();
   }
 }
 response = ResteasyContext.getContextData(HttpResponse.class);
}

代码示例来源:origin: resteasy/Resteasy

return null;
if (request.getAsyncContext().isSuspended())
  initializeAsync(request.getAsyncContext().getAsyncResponse());
  request.getAsyncContext().getAsyncResponse().resume(rtn);
  return null;

代码示例来源:origin: resteasy/Resteasy

if(!httpRequest.getAsyncContext().isSuspended())
  httpRequest.getAsyncContext().suspend();
else
  httpRequest.getAsyncContext().getAsyncResponse().resume(serverResponse);
  return null;

代码示例来源:origin: resteasy/Resteasy

if (request.getAsyncContext().isSuspended())
 request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();

代码示例来源:origin: org.jboss.resteasy/resteasy-jaxrs-20

@Override
public ResteasyAsynchronousContext getAsyncContext()
{
 return delegate.getAsyncContext();
}

代码示例来源:origin: org.jboss.resteasy/resteasy-core

@Override
public ResteasyAsynchronousContext getAsyncContext()
{
 return delegate.getAsyncContext();
}

代码示例来源:origin: resteasy/Resteasy

if(!request.getAsyncContext().isSuspended())
  request.getAsyncContext().suspend();
  weSuspended = true;

代码示例来源:origin: resteasy/Resteasy

if (request.getAsyncContext().isSuspended())
 request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();

代码示例来源:origin: org.jboss.resteasy/resteasy-core

public AsyncResponseConsumer(final ResourceMethodInvoker method)
{
 this.method = method;
 contextDataMap = ResteasyContext.getContextDataMap();
 dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class);
 HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class);
 if(httpRequest.getAsyncContext().isSuspended())
   asyncResponse = httpRequest.getAsyncContext().getAsyncResponse();
 else
   asyncResponse = httpRequest.getAsyncContext().suspend();
}

代码示例来源:origin: org.jboss.resteasy/resteasy-jaxrs-20

public AsyncResponseConsumer(ResourceMethodInvoker method)
{
 this.method = method;
 contextDataMap = ResteasyProviderFactory.getContextDataMap();
 dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class);
 HttpRequest httpRequest = (HttpRequest) contextDataMap.get(HttpRequest.class);
 if(httpRequest.getAsyncContext().isSuspended())
   asyncResponse = httpRequest.getAsyncContext().getAsyncResponse();
 else
   asyncResponse = httpRequest.getAsyncContext().suspend();
}

代码示例来源:origin: org.jboss.resteasy/resteasy-core

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

相关文章