public class RequestServer
extends javax.servlet.http.HttpServlet
Request routing is done by searching a list of registered handlers, in order of registration, for a handler whose path regex matches the request URI and whose HTTP method (GET, POST, DELETE...) matches the request's method. If none is found an HTTP 404 is returned.
A Handler class is parametrized by the kind of Schema that it accepts for request handling, as well as the internal implementation class (Iced class) that the Schema translates from and to. Handler methods are allowed to return other Schema types than in the type parameter if that makes sense for a given request. For example, a prediction (scoring) call on a Model might return a Frame schema.
When an HTTP request is accepted the framework does the following steps:
Handler
,
RegisterV3Api
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
RequestServer.DummyRestApiContext
Dummy Rest API context which is redirecting calls to static method API.
|
static interface |
RequestServer.HttpLogFilter
Create a new HttpLogFilter.
|
static class |
RequestServer.LogFilterLevel |
Modifier and Type | Field and Description |
---|---|
static int |
H2O_REST_API_VERSION |
static java.lang.String |
HTTP_ACCEPTED
Some HTTP response status codes
|
static java.lang.String |
HTTP_BAD_METHOD
Some HTTP response status codes
|
static java.lang.String |
HTTP_BAD_REQUEST
Some HTTP response status codes
|
static java.lang.String |
HTTP_CREATED
Some HTTP response status codes
|
static java.lang.String |
HTTP_FORBIDDEN
Some HTTP response status codes
|
static java.lang.String |
HTTP_INTERNAL_ERROR
Some HTTP response status codes
|
static java.lang.String |
HTTP_NO_CONTENT
Some HTTP response status codes
|
static java.lang.String |
HTTP_NOT_FOUND
Some HTTP response status codes
|
static java.lang.String |
HTTP_NOT_IMPLEMENTED
Some HTTP response status codes
|
static java.lang.String |
HTTP_NOT_MODIFIED
Some HTTP response status codes
|
static java.lang.String |
HTTP_OK
Some HTTP response status codes
|
static java.lang.String |
HTTP_PARTIAL_CONTENT
Some HTTP response status codes
|
static java.lang.String |
HTTP_PRECONDITION_FAILED
Some HTTP response status codes
|
static java.lang.String |
HTTP_RANGE_NOT_SATISFIABLE
Some HTTP response status codes
|
static java.lang.String |
HTTP_REDIRECT
Some HTTP response status codes
|
static java.lang.String |
HTTP_SERVICE_NOT_AVAILABLE
Some HTTP response status codes
|
static java.lang.String |
HTTP_TEAPOT
Some HTTP response status codes
|
static java.lang.String |
HTTP_THROTTLE
Some HTTP response status codes
|
static java.lang.String |
HTTP_TOO_LONG_REQUEST
Some HTTP response status codes
|
static java.lang.String |
HTTP_UNAUTHORIZED
Some HTTP response status codes
|
static java.lang.String |
MIME_CSS
Common mime types for dynamic content
|
static java.lang.String |
MIME_DEFAULT_BINARY
Common mime types for dynamic content
|
static java.lang.String |
MIME_GIF
Common mime types for dynamic content
|
static java.lang.String |
MIME_HTML
Common mime types for dynamic content
|
static java.lang.String |
MIME_JPEG
Common mime types for dynamic content
|
static java.lang.String |
MIME_JS
Common mime types for dynamic content
|
static java.lang.String |
MIME_JSON
Common mime types for dynamic content
|
static java.lang.String |
MIME_PLAINTEXT
Common mime types for dynamic content
|
static java.lang.String |
MIME_PNG
Common mime types for dynamic content
|
static java.lang.String |
MIME_SVG
Common mime types for dynamic content
|
static java.lang.String |
MIME_WOFF
Common mime types for dynamic content
|
static java.lang.String |
MIME_XML
Common mime types for dynamic content
|
Constructor and Description |
---|
RequestServer() |
Modifier and Type | Method and Description |
---|---|
static RequestServer.HttpLogFilter |
defaultFilter()
Provide the default filters for H2O's HTTP logging.
|
protected void |
doDelete(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
void |
doGeneric(java.lang.String method,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Top-level dispatch handling
|
protected void |
doGet(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
protected void |
doHead(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
protected void |
doOptions(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
protected void |
doPost(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
protected void |
doPut(javax.servlet.http.HttpServletRequest rq,
javax.servlet.http.HttpServletResponse rs) |
protected void |
doTrace(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
static Route |
lookupRoute(RequestUri uri) |
static int |
numRoutes() |
static int |
numRoutes(int version)
Calculates number of routes having the specified version.
|
static Route |
registerEndpoint(java.lang.String method_uri,
java.lang.Class<? extends RestApiHandler> handler_clz)
Register an HTTP request handler for the given URL pattern.
|
static Route |
registerEndpoint(java.lang.String api_name,
java.lang.String method_uri,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String summary)
Register an HTTP request handler method for a given URL pattern, with parameters extracted from the URI.
|
static Route |
registerEndpoint(java.lang.String api_name,
java.lang.String http_method,
java.lang.String url,
java.lang.Class<? extends Handler> handler_class,
java.lang.String handler_method,
java.lang.String summary,
HandlerFactory handler_factory) |
static java.util.ArrayList<Route> |
routes() |
static NanoResponse |
serve(java.lang.String url,
java.lang.String method,
java.util.Properties header,
java.util.Properties parms,
java.lang.String post_body)
Subsequent handling of the dispatch
|
static void |
setFilters(RequestServer.HttpLogFilter... filters) |
public static final int H2O_REST_API_VERSION
public static final java.lang.String HTTP_OK
public static final java.lang.String HTTP_CREATED
public static final java.lang.String HTTP_ACCEPTED
public static final java.lang.String HTTP_NO_CONTENT
public static final java.lang.String HTTP_PARTIAL_CONTENT
public static final java.lang.String HTTP_REDIRECT
public static final java.lang.String HTTP_NOT_MODIFIED
public static final java.lang.String HTTP_BAD_REQUEST
public static final java.lang.String HTTP_UNAUTHORIZED
public static final java.lang.String HTTP_FORBIDDEN
public static final java.lang.String HTTP_NOT_FOUND
public static final java.lang.String HTTP_BAD_METHOD
public static final java.lang.String HTTP_PRECONDITION_FAILED
public static final java.lang.String HTTP_TOO_LONG_REQUEST
public static final java.lang.String HTTP_RANGE_NOT_SATISFIABLE
public static final java.lang.String HTTP_TEAPOT
public static final java.lang.String HTTP_THROTTLE
public static final java.lang.String HTTP_INTERNAL_ERROR
public static final java.lang.String HTTP_NOT_IMPLEMENTED
public static final java.lang.String HTTP_SERVICE_NOT_AVAILABLE
public static final java.lang.String MIME_PLAINTEXT
public static final java.lang.String MIME_HTML
public static final java.lang.String MIME_CSS
public static final java.lang.String MIME_JSON
public static final java.lang.String MIME_JS
public static final java.lang.String MIME_JPEG
public static final java.lang.String MIME_PNG
public static final java.lang.String MIME_SVG
public static final java.lang.String MIME_GIF
public static final java.lang.String MIME_WOFF
public static final java.lang.String MIME_DEFAULT_BINARY
public static final java.lang.String MIME_XML
public static int numRoutes()
public static java.util.ArrayList<Route> routes()
public static Route lookupRoute(RequestUri uri)
public static void setFilters(RequestServer.HttpLogFilter... filters)
public static int numRoutes(int version)
public static Route registerEndpoint(java.lang.String api_name, java.lang.String method_uri, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String summary)
URIs which match this pattern will have their parameters collected from the path and from the query params
api_name
- suggested method name for this endpoint in the external API library. These names should be
unique. If null, the api_name will be created from the class name and the handler method name.method_uri
- combined method / url pattern of the request, e.g.: "GET /3/Jobs/{job_id}"handler_class
- class which contains the handler methodhandler_method
- name of the handler methodsummary
- help string which explains the functionality of this endpointRoute
,
RequestServer
public static Route registerEndpoint(java.lang.String api_name, java.lang.String http_method, java.lang.String url, java.lang.Class<? extends Handler> handler_class, java.lang.String handler_method, java.lang.String summary, HandlerFactory handler_factory)
api_name
- suggested method name for this endpoint in the external API library. These names should be
unique. If null, the api_name will be created from the class name and the handler method name.http_method
- HTTP verb (GET, POST, DELETE) this handler will accepturl
- url path, possibly containing placeholders in curly braces, e.g: "/3/DKV/{key}"handler_class
- class which contains the handler methodhandler_method
- name of the handler methodsummary
- help string which explains the functionality of this endpointhandler_factory
- factory to create instance of handler (used by Sparkling Water)public static Route registerEndpoint(java.lang.String method_uri, java.lang.Class<? extends RestApiHandler> handler_clz)
method_uri
- combined method/url pattern of the endpoint, for
example: "GET /3/Jobs/{job_id}"
handler_clz
- class of the handler (should inherit from
RestApiHandler
).protected void doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
doTrace
in class javax.servlet.http.HttpServlet
protected void doGet(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doGet
in class javax.servlet.http.HttpServlet
protected void doPut(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doPut
in class javax.servlet.http.HttpServlet
protected void doPost(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doPost
in class javax.servlet.http.HttpServlet
protected void doHead(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doHead
in class javax.servlet.http.HttpServlet
protected void doDelete(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doDelete
in class javax.servlet.http.HttpServlet
protected void doOptions(javax.servlet.http.HttpServletRequest rq, javax.servlet.http.HttpServletResponse rs)
doOptions
in class javax.servlet.http.HttpServlet
public void doGeneric(java.lang.String method, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
public static NanoResponse serve(java.lang.String url, java.lang.String method, java.util.Properties header, java.util.Properties parms, java.lang.String post_body)
public static RequestServer.HttpLogFilter defaultFilter()