public void doFilter()

in src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java [108:176]


  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
      chain.doFilter(request, response);
      return;
    }

    HttpServletResponse httpResponse = (HttpServletResponse) response;
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    try {
      if (isFetchAction(httpRequest)) {
        if (userProvider.get().isIdentifiedUser()) {
          writeResponse(httpResponse, doFetch(httpRequest));
        } else {
          httpResponse.sendError(SC_UNAUTHORIZED);
        }
      } else if (isApplyObjectAction(httpRequest)) {
        if (userProvider.get().isIdentifiedUser()) {
          writeResponse(httpResponse, doApplyObject(httpRequest));
        } else {
          httpResponse.sendError(SC_UNAUTHORIZED);
        }
      } else if (isInitProjectAction(httpRequest)) {
        if (userProvider.get().isIdentifiedUser()) {
          if (!checkAcceptHeader(httpRequest, httpResponse)) {
            return;
          }
          doInitProject(httpRequest, httpResponse);
        } else {
          httpResponse.sendError(SC_UNAUTHORIZED);
        }
      } else if (isUpdateHEADAction(httpRequest)) {
        if (userProvider.get().isIdentifiedUser()) {
          writeResponse(httpResponse, doUpdateHEAD(httpRequest));
        } else {
          httpResponse.sendError(SC_UNAUTHORIZED);
        }
      } else if (isDeleteProjectAction(httpRequest)) {
        if (userProvider.get().isIdentifiedUser()) {
          writeResponse(httpResponse, doDeleteProject(httpRequest));
        } else {
          httpResponse.sendError(SC_UNAUTHORIZED);
        }
      } else {
        chain.doFilter(request, response);
      }

    } catch (AuthException e) {
      RestApiServlet.replyError(
          httpRequest, httpResponse, SC_FORBIDDEN, e.getMessage(), e.caching(), e);
    } catch (MalformedJsonException | JsonParseException e) {
      logger.atFine().withCause(e).log("REST call failed on JSON parsing");
      RestApiServlet.replyError(
          httpRequest, httpResponse, SC_BAD_REQUEST, "Invalid json in request", e);
    } catch (BadRequestException e) {
      RestApiServlet.replyError(httpRequest, httpResponse, SC_BAD_REQUEST, e.getMessage(), e);
    } catch (UnprocessableEntityException e) {
      RestApiServlet.replyError(
          httpRequest, httpResponse, SC_UNPROCESSABLE_ENTITY, e.getMessage(), e.caching(), e);
    } catch (ResourceConflictException e) {
      RestApiServlet.replyError(
          httpRequest, httpResponse, SC_CONFLICT, e.getMessage(), e.caching(), e);
    } catch (InitProjectException | ResourceNotFoundException e) {
      RestApiServlet.replyError(
          httpRequest, httpResponse, SC_INTERNAL_SERVER_ERROR, e.getMessage(), e.caching(), e);
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }