Class RestApiServlet

    • Field Detail

      • SC_UNPROCESSABLE_ENTITY

        public static final int SC_UNPROCESSABLE_ENTITY
        See Also:
        Constant Field Values
      • SC_CLIENT_CLOSED_REQUEST

        public static final int SC_CLIENT_CLOSED_REQUEST
        See Also:
        Constant Field Values
      • 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.

    • Method Detail

      • 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