public class RequestWrapper extends 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 |
---|---|
Address |
getAddress()
This is used to acquire the address from the request line.
|
Object |
getAttribute(Object key)
This is used as a shortcut for acquiring attributes for the
response.
|
Map |
getAttributes()
This can be used to retrieve the response attributes.
|
ReadableByteChannel |
getByteChannel()
This is used to read the content body.
|
Channel |
getChannel()
This provides the underlying channel for the request.
|
InetSocketAddress |
getClientAddress()
This is used to acquire the remote client address.
|
Certificate |
getClientCertificate()
This is used to acquire the SSL certificate used when the
server is using a HTTPS connection.
|
String |
getContent()
This is used to get the content body.
|
long |
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(String name)
This is used to acquire a cookie usiing the name of that cookie.
|
List<Cookie> |
getCookies()
This is used to acquire all cookies that were sent in the header.
|
long |
getDate(String name)
This can be used to get the date of the first message header
that has the specified name.
|
CharSequence |
getHeader()
This method returns a
CharSequence holding the header
consumed for the request. |
InputStream |
getInputStream()
This is used to read the content body.
|
int |
getInteger(String name)
This can be used to get the integer of the first message header
that has the specified name.
|
List<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.
|
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.
|
List<String> |
getNames()
This method is used to get a
List of the names
for the headers. |
String |
getParameter(String name)
This is used to provide quick access to the parameters.
|
Part |
getPart(String name)
This method is used to acquire a
Part from the
HTTP request using a known name for the part. |
List<Part> |
getParts()
This method is used to get all
Part objects that
are associated with the request. |
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 and a form post if it exists.
|
long |
getRequestTime()
This is the time in milliseconds when the request was first
read from the underlying socket.
|
String |
getTarget()
This can be used to get the URI specified for this HTTP request.
|
String |
getValue(String name)
This can be used to get the value of the first message header
that has the specified name.
|
String |
getValue(String name,
int index)
This can be used to get the value of the first message header
that has the specified name.
|
List<String> |
getValues(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.
|
String |
toString()
This method returns a string representing the header that was
consumed for this request.
|
protected Request request
public RequestWrapper(Request request)
RequestWrapper
object. This allows
the original Request
object to be wrapped so that
adjustments to the behaviour 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 String getMethod()
getMethod
in interface RequestLine
public 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 List<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(String name)
getInteger
in interface RequestHeader
name
- the HTTP message header to get the value frompublic long getDate(String name)
getDate
in interface RequestHeader
name
- the HTTP message header to get the value frompublic Cookie getCookie(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 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 String getValue(String name)
getValue
in interface RequestHeader
name
- the HTTP message header to get the value frompublic String getValue(String name, int index)
getValue
in interface RequestHeader
name
- the HTTP message header to get the value fromindex
- if there are multiple values this selects onepublic List<String> getValues(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 List<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 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 long 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 long getRequestTime()
getRequestTime
in interface Request
public Channel getChannel()
getChannel
in interface Request
public Certificate getClientCertificate()
getClientCertificate
in interface Request
public Map getAttributes()
getAttributes
in interface Request
public Object getAttribute(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 InetSocketAddress getClientAddress()
getClientAddress
in interface Request
public CharSequence getHeader()
CharSequence
holding the header
consumed for the request. A character sequence is returned as it
can provide a much more efficient means of representing the header
data by just wrapping the consumed byte array.getHeader
in interface RequestHeader
public String getContent() throws IOException
getContent
in interface Request
IOException
- signifies that there is an I/O problempublic InputStream getInputStream() throws 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
Exception
- signifies that there is an I/O problemIOException
public ReadableByteChannel getByteChannel() throws 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
IOException
public String getParameter(String name)
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 valuepublic Part getPart(String name)
Part
from the
HTTP request 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 can be acquired as string values
from the attachment object.public List<Part> getParts()
Part
objects that
are associated with the request. Each attachment contains the
body and headers associated with it. If the request is not a
multipart POST request then this will return an empty list.public String toString()
toString
in interface RequestHeader
toString
in class Object
Copyright © 2024. All rights reserved.