Пример #1
0
 public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
   ResteasyRequestWrapper requestWrapper =
       RequestUtil.getRequestWrapper(request, request.getMethod(), prefix);
   try {
     // NOTE: if invoker isn't found, RESTEasy throw NoReourceFoundFailure
     HttpRequest httpRequest = requestWrapper.getHttpRequest();
     if (!httpRequest.isInitial()) {
       String message =
           httpRequest.getUri().getPath()
               + " is not initial request.  Its suspended and retried.  Aborting.";
       logger.error(message);
       requestWrapper.setError(500, message);
     } else {
       Response response = dispatcher.preprocess(httpRequest);
       if (response != null) {
         requestWrapper.setAbortedResponse(response);
       } else {
         requestWrapper.setInvoker(getInvoker(httpRequest));
       }
     }
     return new HandlerExecutionChain(requestWrapper, interceptors);
   } catch (NotFoundException e) {
     if (throwNotFound) {
       throw e;
     }
     logger.error("Resource Not Found: " + e.getMessage(), e);
   } catch (Failure e) {
     logger.error("ResourceFailure: " + e.getMessage(), e);
     throw e;
   }
   return null;
 }
Пример #2
0
  public void service(
      ChannelHandlerContext ctx, HttpRequest request, HttpResponse response, boolean handleNotFound)
      throws IOException {

    try {
      ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
      if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) {
        ThreadLocalResteasyProviderFactory.push(providerFactory);
      }

      SecurityContext securityContext;
      if (domain != null) {
        securityContext = basicAuthentication(request, response);
        if (securityContext == null) // not authenticated
        {
          return;
        }
      } else {
        securityContext = new NettySecurityContext();
      }
      try {

        ResteasyProviderFactory.pushContext(ChannelHandlerContext.class, ctx);
        ResteasyProviderFactory.pushContext(SecurityContext.class, securityContext);
        if (handleNotFound) {
          dispatcher.invoke(request, response);
        } else {
          dispatcher.invokePropagateNotFound(request, response);
        }
      } finally {
        ResteasyProviderFactory.clearContextData();
      }
    } finally {
      ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
      if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) {
        ThreadLocalResteasyProviderFactory.pop();
      }
    }
  }
Пример #3
0
 private ResourceInvoker getInvoker(HttpRequest httpRequest) {
   if (dispatcher != null) return dispatcher.getInvoker(httpRequest);
   return null;
 }