public class RequestWrapper extends java.lang.Object implements ServletRequest
Modifier and Type | Field and Description |
---|---|
protected HttpServletRequest |
_request |
Constructor and Description |
---|
RequestWrapper()
Create a new ServletRequestWrapper wrapping the enclosed request.
|
RequestWrapper(HttpServletRequest request)
Create a new ServletRequestWrapper wrapping the enclosed request.
|
Modifier and Type | Method and Description |
---|---|
void |
addAsyncListener(AsyncListener listener)
Adds an async listener for this request
|
void |
addAsyncListener(AsyncListener listener,
ServletRequest request,
ServletResponse response)
Adds an async listener for this request
|
void |
complete()
Complete the request
|
protected void |
free()
Clears the wrapper.
|
AsyncContext |
getAsyncContext()
Returns the async context for the request
|
java.lang.Object |
getAttribute(java.lang.String name)
Returns an attribute value.
|
java.util.Enumeration |
getAttributeNames()
Enumerates all attribute names in the request.
|
java.lang.String |
getAuthType()
Returns the auth type, e.g.
|
java.lang.String |
getCharacterEncoding()
Returns the character encoding of the POSTed data.
|
int |
getContentLength()
Returns the content length of the data.
|
java.lang.String |
getContentType()
Returns the request's mime-type.
|
java.lang.String |
getContextPath()
Returns the part of the URI corresponding to the application's
prefix.
|
Cookie[] |
getCookies()
Returns an array of all cookies sent by the client.
|
long |
getDateHeader(java.lang.String name)
Converts a date header to milliseconds since the epoch.
|
DispatcherType |
getDispatcherType()
Returns DispatcherType
|
java.lang.String |
getHeader(java.lang.String name)
Returns the first value for a request header.
|
java.util.Enumeration |
getHeaderNames()
Returns an enumeration of all headers sent by the client.
|
java.util.Enumeration |
getHeaders(java.lang.String name)
Returns all the values for a request header.
|
ServletInputStream |
getInputStream()
Returns an InputStream to retrieve POST data from the request.
|
int |
getIntHeader(java.lang.String name)
Converts a header value to an integer.
|
java.lang.String |
getLocalAddr()
Returns the IP address of the local host, i.e.
|
java.util.Locale |
getLocale()
Returns the request's preferred locale.
|
java.util.Enumeration |
getLocales()
Returns an enumeration of all locales acceptable by the client.
|
java.lang.String |
getLocalName()
Returns the local host name.
|
int |
getLocalPort()
Returns the local port
|
java.lang.String |
getMethod()
Returns the HTTP method, e.g.
|
java.lang.String |
getParameter(java.lang.String name)
Returns a form parameter.
|
java.util.Map |
getParameterMap()
Returns the parameter map request parameters.
|
java.util.Enumeration |
getParameterNames()
Returns an enumeration of all form parameter names.
|
java.lang.String[] |
getParameterValues(java.lang.String name)
Returns all values of a form parameter.
|
java.lang.String |
getPathInfo()
Returns the URI part after the selected servlet and null if there
is no suffix.
|
java.lang.String |
getPathTranslated()
Returns the physical path name for the path info.
|
java.lang.String |
getProtocol()
Returns the prococol, e.g.
|
java.lang.String |
getQueryString()
Returns the request's query string.
|
java.io.BufferedReader |
getReader()
Returns a reader to read POSTed data.
|
java.lang.String |
getRealPath(java.lang.String uri)
Returns the real path.
|
java.lang.String |
getRemoteAddr()
Returns the IP address of the remote host, i.e.
|
java.lang.String |
getRemoteHost()
Returns the DNS hostname of the remote host, i.e.
|
int |
getRemotePort()
Returns the remote port
|
java.lang.String |
getRemoteUser()
Returns the remote user if authenticated.
|
HttpServletRequest |
getRequest()
Gets the request object being wrapped.
|
RequestDispatcher |
getRequestDispatcher(java.lang.String uri)
Returns a request dispatcher for later inclusion or forwarding.
|
java.lang.String |
getRequestedSessionId()
Returns the session id.
|
java.lang.String |
getRequestURI()
Returns the entire request URI
|
java.lang.StringBuffer |
getRequestURL()
Reconstructs the URL the client used for the request.
|
java.lang.String |
getScheme()
Returns the request scheme, e.g.
|
java.lang.String |
getServerName()
Returns the server name handling the request.
|
int |
getServerPort()
Returns the server port handling the request, e.g.
|
ServletContext |
getServletContext()
Returns the servlet context for the request
|
java.lang.String |
getServletPath()
Returns the URI part corresponding to the selected servlet.
|
ServletResponse |
getServletResponse()
Returns the servlet response for the request
|
HttpSession |
getSession()
Returns the current session, creating one if necessary.
|
HttpSession |
getSession(boolean create)
Returns a session.
|
java.security.Principal |
getUserPrincipal()
Returns the equivalent principal object for the authenticated user.
|
boolean |
isAsyncStarted()
Returns true if the request is in async.
|
boolean |
isAsyncSupported()
Returns true if the request supports async
|
boolean |
isInitial()
Returns true for the initial dispatch
|
boolean |
isRequestedSessionIdFromCookie()
Returns true if the session came from a cookie.
|
boolean |
isRequestedSessionIdFromUrl()
Deprecated.
|
boolean |
isRequestedSessionIdFromURL()
Returns true if the session came URL-encoding.
|
boolean |
isRequestedSessionIdValid()
Returns true if the session is valid.
|
boolean |
isResumed()
Returns true if the servlet is resumed
|
boolean |
isSecure()
Returns true if the connection is secure, e.g.
|
boolean |
isSuspended()
Returns true if the servlet is suspended
|
boolean |
isTimeout()
Returns true if the servlet timed out
|
boolean |
isUserInRole(java.lang.String role)
Returns true if the user is in the given role.
|
void |
removeAttribute(java.lang.String name)
Removes the given attribute.
|
void |
resume()
Resume the request
|
void |
setAttribute(java.lang.String name,
java.lang.Object o)
Sets an attribute value.
|
void |
setCharacterEncoding(java.lang.String encoding)
Sets the character encoding to be used for forms and getReader.
|
void |
setRequest(HttpServletRequest request)
Sets the request object being wrapped.
|
AsyncContext |
startAsync()
Starts an async mode
|
AsyncContext |
startAsync(ServletRequest servletRequest,
ServletResponse servletResponse)
Starts an async mode
|
void |
suspend()
Suspend the request
|
void |
suspend(long timeout)
Suspend the request
|
protected HttpServletRequest _request
public RequestWrapper()
public RequestWrapper(HttpServletRequest request)
public void setRequest(HttpServletRequest request)
java.lang.IllegalArgumentException
- if the request is nullpublic HttpServletRequest getRequest()
public java.lang.String getProtocol()
getProtocol
in interface ServletRequest
public java.lang.String getScheme()
getScheme
in interface ServletRequest
public java.lang.String getServerName()
getServerName
in interface ServletRequest
public int getServerPort()
getServerPort
in interface ServletRequest
public java.lang.String getRemoteAddr()
getRemoteAddr
in interface ServletRequest
public java.lang.String getRemoteHost()
getRemoteHost
in interface ServletRequest
public int getRemotePort()
getRemotePort
in interface ServletRequest
public java.lang.String getLocalAddr()
getLocalAddr
in interface ServletRequest
public java.lang.String getLocalName()
getLocalName
in interface ServletRequest
public int getLocalPort()
getLocalPort
in interface ServletRequest
public java.lang.String getParameter(java.lang.String name)
getParameter
returns the first.
For example, calling getParameter("a")
with the
the query string a=1&a=2
will return "1".
getParameter
in interface ServletRequest
name
- the form parameter to returnpublic java.util.Map getParameterMap()
getParameterMap
in interface ServletRequest
public java.lang.String[] getParameterValues(java.lang.String name)
For example, calling getParameterValues("a")
with the the query string a=1&a=2
will
return ["1", "2"].
getParameterValues
in interface ServletRequest
name
- the form parameter to returnpublic java.util.Enumeration getParameterNames()
Enumeration e = getRequest().getParameterNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
out.println(name + ": " + request.getParameter(name));
}
getParameterNames
in interface ServletRequest
public ServletInputStream getInputStream() throws java.io.IOException
getInputStream
in interface ServletRequest
java.io.IOException
public java.io.BufferedReader getReader() throws java.io.IOException, java.lang.IllegalStateException
getCharacterEncoding()
getReader
in interface ServletRequest
java.io.IOException
java.lang.IllegalStateException
public java.lang.String getCharacterEncoding()
getCharacterEncoding
in interface ServletRequest
public void setCharacterEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
setCharacterEncoding
in interface ServletRequest
java.io.UnsupportedEncodingException
public int getContentLength()
The upshot is, rely on the input stream to end when the data completes.
getContentLength
in interface ServletRequest
public java.lang.String getContentType()
getContentType
in interface ServletRequest
public java.util.Locale getLocale()
getLocale
in interface ServletRequest
public java.util.Enumeration getLocales()
getLocales
in interface ServletRequest
public boolean isSecure()
isSecure
in interface ServletRequest
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface ServletRequest
name
- the attribute namepublic void setAttribute(java.lang.String name, java.lang.Object o)
setAttribute
in interface ServletRequest
name
- the attribute nameo
- the attribute valuepublic java.util.Enumeration getAttributeNames()
getAttributeNames
in interface ServletRequest
public void removeAttribute(java.lang.String name)
removeAttribute
in interface ServletRequest
name
- the attribute namepublic RequestDispatcher getRequestDispatcher(java.lang.String uri)
uri
is relative to the request URI. Absolute URIs are relative to
the application prefix (getContextPath()
).
If getRequestURI()
is /myapp/dir/test.jsp and the
uri
is "inc.jsp", the resulting page is
/myapp/dir/inc.jsp.
RequestDispatcher disp;
disp = getRequestDispatcher("inc.jsp?a=b");
disp.include(request, response);
getRequestDispatcher
in interface ServletRequest
uri
- path relative to getRequestURI()
(including query string) for the included file.public java.lang.String getRealPath(java.lang.String uri)
getRealPath
in interface ServletRequest
public java.lang.String getMethod()
REQUEST_METHOD
public java.lang.String getRequestURI()
public java.lang.StringBuffer getRequestURL()
public java.lang.String getContextPath()
getContextPath()
is /myapp for the uri
/myapp/servlet/Hello,
public java.lang.String getServletPath()
SCRIPT_NAME
getServletPath()
is /servlet/Hello for the uri
/myapp/servlet/Hello/foo.
getServletPath()
is /dir/hello.jsp
for the uri /myapp/dir/hello.jsp/foo,public java.lang.String getPathInfo()
PATH_INFO
getPathInfo()
is /foo for
the uri /myapp/servlet/Hello/foo.
getPathInfo()
is /hello.jsp for for the uri
/myapp/dir/hello.jsp/foo.
public java.lang.String getPathTranslated()
PATH_TRANSLATED
public java.lang.String getQueryString()
ServletRequest.getParameter()
to decode the form values.
Corresponds to CGI's PATH_TRANSLATED
public java.lang.String getHeader(java.lang.String name)
HTTP_*
String userAgent = request.getHeader("User-Agent");
name
- the header namepublic java.util.Enumeration getHeaders(java.lang.String name)
name
- the header namepublic java.util.Enumeration getHeaderNames()
public int getIntHeader(java.lang.String name)
name
- the header namepublic long getDateHeader(java.lang.String name)
long mod = getRequest().getDateHeader("If-Modified-Since");
name
- the header namepublic Cookie[] getCookies()
public HttpSession getSession(boolean create)
create
- If true, then create a new session if none exists.public HttpSession getSession()
public java.lang.String getRequestedSessionId()
public boolean isRequestedSessionIdValid()
public boolean isRequestedSessionIdFromCookie()
public boolean isRequestedSessionIdFromURL()
public java.lang.String getAuthType()
public java.lang.String getRemoteUser()
public boolean isUserInRole(java.lang.String role)
public java.security.Principal getUserPrincipal()
public boolean isRequestedSessionIdFromUrl()
public ServletContext getServletContext()
getServletContext
in interface ServletRequest
public ServletResponse getServletResponse()
public void addAsyncListener(AsyncListener listener)
public void addAsyncListener(AsyncListener listener, ServletRequest request, ServletResponse response)
public AsyncContext getAsyncContext()
getAsyncContext
in interface ServletRequest
public boolean isAsyncStarted()
isAsyncStarted
in interface ServletRequest
public boolean isAsyncSupported()
isAsyncSupported
in interface ServletRequest
public AsyncContext startAsync()
startAsync
in interface ServletRequest
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse)
startAsync
in interface ServletRequest
public void suspend(long timeout)
public void suspend()
public void resume()
public void complete()
public boolean isSuspended()
public boolean isResumed()
public boolean isTimeout()
public boolean isInitial()
public DispatcherType getDispatcherType()
ServletRequest
getDispatcherType
in interface ServletRequest
protected void free()