Class RestApiServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.google.gerrit.httpd.restapi.RestApiServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
AccessRestApiServlet, AccountsRestApiServlet, ChangesRestApiServlet, ConfigRestApiServlet, GroupsRestApiServlet, ProjectsRestApiServlet

public class RestApiServlet extends javax.servlet.http.HttpServlet
See Also:
  • Field Details

    • X_GERRIT_DEADLINE

      public static final String X_GERRIT_DEADLINE
      See Also:
    • X_GERRIT_TRACE

      public static final String X_GERRIT_TRACE
      See Also:
    • X_GERRIT_UPDATED_REF

      public static final String X_GERRIT_UPDATED_REF
      See Also:
    • X_GERRIT_UPDATED_REF_ENABLED

      public static final String X_GERRIT_UPDATED_REF_ENABLED
      See Also:
    • XD_AUTHORIZATION

      public static final String XD_AUTHORIZATION
      See Also:
    • XD_CONTENT_TYPE

      public static final String XD_CONTENT_TYPE
      See Also:
    • XD_METHOD

      public static final String XD_METHOD
      See Also:
    • SC_UNPROCESSABLE_ENTITY

      public static final int SC_UNPROCESSABLE_ENTITY
      See Also:
    • SC_TOO_MANY_REQUESTS

      public static final int SC_TOO_MANY_REQUESTS
      See Also:
    • SC_CLIENT_CLOSED_REQUEST

      public static final int SC_CLIENT_CLOSED_REQUEST
      See Also:
    • JSON_MAGIC

      public static final byte[] JSON_MAGIC
      Garbage prefix inserted before JSON output to prevent XSSI.

      This prefix is ")]}'\n" and is designed to prevent a web browser from executing the response body if the resource URI were to be referenced using a <script src="...> HTML tag from another web site. Clients using the HTTP interface will need to always strip the first line of response data to remove this magic header.

  • Constructor Details

  • Method Details

    • service

      protected final void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOException
      Overrides:
      service in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      IOException
    • replyJson

      public static long replyJson(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean allowTracing, com.google.common.collect.ListMultimap<String,String> config, Object result) throws IOException
      Sets a JSON reply on the given HTTP servlet response.
      Parameters:
      req - the HTTP servlet request
      res - the HTTP servlet response on which the reply should be set
      allowTracing - whether it is allowed to log the reply if tracing is enabled, must not be set to true if the reply may contain sensitive data
      config - config parameters for the JSON formatting
      result - the object that should be formatted as JSON
      Returns:
      the length of the response
      Throws:
      IOException
    • replyError

      public static long replyError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int statusCode, String msg, Throwable err) throws IOException
      Throws:
      IOException
    • replyError

      public static long replyError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int statusCode, String msg, CacheControl cacheControl, Throwable err) throws IOException
      Throws:
      IOException