Interface WebContext


  • public interface WebContext
    This interface represents the web context to use HTTP request and response.
    Since:
    1.4.0
    Author:
    Jerome Leleu
    • Method Detail

      • getRequestParameter

        java.util.Optional<java.lang.String> getRequestParameter​(java.lang.String name)
        Return a request parameter.
        Parameters:
        name - name of the parameter
        Returns:
        the request parameter
      • getRequestParameters

        java.util.Map<java.lang.String,​java.lang.String[]> getRequestParameters()
        Return all request parameters.
        Returns:
        all request parameters
      • getRequestAttribute

        java.util.Optional getRequestAttribute​(java.lang.String name)
        Return a request attribute.
        Parameters:
        name - the name of the attribute
        Returns:
        the attribute
      • setRequestAttribute

        void setRequestAttribute​(java.lang.String name,
                                 java.lang.Object value)
        Save a request attribute.
        Parameters:
        name - the name of the attribute
        value - the attribute
      • getRequestHeader

        java.util.Optional<java.lang.String> getRequestHeader​(java.lang.String name)
        Return a request header.
        Parameters:
        name - name of the header
        Returns:
        the request header
      • getRequestMethod

        java.lang.String getRequestMethod()
        Return the request method.
        Returns:
        the request method
      • getRemoteAddr

        java.lang.String getRemoteAddr()
        Return the remote address.
        Returns:
        the remote address.
      • setResponseHeader

        void setResponseHeader​(java.lang.String name,
                               java.lang.String value)
        Add a header to the response.
        Parameters:
        name - name of the header
        value - value of the header
      • getResponseHeader

        java.util.Optional<java.lang.String> getResponseHeader​(java.lang.String name)
        Get a header from the response.
        Parameters:
        name - name of the header
        Returns:
        the value of the header
      • setResponseContentType

        void setResponseContentType​(java.lang.String content)
        Sets the response content type.
        Parameters:
        content - the content type
      • getServerName

        java.lang.String getServerName()
        Return the server name.
        Returns:
        the server name
      • getServerPort

        int getServerPort()
        Return the server port.
        Returns:
        the server port
      • getScheme

        java.lang.String getScheme()
        Return the scheme.
        Returns:
        the scheme
      • isSecure

        boolean isSecure()
        Return whether the request is secure.
        Returns:
        whether the request is secure
      • getFullRequestURL

        java.lang.String getFullRequestURL()
        Return the full URL (with query string) the client used to request the server.
        Returns:
        the URL
        Since:
        1.5.0
      • getRequestURL

        default java.lang.String getRequestURL()
        Return the full URL (without the query string) the client used to request the server.
        Returns:
        the URL
        Since:
        5.1.2
      • getRequestCookies

        java.util.Collection<Cookie> getRequestCookies()
        Retrieves request cookies.
        Returns:
        the request cookies
        Since:
        1.8.0
      • addResponseCookie

        void addResponseCookie​(Cookie cookie)
        Adds cookies to the response
        Parameters:
        cookie - a cookie to add to the response
        Since:
        1.8.0
      • getPath

        java.lang.String getPath()
        Get the "servlet path" (in a JEE style).
        Returns:
        the "servlet path"
        Since:
        1.8.1
      • getRequestContent

        default java.lang.String getRequestContent()
        Gets content body of the original request.
        Returns:
        the request content
        Since:
        1.9.2
      • getProtocol

        default java.lang.String getProtocol()
        Get the protocol version.
        Returns:
        the protocol version