コード例 #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
  protected void handleFailure(HttpRequest request, HttpResponse response, Failure failure) {
    if (failure.isLoggable())
      logger.error(
          "Failed executing " + request.getHttpMethod() + " " + request.getUri().getPath(),
          failure);
    else
      logger.debug(
          "Failed executing " + request.getHttpMethod() + " " + request.getUri().getPath(),
          failure);

    if (failure.getResponse() != null) {
      writeFailure(request, response, failure.getResponse());
    } else {
      try {
        if (failure.getMessage() != null) {
          response.sendError(failure.getErrorCode(), failure.getMessage());
        } else {
          response.sendError(failure.getErrorCode());
        }
      } catch (IOException e1) {
        throw new UnhandledException(e1);
      }
    }
  }