Package com.google.gerrit.httpd.restapi
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RestApiServlet.Globals
-
Field Summary
Fields Modifier and Type Field Description static byte[]
JSON_MAGIC
Garbage prefix inserted before JSON output to prevent XSSI.static int
SC_CLIENT_CLOSED_REQUEST
static int
SC_TOO_MANY_REQUESTS
static int
SC_UNPROCESSABLE_ENTITY
static String
X_GERRIT_DEADLINE
static String
X_GERRIT_TRACE
static String
X_GERRIT_UPDATED_REF
static String
X_GERRIT_UPDATED_REF_ENABLED
static String
XD_AUTHORIZATION
static String
XD_CONTENT_TYPE
static String
XD_METHOD
-
Constructor Summary
Constructors Constructor Description RestApiServlet(RestApiServlet.Globals globals, RestCollection<? extends RestResource,? extends RestResource> members)
RestApiServlet(RestApiServlet.Globals globals, com.google.inject.Provider<? extends RestCollection<? extends RestResource,? extends RestResource>> members)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static long
replyError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int statusCode, String msg, CacheControl cacheControl, Throwable err)
static long
replyError(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int statusCode, String msg, Throwable err)
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)
Sets a JSON reply on the given HTTP servlet response.protected void
service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Field Detail
-
X_GERRIT_DEADLINE
public static final String X_GERRIT_DEADLINE
- See Also:
- Constant Field Values
-
X_GERRIT_TRACE
public static final String X_GERRIT_TRACE
- See Also:
- Constant Field Values
-
X_GERRIT_UPDATED_REF
public static final String X_GERRIT_UPDATED_REF
- See Also:
- Constant Field Values
-
X_GERRIT_UPDATED_REF_ENABLED
public static final String X_GERRIT_UPDATED_REF_ENABLED
- See Also:
- Constant Field Values
-
XD_AUTHORIZATION
public static final String XD_AUTHORIZATION
- See Also:
- Constant Field Values
-
XD_CONTENT_TYPE
public static final String XD_CONTENT_TYPE
- See Also:
- Constant Field Values
-
XD_METHOD
public static final String XD_METHOD
- See Also:
- Constant Field Values
-
SC_UNPROCESSABLE_ENTITY
public static final int SC_UNPROCESSABLE_ENTITY
- See Also:
- Constant Field Values
-
SC_TOO_MANY_REQUESTS
public static final int SC_TOO_MANY_REQUESTS
- 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.
-
-
Constructor Detail
-
RestApiServlet
public RestApiServlet(RestApiServlet.Globals globals, RestCollection<? extends RestResource,? extends RestResource> members)
-
RestApiServlet
public RestApiServlet(RestApiServlet.Globals globals, com.google.inject.Provider<? extends RestCollection<? extends RestResource,? extends RestResource>> members)
-
-
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 classjavax.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 requestres
- the HTTP servlet response on which the reply should be setallowTracing
- whether it is allowed to log the reply if tracing is enabled, must not be set totrue
if the reply may contain sensitive dataconfig
- config parameters for the JSON formattingresult
- 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
-
-