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 encodingintGet the content length.longGet 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.intGet 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.booleanDetermines if the requested session ID is valid.booleanisSecure()Determine if the request was made over a secure channel.booleanisUserInRole(String role) Determine if a user is in a specified role.voidsetAttribute(String name, Object value) Set an attribute.voidsetContextAttribute(String name, Object value) Set a context attribute.booleansetMaxInactiveInterval(int interval) Set the maximum inactive interval for this request's session.voidsetSessionState(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, waitMethods inherited from interface org.bzdev.net.HttpServerRequest
getContextPath, getDateHeader, getIntHeader, getParameter, getParameterNames, getParameterNameSet, getParameterValues
-
Method Details
-
getAttribute
Description copied from interface:HttpServerRequestGet an attribute.- Specified by:
getAttributein interfaceHttpServerRequest- Parameters:
name- the attribute name- Returns:
- the attribute
-
setAttribute
Description copied from interface:HttpServerRequestSet an attribute.- Specified by:
setAttributein interfaceHttpServerRequest- Parameters:
name- the attribute namevalue- the attribute value
-
getContextAttribute
Description copied from interface:HttpServerRequestGet a context attribute. A context is an instance ofHttpContextwhen usingEmbeddedWebServerand ServletContext when using a servlet (see the the Jarkarta Servlet API v4.0.3 for a description of this class).- Specified by:
getContextAttributein interfaceHttpServerRequest- Parameters:
name- the attribute name- Returns:
- the attribute
-
setContextAttribute
Description copied from interface:HttpServerRequestSet a context attribute. A context is an instance ofHttpContextwhen usingEmbeddedWebServerand ServletContext when using a servlet (see the the Jarkarta Servlet API v4.0.3 for a description of this class).- Specified by:
setContextAttributein interfaceHttpServerRequest- Parameters:
name- the attribute namevalue- the attribute value
-
getRequestedSessionID
Description copied from interface:HttpServerRequestGet the session ID specified by a client; The default assumes that session IDs have not been implemented.- Specified by:
getRequestedSessionIDin interfaceHttpServerRequest- Returns:
- the session ID; null if there is none
-
changeSessionID
Description copied from interface:HttpServerRequestChange the current session's ID.- Specified by:
changeSessionIDin interfaceHttpServerRequest- Returns:
- the new session ID
- Throws:
IllegalStateException- a session does not exist
-
setSessionState
Description copied from interface:HttpServerRequestSet the current session's state.- Specified by:
setSessionStatein interfaceHttpServerRequest- Parameters:
state- the session state- Throws:
IllegalStateException- the session does not exist
-
getSessionState
Description copied from interface:HttpServerRequestGet the current session state.- Specified by:
getSessionStatein interfaceHttpServerRequest- Returns:
- the session state; null if one does not exist.
-
isRequestedSessionIDValid
public boolean isRequestedSessionIDValid()Description copied from interface:HttpServerRequestDetermines if the requested session ID is valid. The default assumes that session IDs have not been implemented and thus returns false.- Specified by:
isRequestedSessionIDValidin interfaceHttpServerRequest- Returns:
- true if the current session ID is valid; false otherwise
-
setMaxInactiveInterval
public boolean setMaxInactiveInterval(int interval) Description copied from interface:HttpServerRequestSet the maximum inactive interval for this request's session.- Specified by:
setMaxInactiveIntervalin 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:HttpServerRequestGet the maximum inactive interval for this request's session.- Specified by:
getMaxInactiveIntervalin interfaceHttpServerRequest- Returns:
- the maximum inactive interval in seconds; 0 if no timeout; -1 if there is no session
-
getMethod
Description copied from interface:HttpServerRequestGet the request method.- Specified by:
getMethodin interfaceHttpServerRequest- Returns:
- the method.
-
getRequestURI
Description copied from interface:HttpServerRequestGet 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:
getRequestURIin interfaceHttpServerRequest- Returns:
- the request URI
-
getRequestURL
Description copied from interface:HttpServerRequestGet the URL sent by the client. The URL is reconstructed based on server information.- Specified by:
getRequestURLin interfaceHttpServerRequest- Returns:
- the URL
-
getRemoteAddr
Description copied from interface:HttpServerRequestReturn the IP (Internet Protocol) address of the client, last proxy, or router/switch using NAT (Network Address Translation), that sent this request.- Specified by:
getRemoteAddrin interfaceHttpServerRequest- Returns:
- the address
-
getProtocol
Description copied from interface:HttpServerRequestGet the protocol used in the request. For example, HTTP/1.1 for HTTP version 1.1- Specified by:
getProtocolin interfaceHttpServerRequest- Returns:
- the protocol in the form PROTOCOL/MAJOR.MINOR
-
getUserPrincipal
Description copied from interface:HttpServerRequestGet the Principal for the user authenticating this request.- Specified by:
getUserPrincipalin interfaceHttpServerRequest- Returns:
- the Principal; null if this request has not been authenticated o.
-
getQueryString
Description copied from interface:HttpServerRequestReturn the query string- Specified by:
getQueryStringin interfaceHttpServerRequest- Returns:
- the query string
-
getCookies
Description copied from interface:HttpServerRequestGet the cookies for this request.- Specified by:
getCookiesin interfaceHttpServerRequest- Returns:
- a list of cookies
-
getLocale
Description copied from interface:HttpServerRequestGet the preferred locale for this request. The locale is chosen based on the Accept-Language header.- Specified by:
getLocalein 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:
getLocalesin interfaceHttpServerRequest- Returns:
- an enumeration for these locales
-
getHeader
Description copied from interface:HttpServerRequestGet 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:
getHeaderin 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:HttpServerRequestGet an enumeration of all request-header names.- Specified by:
getHeaderNamesin interfaceHttpServerRequest- Returns:
- an enumeration of the names of the request headers; null if not supported
-
getHeaders
Description copied from interface:HttpServerRequestGet 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:
getHeadersin 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:HttpServerRequestDetermine if a user is in a specified role. If roles have not been implemented, this method returns false.- Specified by:
isUserInRolein interfaceHttpServerRequest- Parameters:
role- the role- Returns:
- true if the user is in a specified role; false otherwise
-
getContentType
Get the content type.- Specified by:
getContentTypein interfaceHttpServerRequest- Returns:
- the media type for the content of a request
-
getCharacterEncoding
Description copied from interface:HttpServerRequestGet the content-type's character encoding- Specified by:
getCharacterEncodingin interfaceHttpServerRequest- Returns:
- the character encoding; null if not specified or not applicable
-
getMediaType
Description copied from interface:HttpServerRequestGet the media type (content type) without any of its parameters.- Specified by:
getMediaTypein interfaceHttpServerRequest- Returns:
- the media type without any of its parameters
-
getFromHeader
Description copied from interface:HttpServerRequestExtract 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:
getFromHeaderin 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:HttpServerRequestGet 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:
getContentLengthin interfaceHttpServerRequest- Returns:
- the length of the content; -1 if not known.
-
getContentLengthLong
public long getContentLengthLong()Description copied from interface:HttpServerRequestGet 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:
getContentLengthLongin interfaceHttpServerRequest- Returns:
- the length of the content; -1 if not known.
-
getEncodedInputStream
Description copied from interface:HttpServerRequestGet 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:
getEncodedInputStreamin interfaceHttpServerRequest- Returns:
- the input stream; null if not available
-
getDecodedInputStream
Description copied from interface:HttpServerRequestGet 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:
getDecodedInputStreamin interfaceHttpServerRequest- Returns:
- the input stream; null if not available
-
isSecure
public boolean isSecure()Description copied from interface:HttpServerRequestDetermine 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:
isSecurein interfaceHttpServerRequest- Returns:
- if the channel is secure; false otherwise
-
getParameterMap
Description copied from interface:HttpServerRequestReturns 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:
getParameterMapin interfaceHttpServerRequest- Returns:
- an immutable java.util.Map containing parameter names as keys and parameter values as map values.
-