Class JEEContext

  • All Implemented Interfaces:
    WebContext

    public class JEEContext
    extends Object
    implements WebContext
    This implementation uses the JEE HttpServletRequest and HttpServletResponse.
    Since:
    1.4.0
    Author:
    Jerome Leleu
    • Constructor Detail

      • JEEContext

        public JEEContext​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
        Build a JEE context from the current HTTP request and response.
        Parameters:
        request - the current request
        response - the current response
      • JEEContext

        public JEEContext​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response,
                          SessionStore<JEEContext> sessionStore)
        Build a JEE context from the current HTTP request and response.
        Parameters:
        request - the current request
        response - the current response
        sessionStore - the session store to use
    • Method Detail

      • getRequestAttribute

        public Optional getRequestAttribute​(String name)
        Description copied from interface: WebContext
        Return a request attribute.
        Specified by:
        getRequestAttribute in interface WebContext
        Parameters:
        name - the name of the attribute
        Returns:
        the attribute
      • setRequestAttribute

        public void setRequestAttribute​(String name,
                                        Object value)
        Description copied from interface: WebContext
        Save a request attribute.
        Specified by:
        setRequestAttribute in interface WebContext
        Parameters:
        name - the name of the attribute
        value - the attribute
      • getRequestMethod

        public String getRequestMethod()
        Description copied from interface: WebContext
        Return the request method.
        Specified by:
        getRequestMethod in interface WebContext
        Returns:
        the request method
      • getRemoteAddr

        public String getRemoteAddr()
        Description copied from interface: WebContext
        Return the remote address.
        Specified by:
        getRemoteAddr in interface WebContext
        Returns:
        the remote address.
      • getNativeRequest

        public javax.servlet.http.HttpServletRequest getNativeRequest()
        Return the native HTTP request.
        Returns:
        the native HTTP request
      • getNativeResponse

        public javax.servlet.http.HttpServletResponse getNativeResponse()
        Return the native HTTP response.
        Returns:
        the native HTTP response
      • setResponseHeader

        public void setResponseHeader​(String name,
                                      String value)
        Description copied from interface: WebContext
        Add a header to the response.
        Specified by:
        setResponseHeader in interface WebContext
        Parameters:
        name - name of the header
        value - value of the header
      • setResponseContentType

        public void setResponseContentType​(String content)
        Description copied from interface: WebContext
        Sets the response content type.
        Specified by:
        setResponseContentType in interface WebContext
        Parameters:
        content - the content type
      • getServerName

        public String getServerName()
        Description copied from interface: WebContext
        Return the server name.
        Specified by:
        getServerName in interface WebContext
        Returns:
        the server name
      • getServerPort

        public int getServerPort()
        Description copied from interface: WebContext
        Return the server port.
        Specified by:
        getServerPort in interface WebContext
        Returns:
        the server port
      • getScheme

        public String getScheme()
        Description copied from interface: WebContext
        Return the scheme.
        Specified by:
        getScheme in interface WebContext
        Returns:
        the scheme
      • isSecure

        public boolean isSecure()
        Description copied from interface: WebContext
        Return whether the request is secure.
        Specified by:
        isSecure in interface WebContext
        Returns:
        whether the request is secure
      • getFullRequestURL

        public String getFullRequestURL()
        Description copied from interface: WebContext
        Return the full URL (with query string) the client used to request the server.
        Specified by:
        getFullRequestURL in interface WebContext
        Returns:
        the URL
      • addResponseCookie

        public void addResponseCookie​(Cookie cookie)
        Description copied from interface: WebContext
        Adds cookies to the response
        Specified by:
        addResponseCookie in interface WebContext
        Parameters:
        cookie - a cookie to add to the response
      • getPath

        public String getPath()
        This is not implemented using HttpServletRequest.getServletPath() or HttpServletRequest.getPathInfo() because they both have strange behaviours in different contexts (inside servlets, inside filters, various container implementation, etc)
        Specified by:
        getPath in interface WebContext
        Returns:
        the "servlet path"
      • getRequestContent

        public String getRequestContent()
        Description copied from interface: WebContext
        Gets content body of the original request.
        Specified by:
        getRequestContent in interface WebContext
        Returns:
        the request content
      • getProtocol

        public String getProtocol()
        Description copied from interface: WebContext
        Get the protocol version.
        Specified by:
        getProtocol in interface WebContext
        Returns:
        the protocol version