Package org.apache.hadoop.http
Class HttpServer2
java.lang.Object
org.apache.hadoop.http.HttpServer2
- All Implemented Interfaces:
FilterContainer
Create a Jetty embedded server to answer http requests. The primary goal is
to serve up status information for the server. There are three contexts:
"/logs/" -> points to the log directory "/static/" ->
points to common static files (src/webapps/static) "/" -> the
jsp server code from (src/webapps/<name>)
This class is a fork of the old HttpServer. HttpServer exists for
compatibility reasons. See HBASE-10336 for more details.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass to construct instances of HTTP server with specific options.static classA Servlet input filter that quotes all HTML active characters in the parameter names and values.static classA very simple servlet to serve up a text representation of the current stack traces.static enumThe X-FRAME-OPTIONS header in HTTP response to mitigate clickjacking attack. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected final booleanstatic final intstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final intstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final Stringstatic final booleanstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final org.slf4j.Loggerstatic final Stringprotected final Configuration.IntegerRangesprotected static final Stringstatic final Stringprotected final org.eclipse.jetty.webapp.WebAppContextprotected final org.eclipse.jetty.server.Server -
Method Summary
Modifier and TypeMethodDescriptionvoidaddContext(org.eclipse.jetty.servlet.ServletContextHandler ctxt, boolean isFiltered) protected voidaddDefaultApps(org.eclipse.jetty.server.handler.ContextHandlerCollection parent, String appDir, Configuration conf) Add default apps.protected voidaddDefaultServlets(Configuration configuration) Add default servlets.voidAdd a filter to the container.protected voidaddFilterPathMapping(String pathSpec, org.eclipse.jetty.servlet.ServletContextHandler webAppCtx) Add the path spec to the filter path mapping.voidAdd a global filter to the container.voidaddHandlerAtEnd(org.eclipse.jetty.server.Handler handler) Add the given handler to the end of the list of handlers.voidaddHandlerAtFront(org.eclipse.jetty.server.Handler handler) Add the given handler to the front of the list of handlers.voidaddInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz) Add an internal servlet in the server.voidaddInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz, boolean requireAuth) Add an internal servlet in the server, specifying whether or not to protect with Kerberos authentication.voidaddInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz, Map<String, String> params) Add an internal servlet in the server, with initialization parameters.voidaddJerseyResourceConfig(org.glassfish.jersey.server.ResourceConfig config, String pathSpec, Map<String, String> params) Add a Jersey resource config.voidaddJerseyResourcePackage(String packageName, String pathSpec) Add a Jersey resource package.voidAdd a Jersey resource package.voidaddServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz) Add a servlet in the server.static voiddefineFilter(org.eclipse.jetty.servlet.ServletContextHandler ctx, String name, String classname, Map<String, String> parameters, String[] urls) Define a filter for a context and set up default url mappings.getAttribute(String name) Get the value in the webapp context.getConnectorAddress(int index) Get the address that corresponds to a particular connector.static PropertiesgetFilterProperties(Configuration conf, List<String> prefixes) intgetPort()Deprecated.org.eclipse.jetty.webapp.WebAppContextprotected StringgetWebAppsPath(String appName) Get the pathname to the webapps files.static booleanhasAdministratorAccess(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Does the user sending the HttpServletRequest has the administrator ACLs?booleanisAlive()Test for the availability of the web serverstatic booleanisInstrumentationAccessAllowed(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Checks the user has privileges to access to instrumentation servlets.voidjoin()voidsetAttribute(String name, Object value) Set a value in the webapp context.voidsetThreads(int min, int max) Set the min, max number of worker threads (simultaneous connections).voidstart()Start the server.voidstop()stop the server.toString()static booleanuserHasAdministratorAccess(javax.servlet.ServletContext servletContext, String remoteUser) Get the admin ACLs from the given ServletContext and check if the given user is in the ACL.
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG -
HTTP_SCHEME
- See Also:
-
HTTPS_SCHEME
- See Also:
-
HTTP_MAX_REQUEST_HEADER_SIZE_KEY
- See Also:
-
HTTP_MAX_REQUEST_HEADER_SIZE_DEFAULT
public static final int HTTP_MAX_REQUEST_HEADER_SIZE_DEFAULT- See Also:
-
HTTP_MAX_RESPONSE_HEADER_SIZE_KEY
- See Also:
-
HTTP_MAX_RESPONSE_HEADER_SIZE_DEFAULT
public static final int HTTP_MAX_RESPONSE_HEADER_SIZE_DEFAULT- See Also:
-
HTTP_SOCKET_BACKLOG_SIZE_KEY
- See Also:
-
HTTP_SOCKET_BACKLOG_SIZE_DEFAULT
public static final int HTTP_SOCKET_BACKLOG_SIZE_DEFAULT- See Also:
-
HTTP_MAX_THREADS_KEY
- See Also:
-
HTTP_ACCEPTOR_COUNT_KEY
- See Also:
-
HTTP_ACCEPTOR_COUNT_DEFAULT
public static final int HTTP_ACCEPTOR_COUNT_DEFAULT- See Also:
-
HTTP_SELECTOR_COUNT_KEY
- See Also:
-
HTTP_SELECTOR_COUNT_DEFAULT
public static final int HTTP_SELECTOR_COUNT_DEFAULT- See Also:
-
HTTP_IDLE_TIMEOUT_MS_KEY
- See Also:
-
HTTP_IDLE_TIMEOUT_MS_DEFAULT
public static final int HTTP_IDLE_TIMEOUT_MS_DEFAULT- See Also:
-
HTTP_TEMP_DIR_KEY
- See Also:
-
FILTER_INITIALIZER_PROPERTY
- See Also:
-
HTTP_SNI_HOST_CHECK_ENABLED_KEY
- See Also:
-
HTTP_SNI_HOST_CHECK_ENABLED_DEFAULT
public static final boolean HTTP_SNI_HOST_CHECK_ENABLED_DEFAULT- See Also:
-
CONF_CONTEXT_ATTRIBUTE
- See Also:
-
ADMINS_ACL
- See Also:
-
SPNEGO_FILTER
- See Also:
-
NO_CACHE_FILTER
- See Also:
-
BIND_ADDRESS
- See Also:
-
webServer
protected final org.eclipse.jetty.server.Server webServer -
webAppContext
protected final org.eclipse.jetty.webapp.WebAppContext webAppContext -
findPort
protected final boolean findPort -
portRanges
-
filterNames
-
HTTP_HEADER_PREFIX
- See Also:
-
PROMETHEUS_SINK
- See Also:
-
-
Method Details
-
getFilterProperties
-
addDefaultApps
protected void addDefaultApps(org.eclipse.jetty.server.handler.ContextHandlerCollection parent, String appDir, Configuration conf) throws IOException Add default apps.- Parameters:
parent- contexthandlercollection.appDir- The application directoryconf- configuration.- Throws:
IOException- raised on errors performing I/O.
-
addDefaultServlets
Add default servlets.- Parameters:
configuration- the hadoop configuration
-
addContext
public void addContext(org.eclipse.jetty.servlet.ServletContextHandler ctxt, boolean isFiltered) -
setAttribute
Set a value in the webapp context. These values are available to the jsp pages as "application.getAttribute(name)".- Parameters:
name- The name of the attributevalue- The value of the attribute
-
addJerseyResourcePackage
Add a Jersey resource package.- Parameters:
packageName- The Java package name containing the Jersey resource.pathSpec- The path spec for the servlet
-
addJerseyResourcePackage
public void addJerseyResourcePackage(String packageName, String pathSpec, Map<String, String> params) Add a Jersey resource package.- Parameters:
packageName- The Java package name containing the Jersey resource.pathSpec- The path spec for the servletparams- properties and features for ResourceConfig
-
addJerseyResourceConfig
public void addJerseyResourceConfig(org.glassfish.jersey.server.ResourceConfig config, String pathSpec, Map<String, String> params) Add a Jersey resource config.- Parameters:
config- The Jersey ResourceConfig to be registered.pathSpec- The path spec for the servletparams- properties and features for ResourceConfig
-
addServlet
public void addServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz) Add a servlet in the server.- Parameters:
name- The name of the servlet (can be passed as null)pathSpec- The path spec for the servletclazz- The servlet class
-
addInternalServlet
public void addInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz) Add an internal servlet in the server. Note: This method is to be used for adding servlets that facilitate internal communication and not for user facing functionality. For servlets added using this method, filters are not enabled.- Parameters:
name- The name of the servlet (can be passed as null)pathSpec- The path spec for the servletclazz- The servlet class
-
addInternalServlet
public void addInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz, boolean requireAuth) Add an internal servlet in the server, specifying whether or not to protect with Kerberos authentication. Note: This method is to be used for adding servlets that facilitate internal communication and not for user facing functionality. For servlets added using this method, filters (except internal Kerberos filters) are not enabled.- Parameters:
name- The name of the servlet (can be passed as null)pathSpec- The path spec for the servletclazz- The servlet classrequireAuth- Require Kerberos authenticate to access servlet
-
addInternalServlet
public void addInternalServlet(String name, String pathSpec, Class<? extends javax.servlet.http.HttpServlet> clazz, Map<String, String> params) Add an internal servlet in the server, with initialization parameters. Note: This method is to be used for adding servlets that facilitate internal communication and not for user facing functionality. For servlets added using this method, filters (except internal Kerberos filters) are not enabled.- Parameters:
name- The name of the servlet (can be passed as null)pathSpec- The path spec for the servletclazz- The servlet classparams- init parameters
-
addHandlerAtFront
public void addHandlerAtFront(org.eclipse.jetty.server.Handler handler) Add the given handler to the front of the list of handlers.- Parameters:
handler- The handler to add
-
addHandlerAtEnd
public void addHandlerAtEnd(org.eclipse.jetty.server.Handler handler) Add the given handler to the end of the list of handlers.- Parameters:
handler- The handler to add
-
addFilter
Description copied from interface:FilterContainerAdd a filter to the container.- Specified by:
addFilterin interfaceFilterContainer- Parameters:
name- Filter nameclassname- Filter class nameparameters- a map from parameter names to initial values
-
addGlobalFilter
Description copied from interface:FilterContainerAdd a global filter to the container.- Specified by:
addGlobalFilterin interfaceFilterContainer- Parameters:
name- filter nameclassname- filter class nameparameters- a map from parameter names to initial values
-
defineFilter
public static void defineFilter(org.eclipse.jetty.servlet.ServletContextHandler ctx, String name, String classname, Map<String, String> parameters, String[] urls) Define a filter for a context and set up default url mappings.- Parameters:
ctx- ctx.name- name.classname- classname.parameters- parameters.urls- urls.
-
addFilterPathMapping
protected void addFilterPathMapping(String pathSpec, org.eclipse.jetty.servlet.ServletContextHandler webAppCtx) Add the path spec to the filter path mapping.- Parameters:
pathSpec- The path specwebAppCtx- The WebApplicationContext to add to
-
getAttribute
Get the value in the webapp context.- Parameters:
name- The name of the attribute- Returns:
- The value of the attribute
-
getWebAppContext
public org.eclipse.jetty.webapp.WebAppContext getWebAppContext() -
getWebAppsPath
Get the pathname to the webapps files.- Parameters:
appName- eg "secondary" or "datanode"- Returns:
- the pathname as a URL
- Throws:
FileNotFoundException- if 'webapps' directory cannot be found on CLASSPATH or in the development location.
-
getPort
Deprecated.Get the port that the server is on- Returns:
- the port
-
getConnectorAddress
Get the address that corresponds to a particular connector.- Parameters:
index- index.- Returns:
- the corresponding address for the connector, or null if there's no such connector or the connector is not bounded or was closed.
-
setThreads
public void setThreads(int min, int max) Set the min, max number of worker threads (simultaneous connections).- Parameters:
min- min.max- max.
-
start
Start the server. Does not wait for the server to start.- Throws:
IOException- raised on errors performing I/O.
-
stop
stop the server.- Throws:
Exception- exception.
-
join
- Throws:
InterruptedException
-
isAlive
public boolean isAlive()Test for the availability of the web server- Returns:
- true if the web server is started, false otherwise
-
toString
-
isInstrumentationAccessAllowed
public static boolean isInstrumentationAccessAllowed(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException Checks the user has privileges to access to instrumentation servlets.If
hadoop.security.instrumentation.requires.adminis set to FALSE (default value) it always returns TRUE.If
hadoop.security.instrumentation.requires.adminis set to TRUE it will check that if the current user is in the admin ACLS. If the user is in the admin ACLs it returns TRUE, otherwise it returns FALSE.- Parameters:
servletContext- the servlet context.request- the servlet request.response- the servlet response.- Returns:
- TRUE/FALSE based on the logic decribed above.
- Throws:
IOException- raised on errors performing I/O.
-
hasAdministratorAccess
public static boolean hasAdministratorAccess(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException Does the user sending the HttpServletRequest has the administrator ACLs? If it isn't the case, response will be modified to send an error to the user.- Parameters:
servletContext- servletContext.request- request.response- used to send the error response if user does not have admin access.- Returns:
- true if admin-authorized, false otherwise
- Throws:
IOException- raised on errors performing I/O.
-
userHasAdministratorAccess
public static boolean userHasAdministratorAccess(javax.servlet.ServletContext servletContext, String remoteUser) Get the admin ACLs from the given ServletContext and check if the given user is in the ACL.- Parameters:
servletContext- the context containing the admin ACL.remoteUser- the remote user to check for.- Returns:
- true if the user is present in the ACL, false if no ACL is set or the user is not present
-