Ejemplo n.º 1
0
  /**
   * Handle a request.
   *
   * @param target The target of the request - either a URI or a name.
   * @param baseRequest The original unwrapped request object.
   * @param request The request either as the {@link Request} object or a wrapper of that request.
   * @param response The response as the {@link org.eclipse.jetty.server.Response} object or a
   *     wrapper of that request.
   * @throws IOException in case of IO error.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void handle(
      String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    if (baseRequest.isHandled()) {
      return;
    }
    Route route = findRoute(request.getMethod(), request.getPathInfo());
    if (route == null) {
      return;
    }

    Object param = getRouteParam(request, route);
    try {
      beginTransaction();
      Response<?> handlerResponse =
          route.handle(param, new RouteParameters(route.getRouteParams(request.getPathInfo())));
      commitTransaction();
      writeHttpResponse(request, response, handlerResponse);
    } catch (HttpErrorException httpError) {
      commitTransaction();
      writeHttpError(response, httpError);
    } catch (Exception exception) {
      rollBackTransaction();
      writeInternalError(response, exception);
    }
    baseRequest.setHandled(true);
  }
Ejemplo n.º 2
0
  public Response handleRequest(Request request, RequestBody requestBody) {
    for (Route route : routes) {
      Response response = route.handle(request);
      if (!response.equals(Response.CONTINUE)) {
        return response;
      }
    }

    return defaultHandler.handle(request);
  }
Ejemplo n.º 3
0
  public Response handleRequest(Request request) {
    for (Route route : routes) {
      Response response = route.handle(request);
      if (response.equals(Response.BODY_REQUIRED) || !response.equals(Response.CONTINUE)) {
        return response;
      }
    }

    return defaultHandler.handle(request);
  }