Class HttpsServer

java.lang.Object
com.sun.net.httpserver.HttpServer
com.sun.net.httpserver.HttpsServer

public abstract class HttpsServer extends HttpServer
This class is an extension of HttpServer which provides support for HTTPS.

A HttpsServer must have an associated HttpsConfigurator object which is used to establish the SSL configuration for the SSL connections.

All other configuration is the same as for HttpServer.

Since:
1.6
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for subclasses to call.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a HttpsServer instance which is initially not bound to any local address/port.
    create(InetSocketAddress addr, int backlog)
    Create a HttpsServer instance which will bind to the specified InetSocketAddress (IP address and port number).
    create(InetSocketAddress addr, int backlog, String path, HttpHandler handler, Filter... filters)
    Creates an HttpsServer instance with an initial context.
    Gets this server's HttpsConfigurator object, if it has been set.
    abstract void
    Sets this server's HttpsConfigurator object.

    Methods declared in class HttpServer

    bind, createContext, createContext, getAddress, getExecutor, removeContext, removeContext, setExecutor, start, stop
    Modifier and Type
    Method
    Description
    abstract void
    bind(InetSocketAddress addr, int backlog)
    Binds a currently unbound HttpServer to the given address and port number.
    abstract HttpContext
    Creates a HttpContext without initially specifying a handler.
    abstract HttpContext
    Creates a HttpContext.
    Returns the address this server is listening on
    abstract Executor
    Returns this server's Executor object if one was specified with HttpServer.setExecutor(Executor), or null if none was specified.
    abstract void
    Removes the given context from the server.
    abstract void
    Removes the context identified by the given path from the server.
    abstract void
    Sets this server's Executor object.
    abstract void
    Starts this server in a new background thread.
    abstract void
    stop(int delay)
    Stops this server by closing the listening socket and disallowing any new exchanges from being processed.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    boolean
    Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    int
    Answers an integer hash code for the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    Answers a string containing a concise, human-readable description of the receiver.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
  • Constructor Details

    • HttpsServer

      protected HttpsServer()
      Constructor for subclasses to call.
  • Method Details

    • create

      public static HttpsServer create() throws IOException
      Creates a HttpsServer instance which is initially not bound to any local address/port. The HttpsServer is acquired from the currently installed HttpServerProvider. The server must be bound using HttpServer.bind(InetSocketAddress, int) before it can be used. The server must also have a HttpsConfigurator established with setHttpsConfigurator(HttpsConfigurator).
      Returns:
      an instance of HttpsServer
      Throws:
      IOException - if an I/O error occurs
    • create

      public static HttpsServer create(InetSocketAddress addr, int backlog) throws IOException
      Create a HttpsServer instance which will bind to the specified InetSocketAddress (IP address and port number). A maximum backlog can also be specified. This is the maximum number of queued incoming connections to allow on the listening socket. Queued TCP connections exceeding this limit may be rejected by the TCP implementation. The HttpsServer is acquired from the currently installed HttpServerProvider. The server must have a HttpsConfigurator established with setHttpsConfigurator(HttpsConfigurator).
      Parameters:
      addr - the address to listen on, if null then HttpServer.bind(InetSocketAddress, int) must be called to set the address
      backlog - the socket backlog. If this value is less than or equal to zero, then a system default value is used.
      Returns:
      an instance of HttpsServer
      Throws:
      BindException - if the server cannot bind to the requested address, or if the server is already bound
      IOException - if an I/O error occurs
    • create

      public static HttpsServer create(InetSocketAddress addr, int backlog, String path, HttpHandler handler, Filter... filters) throws IOException
      Creates an HttpsServer instance with an initial context.

      The server is created with an initial context that maps the URI path to the exchange handler. The initial context is created as if by an invocation of createContext(path). The filters, if any, are added to the initial context, in the order they are given. The returned server is not started so can be configured further if required.

      The server instance will bind to the given InetSocketAddress.

      A maximum backlog can also be specified. This is the maximum number of queued incoming connections to allow on the listening socket. Queued TCP connections exceeding this limit may be rejected by the TCP implementation. The HttpsServer is acquired from the currently installed HttpServerProvider.

      The server must have an HttpsConfigurator established with setHttpsConfigurator(HttpsConfigurator).

      Parameters:
      addr - the address to listen on, if null then bind must be called to set the address
      backlog - the socket backlog. If this value is less than or equal to zero, then a system default value is used
      path - the root URI path of the context, must be absolute
      handler - the HttpHandler for the context
      filters - the Filters for the context, optional
      Returns:
      the HttpsServer
      Throws:
      BindException - if the server cannot bind to the address
      IOException - if an I/O error occurs
      IllegalArgumentException - if path is invalid
      NullPointerException - if any of: path, handler, filters, or any element of filters, are null
      Since:
      18
    • setHttpsConfigurator

      public abstract void setHttpsConfigurator(HttpsConfigurator config)
      Sets this server's HttpsConfigurator object.
      Parameters:
      config - the HttpsConfigurator to set
      Throws:
      NullPointerException - if config is null
    • getHttpsConfigurator

      public abstract HttpsConfigurator getHttpsConfigurator()
      Gets this server's HttpsConfigurator object, if it has been set.
      Returns:
      the HttpsConfigurator for this server, or null if not set