Class HttpServer

    • Constructor Detail

      • HttpServer

        public HttpServer()
      • HttpServer

        public HttpServer​(java.lang.Integer port)
      • HttpServer

        protected HttpServer​(java.lang.Integer port,
                             boolean sslProtocol)
    • Method Detail

      • create

        public static void create​(java.lang.Integer port,
                                  Context... contexts)
      • addAccessControl

        public final void addAccessControl​(HttpServer.AccessControl accessControl)
        Adda new access control into the server.
        Parameters:
        accessControl - Access control instance.
      • getSessionManager

        public final HttpSessionManager getSessionManager()
        Return the instance of the session factory.
        Returns:
        Session factory.
      • setSessionManager

        public final void setSessionManager​(HttpSessionManager sessionManager)
        Set the instance of the session factory.
        Parameters:
        sessionManager - Session factory.
      • createSession

        public final HttpSession createSession​(NetPackage netPackage)
        This method must implements the session creation based on the net package that incoming.
        Specified by:
        createSession in class NetServer<HttpSession,​HttpPackage>
        Parameters:
        netPackage - Net package.
        Returns:
        Return the session based on the package.
      • addContext

        public void addContext​(Context context)
        Add context to the server.
        Parameters:
        context - Context instance.
      • findContext

        protected HttpServer.ContextMatcher findContext​(java.lang.String contextName)
        Find the context instance that response to the request's context name.
        Parameters:
        contextName - Request's context name.
        Returns:
        Founded context.
      • onRead

        protected final void onRead​(HttpSession session,
                                    HttpPackage payLoad,
                                    NetPackage netPackage)
        First check if the package is complete, then try to found the context using the http request information a create the response package.
        Overrides:
        onRead in class NetServiceConsumer<HttpSession,​HttpPackage>
        Parameters:
        session - Net session.
        payLoad - Net package decoded
        netPackage - Net package.
      • onCheckSessionError

        protected void onCheckSessionError​(HttpSession session,
                                           HttpPackage requestPayLoad,
                                           NetPackage netPackage,
                                           java.lang.Throwable exception)
        Manages an exception thrown while trying to check session (authenticate) by calling to the specific context for get an error response depending on exception information. Thus, the response is written to the consumer.
        Overrides:
        onCheckSessionError in class NetServiceConsumer<HttpSession,​HttpPackage>
        Parameters:
        session - Net session.
        requestPayLoad - Net package decoded as HttpRequest
        netPackage - Net package.
        exception - exception
      • onContextNotFound

        protected HttpResponse onContextNotFound​(HttpRequest request)
        This method must create the response package when the context not found.
        Parameters:
        request - Http request.
        Returns:
        Context not found response.
      • onUnresponsiveContext

        protected HttpResponse onUnresponsiveContext​(HttpRequest request)
        This method must create the response package when the context result is null.
        Parameters:
        request - Http request.
        Returns:
        Unresponsive context response.
      • onNotCheckedSession

        protected HttpResponse onNotCheckedSession​(HttpRequest request)
        This method must create the response package when the session check fail.
        Parameters:
        request - Http request.
        Returns:
        Session check fail response.