JettyUtils
JettyUtils is a set of utility methods for creating Jetty HTTP Server-specific components.
| Name | Description |
|---|---|
|
Creates an HttpServlet |
|
|
Creates a Handler for a static content |
|
|
Creates a ServletContextHandler for a path |
|
Creating ServletContextHandler for Path — createServletHandler Method
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
createServletHandler( path: String, servlet: HttpServlet, basePath: String): ServletContextHandler (1) createServletHandler[T <: AnyRef]( path: String, servletParams: ServletParams[T], securityMgr: SecurityManager, conf: SparkConf, basePath: String = ""): ServletContextHandler (2) |
-
Calls the first three-argument
createServletHandlerwith
createServletHandler…FIXME
|
Note
|
|
Creating HttpServlet — createServlet Method
|
1 2 3 4 5 6 7 8 |
createServlet[T <: AnyRef]( servletParams: ServletParams[T], securityMgr: SecurityManager, conf: SparkConf): HttpServlet |
createServlet creates the X-Frame-Options header that can be either ALLOW-FROM with the value of spark.ui.allowFramingFrom configuration property if defined or SAMEORIGIN.
createServlet creates a Java Servlets HttpServlet with support for GET requests.
When handling GET requests, the HttpServlet first checks view permissions of the remote user (by requesting the SecurityManager to checkUIViewPermissions of the remote user).
|
Tip
|
Enable Add the following line to
You should see the following DEBUG message in the logs:
|
With view permissions check passed, the HttpServlet sends a response with the following:
In case the view permissions didn’t allow to view the page, the HttpServlet sends an error response with the following:
-
Status
403 -
Cache-Controlheader with “no-cache, no-store, must-revalidate” -
Error message: “User is not authorized to access this page.”
|
Note
|
createServlet is used exclusively when JettyUtils is requested to createServletHandler.
|
Creating Handler For Static Content — createStaticHandler Method
|
1 2 3 4 5 |
createStaticHandler(resourceBase: String, path: String): ServletContextHandler |
createStaticHandler creates a handler for serving files from a static directory
Internally, createStaticHandler creates a Jetty ServletContextHandler and sets org.eclipse.jetty.servlet.Default.gzip init parameter to false.
createRedirectHandler creates a Jetty DefaultServlet.
|
Note
|
Quoting the official documentation of Jetty’s DefaultServlet:
With that,
|
createRedirectHandler resolves the resourceBase in the Spark classloader and, if successful, sets resourceBase init parameter of the Jetty DefaultServlet to the URL.
|
Note
|
resourceBase init parameter is used to replace the context resource base. |
createRedirectHandler requests the ServletContextHandler to use the path as the context path and register the DefaultServlet to serve it.
createRedirectHandler throws an Exception if the input resourceBase could not be resolved.
|
1 2 3 4 5 |
Could not find resource path for Web UI: [resourceBase] |
|
Note
|
createStaticHandler is used when SparkUI, HistoryServer, Spark Standalone’s MasterWebUI and WorkerWebUI, Spark on Mesos’ MesosClusterUI are requested to initialize.
|
createRedirectHandler Method
|
1 2 3 4 5 6 7 8 9 10 |
createRedirectHandler( srcPath: String, destPath: String, beforeRedirect: HttpServletRequest => Unit = x => (), basePath: String = "", httpMethods: Set[String] = Set("GET")): ServletContextHandler |
createRedirectHandler…FIXME
|
Note
|
createRedirectHandler is used when SparkUI and Spark Standalone’s MasterWebUI are requested to initialize.
|
spark技术分享