Class Request<T>

java.lang.Object
org.restheart.exchange.Exchange<T>
org.restheart.exchange.Request<T>
Type Parameters:
T - generic type
Direct Known Subclasses:
ProxyRequest, ServiceRequest

public abstract class Request<T> extends Exchange<T>
The root class for implementing a Request providing the implementation for common methods
Author:
Andrea Di Cesare <[email protected]>
  • Field Details

  • Constructor Details

    • Request

      protected Request(io.undertow.server.HttpServerExchange exchange)
  • Method Details

    • of

      public static Request of(io.undertow.server.HttpServerExchange exchange)
    • getContentType

      public static String getContentType(io.undertow.server.HttpServerExchange exchange)
    • getPath

      public String getPath()
      Returns:
      the request path
    • getURL

      public String getURL()
      Returns:
      the request URL
    • getQueryString

      public String getQueryString()
      Returns:
      the query string
    • getMethod

      public ExchangeKeys.METHOD getMethod()
      Returns:
      the request method
    • getRequestContentLength

      public long getRequestContentLength()
      Returns:
      a content lenght
    • getQueryParameters

      public Map<String,​Deque<String>> getQueryParameters()
      Returns:
      a mutable map of query parameters
    • getQueryParameterOfDefault

      public String getQueryParameterOfDefault(String name, String defaultValue)
      Returns:
      a the first value of the query paramter of defaultValue if not present
    • getHeaders

      public io.undertow.util.HeaderMap getHeaders()
      Returns:
      the request headers
    • getHeader

      public String getHeader(String name)
      note: an header can have multiple values. This only returns the first one. use getHeaders() to get all the header's values
      Parameters:
      name - the name of the header to return
      Returns:
      the first value of the header
    • setHeader

      public void setHeader(io.undertow.util.HttpString name, String value)
      note: an header can have multiple values. This sets the given value clearing existing ones. use getHeaders().add(value) to add the value without clearing.
      Parameters:
      name - the name of the header to return
    • setHeader

      public void setHeader(String name, String value)
      note: an header can have multiple values. This sets the given value clearing existing ones. use getHeaders().add(value) to add the value without clearing.
      Parameters:
      name - the name of the header to return
    • getCookie

      public io.undertow.server.handlers.Cookie getCookie(String name)
      Parameters:
      name - the name of the cookie to return
      Returns:
      a the cookie
    • getPathParams

      public Map<String,​String> getPathParams(String pathTemplate)
      get path parameters using a template pathTemplate=/foo/{id} and URI=/foo/bar => returns a map with id=bar
      Parameters:
      pathTemplate - the path template
      Returns:
      the path parameters
    • getPathParam

      public String getPathParam(String pathTemplate, String paramName)
      get a path parameter using a path template eg pathTemplate=/foo/{id}, paramName=id and URI=/foo/bar => returns bar
      Parameters:
      pathTemplate - the path template
      paramName - name of parameter
      Returns:
      the path parameter
    • getContentType

      public String getContentType()
      Specified by:
      getContentType in class Exchange<T>
      Returns:
      the request ContentType
    • setContentType

      public void setContentType(String responseContentType)
      Parameters:
      responseContentType - the responseContentType to set
    • setContentTypeAsJson

      public void setContentTypeAsJson()
      sets Content-Type=application/json
    • setContentLength

      protected void setContentLength(int length)
    • getStartTime

      public Long getStartTime()
      Returns:
      the requestStartTime
    • setStartTime

      public void setStartTime(Long requestStartTime)
      Parameters:
      requestStartTime - the requestStartTime to set
    • getAuthenticatedAccount

      public io.undertow.security.idm.Account getAuthenticatedAccount()
      Returns:
      the authenticatedAccount
    • addXForwardedHeader

      public void addXForwardedHeader(String key, String value)
      Add the header X-Forwarded-[key] to the proxied request; use it to pass to the backend information otherwise lost proxying the request.
      Parameters:
      key -
      value -
    • getXForwardedHeaders

      public Map<String,​List<String>> getXForwardedHeaders()
    • pipelineInfo

      public static PipelineInfo pipelineInfo(io.undertow.server.HttpServerExchange exchange)
      Returns:
      the PipelineInfo that allows to know which pipeline (service, proxy or static resource) is handling the exchange
    • setPipelineInfo

      public static void setPipelineInfo(io.undertow.server.HttpServerExchange exchange, PipelineInfo pipelineInfo)
      Parameters:
      exchange - the exchange to bind the pipelineInfo to
      pipelineInfo - the pipelineInfo to set
    • getPipelineInfo

      public PipelineInfo getPipelineInfo()
      Returns:
      the PipelineInfo that allows to know which pipeline (service, proxy or static resource) is handling the exchange
    • setPipelineInfo

      public void setPipelineInfo(PipelineInfo pipelineInfo)
      Parameters:
      pipelineInfo - the pipelineInfo to set
    • isContentTypeJson

      public static boolean isContentTypeJson(io.undertow.server.HttpServerExchange exchange)
      helper method to check if the request content is Json
      Parameters:
      exchange -
      Returns:
      true if Content-Type request header is application/json
    • isContentTypeFormOrMultipart

      public static boolean isContentTypeFormOrMultipart(io.undertow.server.HttpServerExchange exchange)
    • isContentTypeFormOrMultipart

      public boolean isContentTypeFormOrMultipart()
    • isDelete

      public boolean isDelete()
      helper method to check request method
      Returns:
      true if method is METHOD.DELETE
    • isGet

      public boolean isGet()
      helper method to check request method
      Returns:
      true if method is METHOD.GET
    • isOptions

      public boolean isOptions()
      helper method to check request method
      Returns:
      true if method is METHOD.OPTIONS
    • isPatch

      public boolean isPatch()
      helper method to check request method
      Returns:
      true if method is METHOD.PATCH
    • isPost

      public boolean isPost()
      helper method to check request method
      Returns:
      true if method is METHOD.POST
    • isPut

      public boolean isPut()
      helper method to check request method
      Returns:
      true if method is METHOD.PUT