Class Context

    • Constructor Summary

      Constructors 
      Constructor Description
      Context​(java.lang.String contextRegex)
      Constructor
    • Method Summary

      Modifier and Type Method Description
      static HttpResponse addDefaultResponseHeaders​(HttpResponse response, byte[] body)
      Utils method in order to add a default headers into the default response package.
      static HttpResponse createDefaultErrorResponse​(java.lang.Throwable throwable)
      Utils method in order to reuse the creation of error response package.
      java.lang.String getContextRegex()
      Return the regular expression that represents the add of URLs that refer to this context.
      java.util.regex.Pattern getPattern()
      Returns the pattern created with the regex of the context.
      long getTimeout()
      Returns the timeout value of the context execution.
      abstract HttpResponse onContext​(HttpRequest request)
      This method is called when there comes a http package addressed to this context.
      protected HttpResponse onError​(HttpRequest request, java.lang.Throwable throwable)
      This method is called when there are any error on the context execution.
      void setTimeout​(long timeout)
      Set the timeout value of the context execution.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Context

        public Context​(java.lang.String contextRegex)
        Constructor
        Parameters:
        contextRegex - Regular expression that represents the add of URLs that refer to this context.
    • Method Detail

      • getContextRegex

        public final java.lang.String getContextRegex()
        Return the regular expression that represents the add of URLs that refer to this context.
        Returns:
        Regular expression.
      • getPattern

        public java.util.regex.Pattern getPattern()
        Returns the pattern created with the regex of the context.
        Returns:
        Pattern instance.
      • onContext

        public abstract HttpResponse onContext​(HttpRequest request)
        This method is called when there comes a http package addressed to this context.
        Parameters:
        request - All the request information.
        Returns:
        Return an object with all the response information.
      • getTimeout

        public long getTimeout()
        Returns the timeout value of the context execution.
        Returns:
        Timeout value.
      • setTimeout

        public void setTimeout​(long timeout)
        Set the timeout value of the context execution.
        Parameters:
        timeout - Timeout value.
      • onError

        protected HttpResponse onError​(HttpRequest request,
                                       java.lang.Throwable throwable)
        This method is called when there are any error on the context execution.
        Parameters:
        request - All the request information.
        throwable - Throwable object, could be null.
        Returns:
        Return an object with all the response information.
      • createDefaultErrorResponse

        public static HttpResponse createDefaultErrorResponse​(java.lang.Throwable throwable)
        Utils method in order to reuse the creation of error response package.
        Parameters:
        throwable - Throwable instance.
        Returns:
        Http response instance.
      • addDefaultResponseHeaders

        public static HttpResponse addDefaultResponseHeaders​(HttpResponse response,
                                                             byte[] body)
        Utils method in order to add a default headers into the default response package.
        Parameters:
        response - Response package.
        body - Body object.
        Returns:
        Returns the same response instance with the headers added.