public class RequestWrapper extends java.lang.Object implements Request
RequestWrapper
object is used so that the original
Request
object can be wrapped in a filtering proxy
object. This allows a Container
that interacts with
a modified request object. To add functionality to the request it
can be wrapped in a subclass of this and the overridden methods
can provide modified functionality to the standard request.Modifier and Type | Field and Description |
---|---|
protected Request |
request
This is the request instance that is being wrapped.
|
Constructor and Description |
---|
RequestWrapper(Request request)
Constructor for
RequestWrapper object. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(java.lang.String name)
This is used to see if there is a HTTP message header with the
given name in this container.
|
Address |
getAddress()
This is used to acquire the address from the request line.
|
java.lang.Object |
getAttribute(java.lang.Object key)
This is used as a shortcut for acquiring attributes for the
response.
|
java.util.Map |
getAttributes()
This can be used to retrieve the response attributes.
|
java.nio.channels.ReadableByteChannel |
getByteChannel()
This is used to read the content body.
|
java.net.InetSocketAddress |
getClientAddress()
This is used to acquire the remote client address.
|
java.lang.String |
getContent()
This is used to get the content body.
|
int |
getContentLength()
This is a convenience method that can be used to determine
the length of the message body.
|
ContentType |
getContentType()
This is a convenience method that can be used to determine the
content type of the message body.
|
Cookie |
getCookie(java.lang.String name)
This is used to acquire a cookie usiing the name of that cookie.
|
java.util.List<Cookie> |
getCookies()
This is used to acquire all cookies that were sent in the header.
|
long |
getDate(java.lang.String name)
This can be used to get the date of the first message header
that has the specified name.
|
Form |
getForm()
This is used to acquire all the form parameters from the
HTTP request.
|
java.io.InputStream |
getInputStream()
This is used to read the content body.
|
int |
getInteger(java.lang.String name)
This can be used to get the integer of the first message header
that has the specified name.
|
java.util.List<java.util.Locale> |
getLocales()
This is used to acquire the locales from the request header.
|
int |
getMajor()
This can be used to get the major number from a HTTP version.
|
java.lang.String |
getMethod()
This can be used to get the HTTP method for this request.
|
int |
getMinor()
This can be used to get the major number from a HTTP version.
|
java.util.List<java.lang.String> |
getNames()
This method is used to get a
List of the names
for the headers. |
java.lang.String |
getParameter(java.lang.String name)
This is used to provide quick access to the parameters.
|
Part |
getPart(java.lang.String name)
This method is used to acquire a
Part from the
form using a known name for the part. |
Path |
getPath()
This is used to acquire the path as extracted from the HTTP
request URI.
|
Query |
getQuery()
This method is used to acquire the query part from the
HTTP request URI target.
|
Session |
getSession()
This method is used to acquire a
Session for the
request. |
Session |
getSession(boolean create)
This method is used to acquire a
Session for the
request. |
java.lang.String |
getTarget()
This can be used to get the URI specified for this HTTP request.
|
java.lang.String |
getValue(java.lang.String name)
This can be used to get the value of the first message header
that has the specified name.
|
java.util.List<java.lang.String> |
getValues(java.lang.String name)
This can be used to get the values of HTTP message headers
that have the specified name.
|
boolean |
isKeepAlive()
This is a convenience method that is used to determine whether
or not this message has the
Connection: close
header. |
boolean |
isSecure()
This is used to determine if the request has been transferred
over a secure connection.
|
protected Request request
public RequestWrapper(Request request)
RequestWrapper
object. This allows
the original Request
object to be wrapped so that
adjustments to the behavior of a request object handed to the
container can be provided by a subclass implementation.request
- the request object that is being wrappedpublic int getMajor()
getMajor
in interface RequestLine
public int getMinor()
getMinor
in interface RequestLine
public java.lang.String getMethod()
getMethod
in interface RequestLine
public java.lang.String getTarget()
getTarget
in interface RequestLine
public Address getAddress()
getAddress
in interface RequestLine
public Path getPath()
Path
object that is provided by
this method is immutable, it represents the normalized path
only part from the request uniform resource identifier.getPath
in interface RequestLine
public Query getQuery()
getQuery
in interface RequestLine
public java.util.List<java.lang.String> getNames()
List
of the names
for the headers. This will provide the original names for the
HTTP headers for the message. Modifications to the provided
list will not affect the header, the list is a simple copy.getNames
in interface RequestHeader
public int getInteger(java.lang.String name)
getInteger
in interface RequestHeader
name
- the HTTP message header to get the value frompublic long getDate(java.lang.String name)
getDate
in interface RequestHeader
name
- the HTTP message header to get the value frompublic Cookie getCookie(java.lang.String name)
Cookie
object. Otherwise this method will
return null. Each cookie object will contain the name, value
and path of the cookie as well as the optional domain part.getCookie
in interface RequestHeader
name
- this is the name of the cookie object to acquirepublic java.util.List<Cookie> getCookies()
Cookie
objects. Otherwise this method will an
empty list. Each cookie object will contain the name, value and
path of the cookie as well as the optional domain part.getCookies
in interface RequestHeader
public java.lang.String getValue(java.lang.String name)
getValue
in interface RequestHeader
name
- the HTTP message header to get the value frompublic java.util.List<java.lang.String> getValues(java.lang.String name)
substring
and trim
calls.
The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearence.
The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has higest preference.
getValues
in interface RequestHeader
name
- the name of the headers that are to be retrievedpublic java.util.List<java.util.Locale> getLocales()
Accept-Language
header.
This provides an indication as to the languages that the client
accepts. It provides the locales in preference order.getLocales
in interface RequestHeader
public boolean contains(java.lang.String name)
contains
in interface RequestHeader
name
- the HTTP message header to get the value frompublic ContentType getContentType()
Content-Type
header, if there is then
this will parse that header and represent it as a typed object
which will expose the various parts of the HTTP header.getContentType
in interface RequestHeader
public int getContentLength()
Content-Length
header, if it does then the
length can be determined, if not then this returns -1.getContentLength
in interface RequestHeader
public boolean isSecure()
public boolean isKeepAlive()
Connection: close
header. If the close token is present then this stream is not
a keep-alive connection. If this has no Connection
header then the keep-alive status is determined by the HTTP
version, that is, HTTP/1.1 is keep-alive by default, HTTP/1.0
is not keep-alive by default.isKeepAlive
in interface Request
public java.util.Map getAttributes()
getAttributes
in interface Request
public java.lang.Object getAttribute(java.lang.Object key)
Map
in order to retrieve the attribute directly from that object.
The attributes contain data specific to the response.getAttribute
in interface Request
key
- this is the key of the attribute to acquirepublic java.net.InetSocketAddress getClientAddress()
getClientAddress
in interface Request
public java.lang.String getContent() throws java.io.IOException
getContent
in interface Request
java.io.IOException
- signifies that there is an I/O problempublic java.io.InputStream getInputStream() throws java.io.IOException
InputStream
can be determined
by the getContentLength
method. If the data sent by
the client is chunked then it is decoded, see RFC 2616 section
3.6. Also multipart data is available as Part
objects
however the raw content of the multipart body is still available.getInputStream
in interface Request
java.lang.Exception
- signifies that there is an I/O problemjava.io.IOException
public java.nio.channels.ReadableByteChannel getByteChannel() throws java.io.IOException
ReadableByteChannel
can be
determined by the getContentLength
method. If the
data sent by the client is chunked then it is decoded, see RFC
2616 section 3.6. This stream will never provide empty reads as
the content is internally buffered, so this can do a full read.getByteChannel
in interface Request
java.io.IOException
public Session getSession() throws LeaseException
Session
for the
request. The object retrieved provides a container for data
associated to the connected client. This allows the request
to perform more complex operations based on knowledge that is
built up through a series of requests. The session is known
to the system using a Cookie
, which contains
the session reference. This cookie value should not be
modified as it used to reference the active session object.getSession
in interface Request
LeaseException
public Session getSession(boolean create) throws LeaseException
Session
for the
request. The object retrieved provides a container for data
associated to the connected client. This allows the request
to perform more complex operations based on knowledge that is
built up through a series of requests. The session is known
to the system using a Cookie
, which contains
the session reference. This cookie value should not be
modified as it used to reference the active session object.getSession
in interface Request
create
- creates the session if it does not existLeaseException
public Form getForm() throws java.io.IOException
public java.lang.String getParameter(java.lang.String name) throws java.io.IOException
Form
object.
This basically acquires the parameters object and invokes
the getParameters
method with the given name.getParameter
in interface Request
name
- this is the name of the parameter valuejava.io.IOException
- thrown if there is an I/O problempublic Part getPart(java.lang.String name) throws java.io.IOException
Part
from the
form using a known name for the part. This is typically used
when there is a file upload with a multipart POST request.
All parts that are not files are added to the query values
as strings so that they can be used in a convenient way.