Class JEEContext

  • All Implemented Interfaces:
    WebContext

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

      Constructors 
      Constructor Description
      JEEContext​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Build a JEE context from the current HTTP request and response.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addResponseCookie​(Cookie cookie)
      Adds cookies to the response
      java.lang.String getFullRequestURL()
      Return the full URL (with query string) the client used to request the server.
      javax.servlet.http.HttpServletRequest getNativeRequest()
      Return the native HTTP request.
      javax.servlet.http.HttpServletResponse getNativeResponse()
      Return the native HTTP response.
      java.lang.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)
      java.lang.String getProtocol()
      Get the protocol version.
      java.lang.String getRemoteAddr()
      Return the remote address.
      java.util.Optional getRequestAttribute​(java.lang.String name)
      Return a request attribute.
      java.lang.String getRequestContent()
      Gets content body of the original request.
      java.util.Collection<Cookie> getRequestCookies()
      Retrieves request cookies.
      java.util.Optional<java.lang.String> getRequestHeader​(java.lang.String name)
      Return a request header.
      java.lang.String getRequestMethod()
      Return the request method.
      java.util.Optional<java.lang.String> getRequestParameter​(java.lang.String name)
      Return a request parameter.
      java.util.Map<java.lang.String,​java.lang.String[]> getRequestParameters()
      Return all request parameters.
      java.lang.String getRequestURL()
      Return the full URL (without the query string) the client used to request the server.
      java.util.Optional<java.lang.String> getResponseHeader​(java.lang.String name)
      Get a header from the response.
      java.lang.String getScheme()
      Return the scheme.
      java.lang.String getServerName()
      Return the server name.
      int getServerPort()
      Return the server port.
      boolean isSecure()
      Return whether the request is secure.
      void setRequestAttribute​(java.lang.String name, java.lang.Object value)
      Save a request attribute.
      void setResponseContentType​(java.lang.String content)
      Sets the response content type.
      void setResponseHeader​(java.lang.String name, java.lang.String value)
      Add a header to the response.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Method Detail

      • getRequestParameter

        public java.util.Optional<java.lang.String> getRequestParameter​(java.lang.String name)
        Description copied from interface: WebContext
        Return a request parameter.
        Specified by:
        getRequestParameter in interface WebContext
        Parameters:
        name - name of the parameter
        Returns:
        the request parameter
      • getRequestAttribute

        public java.util.Optional getRequestAttribute​(java.lang.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​(java.lang.String name,
                                        java.lang.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
      • getRequestParameters

        public java.util.Map<java.lang.String,​java.lang.String[]> getRequestParameters()
        Description copied from interface: WebContext
        Return all request parameters.
        Specified by:
        getRequestParameters in interface WebContext
        Returns:
        all request parameters
      • getRequestHeader

        public java.util.Optional<java.lang.String> getRequestHeader​(java.lang.String name)
        Description copied from interface: WebContext
        Return a request header.
        Specified by:
        getRequestHeader in interface WebContext
        Parameters:
        name - name of the header
        Returns:
        the request header
      • getRequestMethod

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

        public java.lang.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​(java.lang.String name,
                                      java.lang.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
      • getResponseHeader

        public java.util.Optional<java.lang.String> getResponseHeader​(java.lang.String name)
        Description copied from interface: WebContext
        Get a header from the response.
        Specified by:
        getResponseHeader in interface WebContext
        Parameters:
        name - name of the header
        Returns:
        the value of the header
      • setResponseContentType

        public void setResponseContentType​(java.lang.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 java.lang.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 java.lang.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
      • getRequestURL

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

        public java.lang.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
      • getRequestCookies

        public java.util.Collection<Cookie> getRequestCookies()
        Description copied from interface: WebContext
        Retrieves request cookies.
        Specified by:
        getRequestCookies in interface WebContext
        Returns:
        the request cookies
      • 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 java.lang.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 java.lang.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 java.lang.String getProtocol()
        Description copied from interface: WebContext
        Get the protocol version.
        Specified by:
        getProtocol in interface WebContext
        Returns:
        the protocol version