Class HttpServer

java.lang.Object
org.glassfish.grizzly.http.server.HttpServer

public class HttpServer extends Object
  • Field Details

    • jmxManager

      protected volatile GrizzlyJmxManager jmxManager
    • managementObject

      protected volatile Object managementObject
  • Constructor Details

    • HttpServer

      public HttpServer()
  • Method Details

    • getServerConfiguration

      public final ServerConfiguration getServerConfiguration()
      Returns:
      the ServerConfiguration used to configure this HttpServer instance
    • addListener

      public void addListener(NetworkListener listener)

      Adds the specified listener to the server instance.

      If the server is already running when this method is called, the listener will be started.

      Parameters:
      listener - the NetworkListener to associate with this server instance.
    • getListener

      public NetworkListener getListener(String name)
      Parameters:
      name - the NetworkListener name.
      Returns:
      the NetworkListener, if any, associated with the specified name.
    • getListeners

      public Collection<NetworkListener> getListeners()
      Returns:
      a read only Collection over the listeners associated with this HttpServer instance.
    • removeListener

      public NetworkListener removeListener(String name)

      Removes the NetworkListener associated with the specified name.

      If the server is running when this method is invoked, the listener will be stopped before being returned.

      Parameters:
      name - the name of the NetworkListener to remove.
      Returns:
      NetworkListener, that has been removed, or null if the listener with the given name doesn't exist
    • start

      public void start() throws IOException

      Starts the HttpServer.

      Throws:
      IOException - if an error occurs while attempting to start the server.
    • getHttpHandler

      public HttpHandler getHttpHandler()
      Returns:
      the HttpHandler used by this HttpServer instance.
    • isStarted

      public boolean isStarted()
      Returns:
      true if this HttpServer has been started.
    • getManagementObject

      public Object getManagementObject(boolean clear)
    • shutdown

      public GrizzlyFuture<HttpServer> shutdown(long gracePeriod, TimeUnit timeUnit)
    • shutdown

      public GrizzlyFuture<HttpServer> shutdown()

      Gracefully shuts down the HttpServer instance.

    • shutdownNow

      public void shutdownNow()

      Immediately shuts down the HttpServer instance.

    • stop

      @Deprecated public void stop()
      Deprecated.

      Immediately shuts down the HttpServer instance.

    • createSimpleServer

      public static HttpServer createSimpleServer()
      Returns:
      a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:NetworkListener.DEFAULT_NETWORK_PORT, using the directory in which the server was launched the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      Returns:
      a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:NetworkListener.DEFAULT_NETWORK_PORT, using the specified docRoot as the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot, int port)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      port - the network port to which this listener will bind
      Returns:
      a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:port, using the specified docRoot as the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot, PortRange range)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      range - port range to attempt to bind to
      Returns:
      a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:[port-range], using the specified docRoot as the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot, SocketAddress socketAddress)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      socketAddress - the endpoint address to which this listener will bind
      Returns:
      a HttpServer configured to listen to requests on socketAddress, using the specified docRoot as the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot, String host, int port)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      host - the network port to which this listener will bind
      port - the network port to which this listener will bind
      Returns:
      a HttpServer configured to listen to requests on host:port, using the specified docRoot as the server's document root
    • createSimpleServer

      public static HttpServer createSimpleServer(String docRoot, String host, PortRange range)
      Parameters:
      docRoot - the document root, can be null when no static pages are needed
      host - the network port to which this listener will bind
      range - port range to attempt to bind to
      Returns:
      a HttpServer configured to listen to requests on host:[port-range], using the specified docRoot as the server's document root
    • enableJMX

      protected void enableJMX()
    • disableJMX

      protected void disableJMX()
    • configureCompressionEncodings

      protected Set<ContentEncoding> configureCompressionEncodings(NetworkListener listener)