Interface HttpRequest

All Superinterfaces:
AttributeAware

public interface HttpRequest extends AttributeAware
Interface that abstracts out the common request methods used by the system dispatcher.

Example of GET method

Let's take a look at an example HTTP GET request (no body):
 
  GET /api/path/to/hello.html?param1=value1&param2 HTTP/1.1
  User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
  Host: something.example.com
  Accept-Language: en-us
  Accept-Encoding: gzip, deflate
  Connection: Keep-Alive
 
 
When this request is received, the HttpRequest object contains the following values:
  getMethod()            -> RequestMethod.GET
  getPath()              -> "/api/path/to/hello.html"
  getClientAddress()     -> 192.168.99.113  (for example)
  getParameter("param1") -> "value1"
  getParameter("param2") -> ""
  getParameter("param3") -> null
  getParameters()        -> {["param1", "value1"], ["param2", ""]}
  getHeader("Host")      -> "something.example.com"
  getHeader("Bogus")     -> null
  getHeaders("Accept-Encoding") -> ["gzip", "deflate"]
  getHeaderNames()       -> ["User-Agent", "Host", "Accept-Language", "Accept-Encoding", "Connection"]
  getInputStream()       -> [empty]
  getJsonBody()          -> [empty]
 

Example of POST method

In this example, we look at an example HTTP POST request (has body):
  POST /api/user HTTP/1.1
  User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
  Host: mysite.com
  Content-Type: application/json
  Content-Length: [length]
  Accept-Language: en-us
  Accept-Encoding: gzip, deflate
  Connection: Keep-Alive

  {"userId": "123", "firstName": "Fred", "lastName", "Flintstone"}  // this is the body
 
Here's what the "body" methods return:
  getInputStream() -> raw stream of bytes
  getJsonBody()    -> the body in JsonNode object
 
Since:
1.0
Version:
2022-08-30
See Also:
  • Method Details

    • getMethod

      RequestMethod getMethod()
      Returns the HTTP method of the request.
      Returns:
      the method of the request
    • getPath

      String getPath()
      Returns the path portion of the request.
      Returns:
      path of the request
    • getClientAddress

      InetSocketAddress getClientAddress()
      Returns the IP address of the client.
      Returns:
      client ip address
    • getParameter

      String getParameter(String name)
      Gets the first query parameter with the specified name.
      Parameters:
      name - the parameter name
      Returns:
      the first parameter value or null
    • getParameters

      MultiValueMap<String,String> getParameters()
      Gets all query parameters for the request.
      Returns:
      the parameters
    • getHeader

      String getHeader(String name)
      Returns the first value for the given header.
      Parameters:
      name - the header name
      Returns:
      the first value
    • getHeaders

      Collection<String> getHeaders(String name)
      Returns a list of values for the specified header.
      Parameters:
      name - the header name
      Returns:
      list of values
    • getHeaderNames

      Collection<String> getHeaderNames()
      Returns a list of header names.
      Returns:
      list of header names
    • getInputStream

      InputStream getInputStream() throws IOException
      Returns the input stream for the body of the request. This can only be read once.
      Returns:
      input stream to the request body
      Throws:
      IOException
    • getJsonBody

      JsonNode getJsonBody()
      Returns the input for the body of the request in pre-parsed form. This is only used for requests that bypass networking (API calls), which basically performs object-to-object mapping, but without going to string.
      Returns:
      input body in parsed form
    • isWebsocket

      default boolean isWebsocket()
      Return true if this request arrived over a routed websocket
    • getWebsocketSrcAddr

      default String getWebsocketSrcAddr()
      Return the src address if the request arrived over a routed websocket.