Class HttpServer2

java.lang.Object
org.apache.hadoop.http.HttpServer2
All Implemented Interfaces:
FilterContainer

@Private @Evolving public final class HttpServer2 extends Object implements 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.
  • Field Details

  • Method Details

    • getFilterProperties

      public static Properties getFilterProperties(Configuration conf, List<String> prefixes)
    • 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 directory
      conf - configuration.
      Throws:
      IOException - raised on errors performing I/O.
    • addDefaultServlets

      protected void addDefaultServlets(Configuration configuration)
      Add default servlets.
      Parameters:
      configuration - the hadoop configuration
    • addContext

      public void addContext(org.eclipse.jetty.servlet.ServletContextHandler ctxt, boolean isFiltered)
    • setAttribute

      public void setAttribute(String name, Object value)
      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 attribute
      value - The value of the attribute
    • addJerseyResourcePackage

      public void addJerseyResourcePackage(String packageName, String pathSpec)
      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 servlet
      params - 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 servlet
      params - 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 servlet
      clazz - 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 servlet
      clazz - 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 servlet
      clazz - The servlet class
      requireAuth - 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 servlet
      clazz - The servlet class
      params - 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

      public void addFilter(String name, String classname, Map<String,String> parameters)
      Description copied from interface: FilterContainer
      Add a filter to the container.
      Specified by:
      addFilter in interface FilterContainer
      Parameters:
      name - Filter name
      classname - Filter class name
      parameters - a map from parameter names to initial values
    • addGlobalFilter

      public void addGlobalFilter(String name, String classname, Map<String,String> parameters)
      Description copied from interface: FilterContainer
      Add a global filter to the container.
      Specified by:
      addGlobalFilter in interface FilterContainer
      Parameters:
      name - filter name
      classname - filter class name
      parameters - 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 spec
      webAppCtx - The WebApplicationContext to add to
    • getAttribute

      public Object getAttribute(String name)
      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

      protected String getWebAppsPath(String appName) throws FileNotFoundException
      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 public int getPort()
      Deprecated.
      Get the port that the server is on
      Returns:
      the port
    • getConnectorAddress

      public InetSocketAddress getConnectorAddress(int index)
      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

      public void start() throws IOException
      Start the server. Does not wait for the server to start.
      Throws:
      IOException - raised on errors performing I/O.
    • stop

      public void stop() throws Exception
      stop the server.
      Throws:
      Exception - exception.
    • join

      public void join() throws InterruptedException
      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

      public String toString()
      Overrides:
      toString in class Object
    • 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.admin is set to FALSE (default value) it always returns TRUE.

      If hadoop.security.instrumentation.requires.admin is 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