public class Request extends Object
Modifier and Type | Field and Description |
---|---|
protected List<AfterServiceListener> |
afterServicesList |
protected Cookie[] |
cookies
The set of cookies associated with this Request.
|
protected boolean |
cookiesParsed
Cookies parsed flag.
|
protected FilterChainContext |
ctx |
protected static Locale |
defaultLocale
The default Locale if none are specified.
|
protected Object |
dispatcherType
The current dispatcher type.
|
protected HttpServerFilter |
httpServerFilter |
protected InputBuffer |
inputBuffer
The associated input buffer.
|
protected ArrayList<Locale> |
locales
The preferred Locales associated with this Request.
|
protected boolean |
localesParsed
Parse locales.
|
protected ParameterMap |
parameterMap
Hash map used in the getParametersMap method.
|
protected Parameters |
parameters |
protected Cookies |
rawCookies |
protected HttpRequestPacket |
request
HTTP Request Packet
|
protected Object |
requestDispatcherPath
The current request dispatcher path.
|
protected boolean |
requestedSessionCookie
Was the requested session ID received in a cookie?
|
protected String |
requestedSessionId
The requested session ID (if any) for this request.
|
protected boolean |
requestedSessionURL
Was the requested session ID received in a URL?
|
protected boolean |
requestParametersParsed
Request parameters parsed flag.
|
protected Response |
response
The response with which this request is associated.
|
protected boolean |
secure
Secure flag.
|
static String |
SEND_FILE_ATTR
The value of this request attribute, as set by the developer must be a
File
that exists, is not a directory, and is readable. |
static String |
SEND_FILE_ENABLED_ATTR
Request attribute will be associated with a boolean value indicating
whether or not it's possible to transfer a
File using sendfile. |
static String |
SEND_FILE_START_OFFSET_ATTR
The value of this request attribute signifies the starting offset of the file
transfer.
|
static String |
SEND_FILE_WRITE_LEN_ATTR
The value of this request attribute signifies the total number of bytes to
transfer.
|
protected boolean |
sessionParsed
Session parsed flag.
|
protected Subject |
subject
The Subject associated with the current AccessControllerContext
|
protected Principal |
userPrincipal
User principal.
|
protected boolean |
usingInputStream
Using stream flag.
|
protected boolean |
usingReader
Using writer flag.
|
Modifier | Constructor and Description |
---|---|
protected |
Request(Response response) |
Modifier and Type | Method and Description |
---|---|
void |
addAfterServiceListener(AfterServiceListener listener)
Add the listener, which will be notified, once Request processing will be finished.
|
void |
addCookie(Cookie cookie)
Add a Cookie to the set of Cookies associated with this Request.
|
void |
addLocale(Locale locale)
Add a Locale to the set of preferred Locales for this Request.
|
void |
addParameter(String name,
String[] values)
Add a parameter name and corresponding set of values to this Request.
|
static StringBuffer |
appendRequestURL(Request request,
StringBuffer buffer)
Appends the reconstructed URL the client used to make the request.
|
static StringBuilder |
appendRequestURL(Request request,
StringBuilder buffer)
Appends the reconstructed URL the client used to make the request.
|
boolean |
asyncInput()
Deprecated.
will always return true
|
String |
changeSessionId()
Change the session id of the current session associated with this
request and return the new session id.
|
void |
clearCookies()
Clear the collection of Cookies associated with this Request.
|
void |
clearHeaders()
Clear the collection of Headers associated with this Request.
|
void |
clearLocales()
Clear the collection of Locales associated with this Request.
|
void |
clearParameters()
Clear the collection of parameters associated with this Request.
|
protected void |
configureSessionCookie(Cookie cookie)
Configures the given JSESSIONID cookie.
|
static Request |
create() |
NIOInputStream |
createInputStream()
Create and return a NIOInputStream to read the content
associated with this Request.
|
static <E> Note<E> |
createNote(String name)
Create a named
Note associated with this Request. |
int |
decrementDispatchDepth()
Decrement the depth of application dispatch
|
protected Session |
doGetSession(boolean create) |
Object |
getAttribute(String name)
Return the specified request attribute if it exists; otherwise, return
null . |
Set<String> |
getAttributeNames()
Return the names of all request attributes for this Request, or an
empty
Set if there are none. |
String |
getAuthorization()
Return the authorization credentials sent with this request.
|
String |
getAuthType()
Return the authentication type used for this Request.
|
String |
getCharacterEncoding()
Return the character encoding for this Request.
|
int |
getContentLength()
Return the content length for this Request.
|
long |
getContentLengthLong()
Return the content length for this Request represented by Java long type.
|
String |
getContentType()
Return the content type for this Request.
|
FilterChainContext |
getContext() |
String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request.
|
Cookie[] |
getCookies()
Return the set of Cookies received with this Request.
|
long |
getDateHeader(Header header)
Return the value of the specified date header, if any; otherwise
return -1.
|
long |
getDateHeader(String name)
Return the value of the specified date header, if any; otherwise
return -1.
|
String |
getDecodedRequestURI()
Get the decoded request URI.
|
String |
getHeader(Header header)
Return the first value of the specified header, if any; otherwise,
return
null |
String |
getHeader(String name)
Return the first value of the specified header, if any; otherwise,
return
null |
Iterable<String> |
getHeaderNames()
Return the names of all headers received with this request.
|
Iterable<String> |
getHeaders(Header header)
Return all of the values of the specified header, if any; otherwise,
return an empty enumeration.
|
Iterable<String> |
getHeaders(String name)
Return all of the values of the specified header, if any; otherwise,
return an empty enumeration.
|
HttpServerFilter |
getHttpFilter()
Returns
HttpServerFilter , which dispatched this request. |
String |
getHttpHandlerPath()
Returns the part of this request's URL that calls the HttpHandler.
|
InputBuffer |
getInputBuffer() |
InputStream |
getInputStream()
Return the
InputStream for this Request . |
int |
getIntHeader(Header header)
Return the value of the specified header as an integer, or -1 if there
is no such header for this request.
|
int |
getIntHeader(String name)
Return the value of the specified header as an integer, or -1 if there
is no such header for this request.
|
String |
getJrouteId()
Gets the jroute id of this request, which may have been
sent as a separate
JROUTE cookie or appended to the
session identifier encoded in the URI (if cookies have been disabled). |
String |
getLocalAddr()
Returns the Internet Protocol (IP) address of the interface on
which the request was received.
|
Locale |
getLocale()
Return the preferred Locale that the client will accept content in,
based on the value for the first
Accept-Language header
that was encountered. |
List<Locale> |
getLocales()
Return the set of preferred Locales that the client will accept
content in, based on the values for any
Accept-Language
headers that were encountered. |
String |
getLocalName()
Returns the host name of the Internet Protocol (IP) interface on
which the request was received.
|
int |
getLocalPort()
Returns the Internet Protocol (IP) port number of the interface
on which the request was received.
|
static int |
getMaxDispatchDepth() |
Method |
getMethod()
Return the HTTP request method used in this Request.
|
NIOInputStream |
getNIOInputStream()
Return the
NIOInputStream for this Request . |
NIOReader |
getNIOReader()
|
<E> E |
getNote(Note<E> note)
Return the
Note value associated with this Request,
or null if no such binding exists. |
Set<String> |
getNoteNames()
Return a
Set containing the String names of all note bindings
that exist for this request. |
String |
getParameter(String name)
Return the value of the specified request parameter, if any; otherwise,
return
null . |
Map<String,String[]> |
getParameterMap()
Returns a
Map of the parameters of this request. |
Set<String> |
getParameterNames()
Return the names of all defined request parameters for this request.
|
Parameters |
getParameters()
Returns the low-level parameters holder for finer control over parameters.
|
String[] |
getParameterValues(String name)
Return the defined values for the specified request parameter, if any;
otherwise, return
null . |
String |
getPathInfo()
Returns any extra path information associated with the URL the client
sent when it made this request.
|
Buffer |
getPostBody(int len)
Gets the POST body of this request.
|
Protocol |
getProtocol()
Return the protocol and version used to make this Request.
|
String |
getQueryString()
Return the query string associated with this request.
|
protected Cookies |
getRawCookies()
TODO DOCS
|
Reader |
getReader()
|
String |
getRemoteAddr()
Return the remote IP address making this Request.
|
String |
getRemoteHost()
Return the remote host name making this Request.
|
int |
getRemotePort()
Returns the Internet Protocol (IP) source port of the client
or last proxy that sent the request.
|
String |
getRemoteUser()
Return the name of the remote user that has been authenticated
for this Request.
|
HttpRequestPacket |
getRequest()
Get the Coyote request.
|
String |
getRequestedSessionId()
Return the session identifier included in this request, if any.
|
String |
getRequestURI()
Return the request URI for this request.
|
StringBuilder |
getRequestURL()
Reconstructs the URL the client used to make the request.
|
Response |
getResponse()
Return the Response with which this Request is associated.
|
String |
getScheme()
Return the scheme used to make this Request.
|
String |
getServerName()
Return the server name responding to this Request.
|
int |
getServerPort()
Return the server port responding to this Request.
|
Session |
getSession()
Return the session associated with this Request, creating one
if necessary.
|
Session |
getSession(boolean create)
Return the session associated with this Request, creating one
if necessary and requested.
|
Principal |
getUserPrincipal()
Return the principal that has been authenticated for this Request.
|
int |
incrementDispatchDepth()
Increment the depth of application dispatch
|
void |
initialize(HttpRequestPacket request,
FilterChainContext ctx,
HttpServerFilter httpServerFilter) |
boolean |
isMaxDispatchDepthReached()
Check if the application dispatching has reached the maximum
|
boolean |
isRequestedSessionIdFromCookie()
Return
true if the session identifier included in this
request came from a cookie. |
boolean |
isRequestedSessionIdFromURL()
Return
true if the session identifier included in this
request came from the request URI. |
boolean |
isRequestedSessionIdValid()
Return true if the session identifier included in this
request identifies a valid session.
|
boolean |
isSecure()
Was this request received on a secure connection?
|
MappingData |
obtainMappingData() |
protected void |
onAfterService() |
protected void |
parseCookies()
Parse cookies.
|
protected void |
parseLocales()
Parse request locales.
|
protected void |
parseLocalesHeader(String value)
Parse accept-language header value.
|
protected void |
parseRequestParameters()
Parse request parameters.
|
protected void |
parseSessionId()
Parse session id in URL.
|
protected void |
recycle()
Release all object references, and initialize instance variables, in
preparation for reuse of this object.
|
void |
removeAfterServiceListener(AfterServiceListener listener)
Remove the "after-service" listener, which was previously added by
addAfterServiceListener(org.glassfish.grizzly.http.server.AfterServiceListener) . |
void |
removeAttribute(String name)
Remove the specified request attribute if it exists.
|
<E> E |
removeNote(Note<E> note)
Remove the
Note value associated with this request. |
void |
replayPayload(Buffer buffer)
Replays request's payload by setting new payload
Buffer . |
boolean |
requiresAcknowledgement() |
void |
setAttribute(String name,
Object value)
Set the specified request attribute to the specified value.
|
void |
setCharacterEncoding(String encoding)
Overrides the name of the character encoding used in the body of this
request.
|
protected void |
setContextPath(String contextPath) |
void |
setCookies(Cookie[] cookies)
Set the set of cookies received with this Request.
|
protected void |
setHttpHandlerPath(String httpHandlerPath) |
static void |
setMaxDispatchDepth(int depth)
Static setter method for the maximum dispatch depth
|
void |
setMethod(String method)
Sets the HTTP request method used in this Request.
|
<E> void |
setNote(Note<E> note,
E value)
Bind the
Note value to this Request,
replacing any existing binding for this name. |
protected void |
setPathInfo(String pathInfo) |
void |
setQueryString(String queryString)
Sets the query string associated with this request.
|
void |
setRequestedSessionCookie(boolean flag)
Set a flag indicating whether or not the requested session ID for this
request came in through a cookie.
|
void |
setRequestedSessionId(String id)
Set the requested session ID for this request.
|
void |
setRequestedSessionURL(boolean flag)
Set a flag indicating whether or not the requested session ID for this
request came in through a URL.
|
void |
setRequestParameters(Parameters parameters)
This method may be used if some other entity processed request parameters
and wishes to expose them via the request.
|
void |
setRequestURI(String uri)
Sets the request URI for this request.
|
void |
setServerName(String name)
Set the name of the server (virtual host) to process this request.
|
void |
setServerPort(int port)
Set the port number of the server to process this request.
|
void |
setUserPrincipal(Principal principal)
Set the Principal who has been authenticated for this Request.
|
protected void |
skipPostBody(int len)
Skips the POST body of this request.
|
protected String |
unescape(String s) |
public static final String SEND_FILE_ENABLED_ATTR
File
using sendfile.public static final String SEND_FILE_ATTR
The value of this request attribute, as set by the developer must be a File
that exists, is not a directory, and is readable. This File
will be
transferred using sendfile if SEND_FILE_ENABLED_ATTR
is true. If sendfile
support isn't enabled, an IllegalStateException will be raised at runtime.
The HttpHandler
using this functionality should refrain from writing content
via the response.
Note that once this attribute is set, the sendfile process will begin.
public static final String SEND_FILE_START_OFFSET_ATTR
The value of this request attribute signifies the starting offset of the file
transfer. If not specified, an offset of zero will be assumed. The type of
the value must be Long
.
NOTE: In order for this attribute to take effect, it must be
set before the SEND_FILE_ATTR
is set.
public static final String SEND_FILE_WRITE_LEN_ATTR
The value of this request attribute signifies the total number of bytes to
transfer. If not specified, the entire file will be transferred.
The type of the value must be Long
NOTE: In order for this attribute to take effect, it must be
set before the SEND_FILE_ATTR
is set.
protected HttpRequestPacket request
protected FilterChainContext ctx
protected HttpServerFilter httpServerFilter
protected final List<AfterServiceListener> afterServicesList
protected Cookie[] cookies
protected Cookies rawCookies
protected static final Locale defaultLocale
protected final ArrayList<Locale> locales
protected Object dispatcherType
protected final InputBuffer inputBuffer
protected boolean usingInputStream
protected boolean usingReader
protected Principal userPrincipal
protected boolean sessionParsed
protected boolean requestParametersParsed
protected boolean cookiesParsed
protected boolean secure
protected Subject subject
protected final ParameterMap parameterMap
protected final Parameters parameters
protected Object requestDispatcherPath
protected boolean requestedSessionCookie
protected String requestedSessionId
protected boolean requestedSessionURL
protected boolean localesParsed
protected final Response response
protected Request(Response response)
public static Request create()
public final MappingData obtainMappingData()
public void initialize(HttpRequestPacket request, FilterChainContext ctx, HttpServerFilter httpServerFilter)
public HttpRequestPacket getRequest()
public Response getResponse()
public void addAfterServiceListener(AfterServiceListener listener)
listener
- the listener, which will be notified, once Request processing will be finished.public void removeAfterServiceListener(AfterServiceListener listener)
addAfterServiceListener(org.glassfish.grizzly.http.server.AfterServiceListener)
.listener
- the "after-service" listener, which was previously added by addAfterServiceListener(org.glassfish.grizzly.http.server.AfterServiceListener)
.protected void onAfterService()
protected void recycle()
public String getAuthorization()
public void replayPayload(Buffer buffer)
Buffer
.
If request parameters have been parsed based on prev. request's POST
payload - the parameters will be recycled and ready to be parsed again.buffer
- payloadIllegalStateException,
- if previous request payload has not been read off.public NIOInputStream createInputStream()
IOException
- if an input/output error occurspublic static <E> Note<E> createNote(String name)
Note
associated with this Request.public <E> E getNote(Note<E> note)
Note
value associated with this Request,
or null
if no such binding exists.
Use createNote(java.lang.String)
to create a new Note
.note
- Note
value to be returnedpublic Set<String> getNoteNames()
Set
containing the String names of all note bindings
that exist for this request.
Use createNote(java.lang.String)
to create a new Note
.Set
containing the String names of all note bindings
that exist for this request.public <E> E removeNote(Note<E> note)
Note
value associated with this request.
Use createNote(java.lang.String)
to create a new Note
.note
- Note
value to be removedpublic <E> void setNote(Note<E> note, E value)
Note
value to this Request,
replacing any existing binding for this name.
Use createNote(java.lang.String)
to create a new Note
.public void setServerName(String name)
name
- The server namepublic void setServerPort(int port)
port
- The server portpublic String getContextPath()
HttpHandler
s in the default (root) context, this method returns "".
The container does not decode this string.protected void setContextPath(String contextPath)
public HttpServerFilter getHttpFilter()
HttpServerFilter
, which dispatched this request.public String getHttpHandlerPath()
IllegalStateException
- if HttpHandler path was not set explicitly
and attempt to URI-decode RequestURIRef.getDecodedURI()
failed.protected void setHttpHandlerPath(String httpHandlerPath)
public String getPathInfo()
protected void setPathInfo(String pathInfo)
public Object getAttribute(String name)
null
.name
- Name of the request attribute to returnpublic Set<String> getAttributeNames()
Set
if there are none.public String getCharacterEncoding()
public int getContentLength()
public long getContentLengthLong()
public String getContentType()
public InputStream getInputStream()
Return the InputStream
for this Request
.
NIOInputStream
will work as blocking
InputStream
, but it will be possible to call InputSource.isReady()
,
InputStream.available()
, or InputSource.notifyAvailable(org.glassfish.grizzly.ReadHandler)
to avoid blocking.NIOInputStream
for this Request
.IllegalStateException
- if getReader()
or
getNIOReader()
has already been called for this request.public NIOInputStream getNIOInputStream()
Return the NIOInputStream
for this Request
. This stream
will not block when reading content.
NOTE: For now, in order to use non-blocking functionality, this
method must be invoked before the HttpHandler.service(Request, Response)
method returns. We hope to have this addressed in the next release.
NIOInputStream
for this Request
.IllegalStateException
- if getReader()
or
getNIOReader()
has already been called for this request.public boolean asyncInput()
true
if the current input source is operating in
non-blocking mode. In other words getNIOInputStream()
or
getNIOReader()
were invoked.public boolean requiresAcknowledgement()
true
if this request requires acknowledgment.public Locale getLocale()
Accept-Language
header
that was encountered. If the request did not specify a preferred
language, the server's default Locale is returned.public List<Locale> getLocales()
Accept-Language
headers that were encountered. If the request did not specify a
preferred language, the server's default Locale is returned.public Parameters getParameters()
Parameters
.public String getParameter(String name)
null
. If there is more than one value defined,
return only the first one.name
- Name of the desired request parameterpublic Map<String,String[]> getParameterMap()
Map
of the parameters of this request.
Request parameters are extra information sent with the request.
For HTTP servlets, parameters are contained in the query string
or posted form data.Map
containing parameter names as keys
and parameter values as map values.public Set<String> getParameterNames()
public String[] getParameterValues(String name)
null
.name
- Name of the desired request parameterpublic Protocol getProtocol()
public Reader getReader()
Returns the Reader
associated with this Request
.
NIOReader
will work as blocking
Reader
, but it will be possible to call InputSource.isReady()
or InputSource.notifyAvailable(org.glassfish.grizzly.ReadHandler)
to avoid blocking.NIOReader
associated with this Request
.IllegalStateException
- if getInputStream()
or
getNIOInputStream()
has already been called for this request.public NIOReader getNIOReader()
Returns the NIOReader
associated with this Request
.
This NIOReader
will not block while reading content.
IllegalStateException
- if getInputStream()
or
getNIOInputStream()
has already been called for this request.public String getRemoteAddr()
public String getRemoteHost()
public int getRemotePort()
public String getLocalName()
public String getLocalAddr()
public int getLocalPort()
public String getScheme()
public String getServerName()
public int getServerPort()
public boolean isSecure()
public void removeAttribute(String name)
name
- Name of the request attribute to removepublic void setAttribute(String name, Object value)
name
- Name of the request attribute to setvalue
- The associated valuepublic void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
getReader()
. Otherwise, it has no
effect.encoding
- String
containing the name of
the character encoding.UnsupportedEncodingException
- if this
ServletRequest is still in a state where a
character encoding may be set, but the specified
encoding is invalidpublic static void setMaxDispatchDepth(int depth)
public static int getMaxDispatchDepth()
public int incrementDispatchDepth()
public int decrementDispatchDepth()
public boolean isMaxDispatchDepthReached()
public void addCookie(Cookie cookie)
cookie
- The new cookiepublic void addLocale(Locale locale)
locale
- The new preferred Localepublic void addParameter(String name, String[] values)
name
- Name of this request parametervalues
- Corresponding values for this request parameterpublic void clearCookies()
public void clearHeaders()
public void clearLocales()
public void clearParameters()
public String getDecodedRequestURI() throws CharConversionException
CharConversionException
public void setUserPrincipal(Principal principal)
getRemoteUser()
method.principal
- The user Principalpublic String getAuthType()
public Cookie[] getCookies()
public void setCookies(Cookie[] cookies)
public long getDateHeader(String name)
name
- Name of the requested date headerIllegalArgumentException
- if the specified header value
cannot be converted to a datepublic long getDateHeader(Header header)
header
- the requested date Header
IllegalArgumentException
- if the specified header value
cannot be converted to a datepublic String getHeader(String name)
null
name
- Name of the requested headerpublic String getHeader(Header header)
null
header
- the requested Header
public Iterable<String> getHeaders(String name)
name
- Name of the requested headerpublic Iterable<String> getHeaders(Header header)
header
- the requested Header
public Iterable<String> getHeaderNames()
public int getIntHeader(String name)
name
- Name of the requested headerIllegalArgumentException
- if the specified header value
cannot be converted to an integerpublic int getIntHeader(Header header)
header
- the requested Header
IllegalArgumentException
- if the specified header value
cannot be converted to an integerpublic Method getMethod()
public void setMethod(String method)
method
- the HTTP request method used in this Request.public String getQueryString()
public void setQueryString(String queryString)
queryString
- the query string associated with this request.public String getRemoteUser()
public String getRequestedSessionId()
public String getRequestURI()
public void setRequestURI(String uri)
uri
- the request URI for this request.public StringBuilder getRequestURL()
Because this method returns a StringBuilder
,
not a String
, you can modify the URL easily,
for example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
StringBuffer
object containing the
reconstructed URLpublic static StringBuilder appendRequestURL(Request request, StringBuilder buffer)
Because this method returns a StringBuilder
,
not a String
, you can modify the URL easily,
for example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
StringBuilder
object containing the appended
reconstructed URLpublic static StringBuffer appendRequestURL(Request request, StringBuffer buffer)
Because this method returns a StringBuffer
,
not a String
, you can modify the URL easily,
for example, to append query parameters.
This method is useful for creating redirect messages and for reporting errors.
StringBuffer
object containing the appended
reconstructed URLpublic Principal getUserPrincipal()
public FilterChainContext getContext()
protected void parseCookies()
public InputBuffer getInputBuffer()
InputBuffer
associated with this request, which is the
source for getInputStream()
, getReader()
,
getNIOInputStream()
, and getNIOReader()
public void setRequestParameters(Parameters parameters)
parameters
- the parameters to expose via this request.protected Cookies getRawCookies()
protected void parseRequestParameters()
public Buffer getPostBody(int len) throws IOException
IOException
protected void skipPostBody(int len) throws IOException
len
- how much of the POST body to skip.IOException
protected void parseLocales()
protected void parseLocalesHeader(String value)
public String getJrouteId()
JROUTE
cookie or appended to the
session identifier encoded in the URI (if cookies have been disabled).public Session getSession()
public Session getSession(boolean create)
create
- Create a new session if one does not existpublic String changeSessionId()
IllegalStateException
- if there is no session associated
with the requestprotected Session doGetSession(boolean create)
public boolean isRequestedSessionIdFromCookie()
true
if the session identifier included in this
request came from a cookie.public boolean isRequestedSessionIdFromURL()
true
if the session identifier included in this
request came from the request URI.public boolean isRequestedSessionIdValid()
protected void configureSessionCookie(Cookie cookie)
cookie
- The JSESSIONID cookie to be configuredprotected void parseSessionId()
public void setRequestedSessionCookie(boolean flag)
flag
- The new flagpublic void setRequestedSessionId(String id)
id
- The new session idpublic void setRequestedSessionURL(boolean flag)
flag
- The new flagCopyright © 2014 Oracle Corporation. All rights reserved.