Package ej.hoka.http

Class HttpRequest


  • public class HttpRequest
    extends java.lang.Object
    Represents a HTTP Request.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int AFTER
      after filter code.
      protected static int AFTER_ALL
      after all filter code.
      protected static int BEFORE
      before filter code.
      protected static int BEFORE_ALL
      before all filter code.
      static int CONNECT
      Value returned by getMethod() if the request method is CONNECT.
      static int DELETE
      Value returned by getMethod() if the request method is DELETE.
      static int GET
      Value returned by getMethod() if the request method is GET.
      static int HEAD
      Value returned by getMethod() if the request method is HEAD.
      static int OPTIONS
      Value returned by getMethod() if the request method is OPTIONS.
      static int PATCH
      Value returned by getMethod() if the request method is PATCH.
      static int POST
      Value returned by getMethod() if the request method is POST.
      static int PUT
      Value returned by getMethod() if the request method is PUT.
      static int TRACE
      Value returned by getMethod() if the request method is TRACE.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected HttpRequest​(java.io.InputStream inputStream, EncodingRegistry encodingRegistry)
      Constructs a new instance of HTTPRequest.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addPathParameters​(java.util.Map<java.lang.String,​java.lang.String> parameters)
      Adds path parameters from a given list to the list of path path parameters of the request.
      protected void addSplatParameters​(java.util.List<java.lang.String> splatParameters)
      Sets the splat Parameters.
      java.lang.Object getAttribute​(java.lang.String key)
      Get request server-side attribute by key.
      java.lang.String getCookie​(java.lang.String name)
      Return the cookie of the request with given name.
      java.util.Map<java.lang.String,​java.lang.String> getCookies()
      Returns the cookies of the request.
      java.lang.String getHeader​(java.lang.String name)
      Returns the header field value associated to the given header field name.
      java.util.Map<java.lang.String,​java.lang.String> getHeaders()
      Returns all HTTP header fields of the request.
      int getMethod()
      Returns the request method as an integer value which is one of POST, GET, PUT or DELETE.
      java.lang.String getPathParam​(java.lang.String param)
      Returns the path parameter value mapped to the given name.
      java.lang.String getQueryParam​(java.lang.String name)
      Returns the query parameter mapped to the given name.
      java.util.Map<java.lang.String,​java.lang.String> getQueryParams()
      Returns the Query parameters as Map.
      java.io.InputStream getRequestBody()
      use parseBody(BodyParser) for more option on request body provided parsers.
      java.util.List<java.lang.String> getSplatParams()
      Returns the list of splat parameters.
      java.lang.String getURI()
      Returns the request URI.
      java.lang.String getVersion()
      Returns the HTTP version request.
      <T> T parseBody​(BodyParser<T> bodyParser)
      Request the body to be parsed.
      void setAttribute​(java.lang.String key, java.lang.Object value)
      Set a request server-side attribute.
      • Methods inherited from class java.lang.Object

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

      • HttpRequest

        protected HttpRequest​(java.io.InputStream inputStream,
                              EncodingRegistry encodingRegistry)
                       throws java.io.IOException
        Constructs a new instance of HTTPRequest.
        Parameters:
        inputStream - the input stream of the request.
        encodingRegistry - the register of available encoding and transfer coding handlers.
        Throws:
        java.io.IOException - if connection is lost during processing the request.
        java.lang.IllegalArgumentException - if parsing the request failed.
    • Method Detail

      • getMethod

        public int getMethod()
        Returns the request method as an integer value which is one of POST, GET, PUT or DELETE.
        Returns:
        the request method (one of POST, GET, PUT or DELETE).
      • getURI

        public java.lang.String getURI()
        Returns the request URI.
        Returns:
        the request URI string.
      • getQueryParams

        public java.util.Map<java.lang.String,​java.lang.String> getQueryParams()
        Returns the Query parameters as Map.
        Returns:
        a Map of (String,String) representing the HTTP query parameters.
      • getQueryParam

        @Nullable
        public java.lang.String getQueryParam​(java.lang.String name)
        Returns the query parameter mapped to the given name.
        Parameters:
        name - of query parameter
        Returns:
        the parameter mapped to name
      • getPathParam

        @Nullable
        public java.lang.String getPathParam​(java.lang.String param)
        Returns the path parameter value mapped to the given name.
        Parameters:
        param - path parameter name
        Returns:
        path parameter value if exist, null otherwise
      • getSplatParams

        public java.util.List<java.lang.String> getSplatParams()
        Returns the list of splat parameters.
        Returns:
        a List of splat parameters.
      • addSplatParameters

        protected void addSplatParameters​(java.util.List<java.lang.String> splatParameters)
        Sets the splat Parameters.
        Parameters:
        splatParameters - the splat parameters to set.
      • addPathParameters

        protected void addPathParameters​(java.util.Map<java.lang.String,​java.lang.String> parameters)
        Adds path parameters from a given list to the list of path path parameters of the request.
        Parameters:
        parameters - path parameters to be added to the request
      • getAttribute

        @Nullable
        public java.lang.Object getAttribute​(java.lang.String key)
        Get request server-side attribute by key.
        Parameters:
        key - attribute key
        Returns:
        value mapped to key
      • setAttribute

        public void setAttribute​(java.lang.String key,
                                 java.lang.Object value)
        Set a request server-side attribute.
        Parameters:
        key - attribute key
        value - attribute value
      • getVersion

        public java.lang.String getVersion()
        Returns the HTTP version request.
        Returns:
        the HTTP version request string.
      • getHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHeaders()
        Returns all HTTP header fields of the request.
        Returns:
        a Map of (String,String) representing the HTTP header fields (may be empty).
      • getHeader

        @Nullable
        public java.lang.String getHeader​(@Nullable
                                          java.lang.String name)
        Returns the header field value associated to the given header field name.
        Parameters:
        name - the header field name.
        Returns:
        the requested header field value, null if the header field is not found or name is null.
      • getCookies

        public java.util.Map<java.lang.String,​java.lang.String> getCookies()
        Returns the cookies of the request.

        Cookies are lazily parsed.

        Returns:
        a Map of (String,String) representing the HTTP cookies (may be empty)
      • getCookie

        @Nullable
        public java.lang.String getCookie​(@Nullable
                                          java.lang.String name)
        Return the cookie of the request with given name.

        Cookies are lazily parsed.

        Parameters:
        name - the name of the cookie.
        Returns:
        the cookie, or null if name is null.
      • parseBody

        public <T> T parseBody​(BodyParser<T> bodyParser)
                        throws java.io.IOException
        Request the body to be parsed.
        Type Parameters:
        T - the type of body.
        Parameters:
        bodyParser - the parser.
        Returns:
        the parsed body.
        Throws:
        java.io.IOException - if an IOException occurs during parsing.
      • getRequestBody

        public java.io.InputStream getRequestBody()
        use parseBody(BodyParser) for more option on request body provided parsers.
        Returns:
        request request body as an input stream.