Class HttpRestServerImpl

    • Field Detail

      • CONTEXT_PATH

        protected static final java.lang.String CONTEXT_PATH
    • Constructor Detail

      • HttpRestServerImpl

        public HttpRestServerImpl​(org.refcodes.controlflow.ThreadingModel aThreadingModel)
        Constructs a HttpRestServerImpl. Use HttpRestServer.open(int) or similar to make it listen on your port. The provided ThreadingModel defines whether to use a single-threaded or a multi-threaded threading model. Threads are created as daemon threads. For more control on thread generation use the constructor HttpRestServerImpl(ExecutorService).
        Parameters:
        aThreadingModel - Specifies to either use a single-threaded threading model (no ExecutorService) or a multi-threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean).
      • HttpRestServerImpl

        public HttpRestServerImpl()
        Constructs a HttpRestServerImpl. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model with a default ExecutorService as of ControlFlowUtility.createCachedExecutorService(boolean). Threads are created as daemon threads. For more control on thread generation use the constructor HttpRestServerImpl(ExecutorService).
      • HttpRestServerImpl

        public HttpRestServerImpl​(java.util.concurrent.ExecutorService aExecutorService)
        Constructs a HttpRestServerImpl. Use HttpRestServer.open(int) or similar to make it listen on your port. Uses a multi threaded threading model.
        Parameters:
        aExecutorService - An executor service to be used when creating Threads.
    • Method Detail

      • close

        public void close()
                   throws org.refcodes.component.CloseException
        Specified by:
        close in interface org.refcodes.component.Closable
        Throws:
        org.refcodes.component.CloseException
      • open

        public void open​(java.lang.String aProtocol,
                         org.refcodes.security.KeyStoreDescriptor aStoreDescriptor,
                         int aPort,
                         int aMaxConnections)
                  throws org.refcodes.component.OpenException
        Opens the HTTPS sever connection (socket) at the given port allowing the given number of maximum connections at the same time using the provided HTTPS configuration parameters.
        Specified by:
        open in interface HttpRestServer
        Parameters:
        aProtocol - The protocol to use, e.g. "TLS".
        aStoreDescriptor - The store descriptor describing your KeyStore required for HTTPS.
        aPort - The port on which to listen for requests.
        aMaxConnections - The number of maximum connections at the same time.
        Throws:
        org.refcodes.component.OpenException - thrown in case something went wrong such as the port being already in use.
      • getConnectionStatus

        public org.refcodes.component.ConnectionStatus getConnectionStatus()
        Specified by:
        getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessor
      • onConnectionRequest

        public HttpRestServer onConnectionRequest​(org.refcodes.net.HttpsConnectionRequestObserver aObserver)
        Specified by:
        onConnectionRequest in interface org.refcodes.net.HttpsConnectionRequestObservable<HttpRestServer>
      • onBasicAuthRequest

        public HttpRestServer onBasicAuthRequest​(org.refcodes.net.BasicAuthObserver aBasicAuthObserver)
        Specified by:
        onBasicAuthRequest in interface org.refcodes.net.BasicAuthObservable<HttpRestServer>
      • setPort

        public void setPort​(int aPort)
        Specified by:
        setPort in interface org.refcodes.mixin.PortAccessor.PortMutator
      • getPort

        public int getPort()
        Specified by:
        getPort in interface org.refcodes.mixin.PortAccessor
      • setScheme

        public void setScheme​(org.refcodes.data.Scheme aScheme)
        Specified by:
        setScheme in interface org.refcodes.net.SchemeAccessor.SchemeMutator
      • getScheme

        public org.refcodes.data.Scheme getScheme()
        Specified by:
        getScheme in interface org.refcodes.net.SchemeAccessor
      • toProtocol

        public java.lang.String toProtocol()
        Specified by:
        toProtocol in interface org.refcodes.net.SchemeAccessor
      • setProtocol

        public void setProtocol​(java.lang.String aProtocol)
        Specified by:
        setProtocol in interface org.refcodes.net.SchemeAccessor.SchemeMutator
      • getKeyStoreDescriptor

        public org.refcodes.security.KeyStoreDescriptor getKeyStoreDescriptor()
        Specified by:
        getKeyStoreDescriptor in interface org.refcodes.security.KeyStoreDescriptorAccessor
      • setKeyStoreDescriptor

        public void setKeyStoreDescriptor​(org.refcodes.security.KeyStoreDescriptor aStoreDescriptor)
        Specified by:
        setKeyStoreDescriptor in interface org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator
      • getMaxConnections

        public int getMaxConnections()
        Specified by:
        getMaxConnections in interface org.refcodes.io.MaxConnectionsAccessor
      • setMaxConnections

        public void setMaxConnections​(int aMaxConnections)
        Specified by:
        setMaxConnections in interface org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator
      • getHttpServer

        protected com.sun.net.httpserver.HttpServer getHttpServer()
        Gets the http server.
        Returns:
        the http server
      • open

        protected void open​(com.sun.net.httpserver.HttpServer aHttpServer)
                     throws java.io.IOException
        A hook to be used when using custom HttpServer ( HttpsServer) by custom open(...) methods of sub-classes of this HttpRestServerImpl. E.g HttpRestServerImpl uses this hook to pre-configure a HttpsServer for HTTPS. The passed HttpServer ( HttpsServer) must already be bound to a port and enabled with the number of concurrent connections as of HttpServer.bind(InetSocketAddress, int).
        Parameters:
        aHttpServer - The HttpServer to be used. E.g. an HttpsServer might be used to enable HTTPS.
        Throws:
        java.io.IOException - in case opening with the provided HttpRestServer fails.