Class WebMap.RequestInfo

java.lang.Object
org.bzdev.ejws.WebMap.RequestInfo
All Implemented Interfaces:
HttpServerRequest
Enclosing class:
WebMap

public static class WebMap.RequestInfo extends Object implements HttpServerRequest
HTTP Request data. This data structure is passed as an argument to WebMap.getInfoFromPath(String,String,String,String,WebMap.RequestInfo) and allows implementations of that method
  • to get the request method (HEAD, GET, POST, PUT, etc.).
  • to get the value(s) associated a header given its key.
  • to get the content type of a request.
  • to get the content length of a request.
  • A stream to read the request's contents. The method getDecodedInputStream() will provide the contents after any content-encoding has been processed. This is useful if data was compressed and will be stored somewhere in compressed form. The method getDecodedInputStream() provides an input stream that will decompress the data if necessary. When the actual data is used, this method is preferred.
Note: the constructor is visible only in this package. It is used by FileHandler. This class implements the interface HttpServerRequest because that interface was designed to be easily implemented by a servlet. This design decision was made to facilitate migrating code written for an EJWS server to a web server that supports servlet.
  • Method Details

    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: HttpServerRequest
      Get an attribute.
      Specified by:
      getAttribute in interface HttpServerRequest
      Parameters:
      name - the attribute name
      Returns:
      the attribute
    • setAttribute

      public void setAttribute(String name, Object value)
      Description copied from interface: HttpServerRequest
      Set an attribute.
      Specified by:
      setAttribute in interface HttpServerRequest
      Parameters:
      name - the attribute name
      value - the attribute value
    • getContextAttribute

      public Object getContextAttribute(String name)
      Description copied from interface: HttpServerRequest
      Get a context attribute. A context is an instance of HttpContext when using EmbeddedWebServer and ServletContext when using a servlet (see the the Jarkarta Servlet API v4.0.3 for a description of this class).
      Specified by:
      getContextAttribute in interface HttpServerRequest
      Parameters:
      name - the attribute name
      Returns:
      the attribute
    • setContextAttribute

      public void setContextAttribute(String name, Object value)
      Description copied from interface: HttpServerRequest
      Set a context attribute. A context is an instance of HttpContext when using EmbeddedWebServer and ServletContext when using a servlet (see the the Jarkarta Servlet API v4.0.3 for a description of this class).
      Specified by:
      setContextAttribute in interface HttpServerRequest
      Parameters:
      name - the attribute name
      value - the attribute value
    • getRequestedSessionID

      public String getRequestedSessionID()
      Description copied from interface: HttpServerRequest
      Get the session ID specified by a client; The default assumes that session IDs have not been implemented.
      Specified by:
      getRequestedSessionID in interface HttpServerRequest
      Returns:
      the session ID; null if there is none
    • changeSessionID

      public String changeSessionID() throws IllegalStateException
      Description copied from interface: HttpServerRequest
      Change the current session's ID.
      Specified by:
      changeSessionID in interface HttpServerRequest
      Returns:
      the new session ID
      Throws:
      IllegalStateException - a session does not exist
    • setSessionState

      public void setSessionState(Object state) throws IllegalStateException
      Description copied from interface: HttpServerRequest
      Set the current session's state.
      Specified by:
      setSessionState in interface HttpServerRequest
      Parameters:
      state - the session state
      Throws:
      IllegalStateException - the session does not exist
    • getSessionState

      public Object getSessionState()
      Description copied from interface: HttpServerRequest
      Get the current session state.
      Specified by:
      getSessionState in interface HttpServerRequest
      Returns:
      the session state; null if one does not exist.
    • isRequestedSessionIDValid

      public boolean isRequestedSessionIDValid()
      Description copied from interface: HttpServerRequest
      Determines if the requested session ID is valid. The default assumes that session IDs have not been implemented and thus returns false.
      Specified by:
      isRequestedSessionIDValid in interface HttpServerRequest
      Returns:
      true if the current session ID is valid; false otherwise
    • setMaxInactiveInterval

      public boolean setMaxInactiveInterval(int interval)
      Description copied from interface: HttpServerRequest
      Set the maximum inactive interval for this request's session.
      Specified by:
      setMaxInactiveInterval in interface HttpServerRequest
      Parameters:
      interval - the maximum inactive interval in seconds; 0 if no timeout
      Returns:
      true if this method succeeded; false otherwise (i.e., if there is no session)
    • getMaxInactiveInterval

      public int getMaxInactiveInterval()
      Description copied from interface: HttpServerRequest
      Get the maximum inactive interval for this request's session.
      Specified by:
      getMaxInactiveInterval in interface HttpServerRequest
      Returns:
      the maximum inactive interval in seconds; 0 if no timeout; -1 if there is no session
    • getMethod

      public HttpMethod getMethod()
      Description copied from interface: HttpServerRequest
      Get the request method.
      Specified by:
      getMethod in interface HttpServerRequest
      Returns:
      the method.
    • getRequestURI

      public String getRequestURI()
      Description copied from interface: HttpServerRequest
      Get the request URI. This is the first line of an HTTP request. It will not include the server or the method. It does not include a query string
      Specified by:
      getRequestURI in interface HttpServerRequest
      Returns:
      the request URI
    • getRequestURL

      public String getRequestURL()
      Description copied from interface: HttpServerRequest
      Get the URL sent by the client. The URL is reconstructed based on server information.
      Specified by:
      getRequestURL in interface HttpServerRequest
      Returns:
      the URL
    • getRemoteAddr

      public String getRemoteAddr()
      Description copied from interface: HttpServerRequest
      Return the IP (Internet Protocol) address of the client, last proxy, or router/switch using NAT (Network Address Translation), that sent this request.
      Specified by:
      getRemoteAddr in interface HttpServerRequest
      Returns:
      the address
    • getProtocol

      public String getProtocol()
      Description copied from interface: HttpServerRequest
      Get the protocol used in the request. For example, HTTP/1.1 for HTTP version 1.1
      Specified by:
      getProtocol in interface HttpServerRequest
      Returns:
      the protocol in the form PROTOCOL/MAJOR.MINOR
    • getUserPrincipal

      public Principal getUserPrincipal()
      Description copied from interface: HttpServerRequest
      Get the Principal for the user authenticating this request.
      Specified by:
      getUserPrincipal in interface HttpServerRequest
      Returns:
      the Principal; null if this request has not been authenticated o.
    • getQueryString

      public String getQueryString()
      Description copied from interface: HttpServerRequest
      Return the query string
      Specified by:
      getQueryString in interface HttpServerRequest
      Returns:
      the query string
    • getCookies

      public ServerCookie[] getCookies()
      Description copied from interface: HttpServerRequest
      Get the cookies for this request.
      Specified by:
      getCookies in interface HttpServerRequest
      Returns:
      a list of cookies
    • getLocale

      public Locale getLocale()
      Description copied from interface: HttpServerRequest
      Get the preferred locale for this request. The locale is chosen based on the Accept-Language header.
      Specified by:
      getLocale in interface HttpServerRequest
      Returns:
      the preferred locale
    • getLocales

      public Enumeration<Locale> getLocales()
      Get the locales provided by the Accept-Language header, ordered by preference, highest preference first.

      Note: an enumeration is returned instead of an iterator for compatibility with the servlet specification.

      Specified by:
      getLocales in interface HttpServerRequest
      Returns:
      an enumeration for these locales
    • getHeader

      public String getHeader(String type)
      Description copied from interface: HttpServerRequest
      Get the value of the request header for the specified type. If there are more then one header with the same type (or name), the first will be returned
      Specified by:
      getHeader in interface HttpServerRequest
      Parameters:
      type - the type (or name) of the header.
      Returns:
      the value of the header; null if there is no values for this type
    • getHeaderNames

      public Enumeration<String> getHeaderNames()
      Description copied from interface: HttpServerRequest
      Get an enumeration of all request-header names.
      Specified by:
      getHeaderNames in interface HttpServerRequest
      Returns:
      an enumeration of the names of the request headers; null if not supported
    • getHeaders

      public Enumeration<String> getHeaders(String type)
      Description copied from interface: HttpServerRequest
      Get the values of the request headers for the specified type. The enumeration will contain a single element if there is only a single header with specified type. With multiple headers, each header's value is separate element in the enumeration.

      Note: an enumeration is returned for compatibility with the servlet specification

      Specified by:
      getHeaders in interface HttpServerRequest
      Parameters:
      type - the type or name of the header.
      Returns:
      an enumeration containing the values of the header; null if there are no values for this type
    • isUserInRole

      public boolean isUserInRole(String role)
      Description copied from interface: HttpServerRequest
      Determine if a user is in a specified role. If roles have not been implemented, this method returns false.
      Specified by:
      isUserInRole in interface HttpServerRequest
      Parameters:
      role - the role
      Returns:
      true if the user is in a specified role; false otherwise
    • getContentType

      public String getContentType()
      Get the content type.
      Specified by:
      getContentType in interface HttpServerRequest
      Returns:
      the media type for the content of a request
    • getCharacterEncoding

      public String getCharacterEncoding()
      Description copied from interface: HttpServerRequest
      Get the content-type's character encoding
      Specified by:
      getCharacterEncoding in interface HttpServerRequest
      Returns:
      the character encoding; null if not specified or not applicable
    • getMediaType

      public String getMediaType()
      Description copied from interface: HttpServerRequest
      Get the media type (content type) without any of its parameters.
      Specified by:
      getMediaType in interface HttpServerRequest
      Returns:
      the media type without any of its parameters
    • getFromHeader

      public String getFromHeader(String key, String parameter)
      Description copied from interface: HttpServerRequest
      Extract parameters from a request header. This method assumes that a header contains a single value and that multiple values would be separated by commas.
      Specified by:
      getFromHeader in interface HttpServerRequest
      Parameters:
      key - the name of the header (e.g., "content-type")
      parameter - the name of a header parameter (e.g., "charset"); null for the header without its parameters
      Returns:
      the value with quotes and character escapes processed
    • getContentLength

      public int getContentLength()
      Description copied from interface: HttpServerRequest
      Get the content length. The content length (more or less) is the length in bytes of the content including any content encoding. If compression is used, the content length should be considered to be an estimate of the length, perhaps off by some factor. It can be useful in this case for estimating the size of a ByteArrayBuffer or similar Java classes that can grow if needed but start with an initial size.
      Specified by:
      getContentLength in interface HttpServerRequest
      Returns:
      the length of the content; -1 if not known.
    • getContentLengthLong

      public long getContentLengthLong()
      Description copied from interface: HttpServerRequest
      Get the content length as a long integer. The content length (more or less) is the length in bytes of the content including any content encoding. If compression is used, the content length should be considered to be an estimate of the length, perhaps off by some factor. It can be useful in this case for estimating the size of a ByteArrayBuffer or similar Java classes that can grow if needed but start with an initial size.
      Specified by:
      getContentLengthLong in interface HttpServerRequest
      Returns:
      the length of the content; -1 if not known.
    • getEncodedInputStream

      public InputStream getEncodedInputStream()
      Description copied from interface: HttpServerRequest
      Get an input stream that will read data in a request without content decoding. This method is useful when the content will be stored as is - e.g., with compression. One may call HttpServerRequest.getEncodedInputStream() or HttpServerRequest.getDecodedInputStream() but not both. If either is called multiple times, the same input stream will be returned and it may be in a partially-read state. Regardless of which method is used, the stream should be fully read: otherwise the server, or at least the current transaction, may hang.

      When implemented for a servlet, this method should just return the servlet request's getInputStream() method and ensure that HttpServerRequest.getDecodedInputStream() will return null;

      Specified by:
      getEncodedInputStream in interface HttpServerRequest
      Returns:
      the input stream; null if not available
    • getDecodedInputStream

      public InputStream getDecodedInputStream()
      Description copied from interface: HttpServerRequest
      Get an input stream that will read data in a request with content decoding. Any compression (gzip or deflate) will be removed. One may call HttpServerRequest.getEncodedInputStream() or HttpServerRequest.getDecodedInputStream() but not both. If either is called multiple times, the same input stream will be returned and it may be in a partially-read state. Regardless of which method is used, the stream should be fully read: otherwise the server, or at least the current transaction, may hang.

      In a servlet implementation, the following code fragment can be used in implementing this method:

      
           // Need to check that we don't already have a stream.
           // If we don't ...
           String encoding = servletRequest.getHeader("content-encoding");
           InputStream is = servletRequest.getInputStream();
           if (encoding.equalsIgnoreCase("identity")) {
               // nothing to do
           } else if (encoding.equalsIgnoreCase("gzip")) {
               is = new java.util.zip.GZIPInputStream(is);
           } else if (encoding.equalsIgnoreCase("deflate")) {
               is = new java.util.zip.InflaterInputStream(is);
           } else {
             is = null;
           }
           // after adding some bookkeeping to track if we have a stream
           return is;
       
      Specified by:
      getDecodedInputStream in interface HttpServerRequest
      Returns:
      the input stream; null if not available
    • isSecure

      public boolean isSecure()
      Description copied from interface: HttpServerRequest
      Determine if the request was made over a secure channel. Note: the test is usually based on the protocol being used, not how it is configured.
      Specified by:
      isSecure in interface HttpServerRequest
      Returns:
      if the channel is secure; false otherwise
    • getParameterMap

      public Map<String,String[]> getParameterMap()
      Description copied from interface: HttpServerRequest
      Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP, parameters are contained in a URL's query string or posted form data with content type application/x-www-form-urlencoded.
      Specified by:
      getParameterMap in interface HttpServerRequest
      Returns:
      an immutable java.util.Map containing parameter names as keys and parameter values as map values.