java.lang.Object
org.bzdev.ejws.WebMap.RequestInfo
- All Implemented Interfaces:
HttpServerRequest
- Enclosing class:
- WebMap
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 methodgetDecodedInputStream()
provides an input stream that will decompress the data if necessary. When the actual data is used, this method is preferred.
-
Method Summary
Modifier and TypeMethodDescriptionChange the current session's ID.getAttribute
(String name) Get an attribute.Get the content-type's character encodingint
Get the content length.long
Get the content length as a long integer.Get the content type.getContextAttribute
(String name) Get a context attribute.Get the cookies for this request.Get an input stream that will read data in a request with content decoding.Get an input stream that will read data in a request without content decoding.getFromHeader
(String key, String parameter) Extract parameters from a request header.Get the value of the request header for the specified type.Get an enumeration of all request-header names.getHeaders
(String type) Get the values of the request headers for the specified type.Get the preferred locale for this request.Get the locales provided by the Accept-Language header, ordered by preference, highest preference first.int
Get the maximum inactive interval for this request's session.Get the media type (content type) without any of its parameters.Get the request method.Returns a java.util.Map of the parameters of this request.Get the protocol used in the request.Return the query stringReturn the IP (Internet Protocol) address of the client, last proxy, or router/switch using NAT (Network Address Translation), that sent this request.Get the session ID specified by a client; The default assumes that session IDs have not been implemented.Get the request URI.Get the URL sent by the client.Get the current session state.Get the Principal for the user authenticating this request.boolean
Determines if the requested session ID is valid.boolean
isSecure()
Determine if the request was made over a secure channel.boolean
isUserInRole
(String role) Determine if a user is in a specified role.void
setAttribute
(String name, Object value) Set an attribute.void
setContextAttribute
(String name, Object value) Set a context attribute.boolean
setMaxInactiveInterval
(int interval) Set the maximum inactive interval for this request's session.void
setSessionState
(Object state) Set the current session's state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.net.HttpServerRequest
getContextPath, getDateHeader, getIntHeader, getParameter, getParameterNames, getParameterNameSet, getParameterValues
-
Method Details
-
getAttribute
Description copied from interface:HttpServerRequest
Get an attribute.- Specified by:
getAttribute
in interfaceHttpServerRequest
- Parameters:
name
- the attribute name- Returns:
- the attribute
-
setAttribute
Description copied from interface:HttpServerRequest
Set an attribute.- Specified by:
setAttribute
in interfaceHttpServerRequest
- Parameters:
name
- the attribute namevalue
- the attribute value
-
getContextAttribute
Description copied from interface:HttpServerRequest
Get a context attribute. A context is an instance ofHttpContext
when usingEmbeddedWebServer
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 interfaceHttpServerRequest
- Parameters:
name
- the attribute name- Returns:
- the attribute
-
setContextAttribute
Description copied from interface:HttpServerRequest
Set a context attribute. A context is an instance ofHttpContext
when usingEmbeddedWebServer
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 interfaceHttpServerRequest
- Parameters:
name
- the attribute namevalue
- the attribute value
-
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 interfaceHttpServerRequest
- Returns:
- the session ID; null if there is none
-
changeSessionID
Description copied from interface:HttpServerRequest
Change the current session's ID.- Specified by:
changeSessionID
in interfaceHttpServerRequest
- Returns:
- the new session ID
- Throws:
IllegalStateException
- a session does not exist
-
setSessionState
Description copied from interface:HttpServerRequest
Set the current session's state.- Specified by:
setSessionState
in interfaceHttpServerRequest
- Parameters:
state
- the session state- Throws:
IllegalStateException
- the session does not exist
-
getSessionState
Description copied from interface:HttpServerRequest
Get the current session state.- Specified by:
getSessionState
in interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- Returns:
- the maximum inactive interval in seconds; 0 if no timeout; -1 if there is no session
-
getMethod
Description copied from interface:HttpServerRequest
Get the request method.- Specified by:
getMethod
in interfaceHttpServerRequest
- Returns:
- the method.
-
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 interfaceHttpServerRequest
- Returns:
- the request URI
-
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 interfaceHttpServerRequest
- Returns:
- the URL
-
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 interfaceHttpServerRequest
- Returns:
- the address
-
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 interfaceHttpServerRequest
- Returns:
- the protocol in the form PROTOCOL/MAJOR.MINOR
-
getUserPrincipal
Description copied from interface:HttpServerRequest
Get the Principal for the user authenticating this request.- Specified by:
getUserPrincipal
in interfaceHttpServerRequest
- Returns:
- the Principal; null if this request has not been authenticated o.
-
getQueryString
Description copied from interface:HttpServerRequest
Return the query string- Specified by:
getQueryString
in interfaceHttpServerRequest
- Returns:
- the query string
-
getCookies
Description copied from interface:HttpServerRequest
Get the cookies for this request.- Specified by:
getCookies
in interfaceHttpServerRequest
- Returns:
- a list of cookies
-
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 interfaceHttpServerRequest
- Returns:
- the preferred 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 interfaceHttpServerRequest
- Returns:
- an enumeration for these locales
-
getHeader
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 interfaceHttpServerRequest
- 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
Description copied from interface:HttpServerRequest
Get an enumeration of all request-header names.- Specified by:
getHeaderNames
in interfaceHttpServerRequest
- Returns:
- an enumeration of the names of the request headers; null if not supported
-
getHeaders
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 interfaceHttpServerRequest
- 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
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 interfaceHttpServerRequest
- Parameters:
role
- the role- Returns:
- true if the user is in a specified role; false otherwise
-
getContentType
Get the content type.- Specified by:
getContentType
in interfaceHttpServerRequest
- Returns:
- the media type for the content of a request
-
getCharacterEncoding
Description copied from interface:HttpServerRequest
Get the content-type's character encoding- Specified by:
getCharacterEncoding
in interfaceHttpServerRequest
- Returns:
- the character encoding; null if not specified or not applicable
-
getMediaType
Description copied from interface:HttpServerRequest
Get the media type (content type) without any of its parameters.- Specified by:
getMediaType
in interfaceHttpServerRequest
- Returns:
- the media type without any of its parameters
-
getFromHeader
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 interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- Returns:
- the length of the content; -1 if not known.
-
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 callHttpServerRequest.getEncodedInputStream()
orHttpServerRequest.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 interfaceHttpServerRequest
- Returns:
- the input stream; null if not available
-
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 callHttpServerRequest.getEncodedInputStream()
orHttpServerRequest.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 interfaceHttpServerRequest
- 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 interfaceHttpServerRequest
- Returns:
- if the channel is secure; false otherwise
-
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 interfaceHttpServerRequest
- Returns:
- an immutable java.util.Map containing parameter names as keys and parameter values as map values.
-