public class Request extends java.lang.Object implements HttpUtil
HttpUtil.HEADER, HttpUtil.Helper, HttpUtil.METHOD, HttpUtil.STATUS
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SESSION_COOKIE
The session cookie name.
|
Constructor and Description |
---|
Request(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Creates a new request wrapper.
|
Modifier and Type | Method and Description |
---|---|
void |
commit()
Sends the request response to the underlying HTTP response
object.
|
void |
dispose()
Disposes of all resources used by this request object.
|
java.lang.String |
getAbsolutePath()
Returns the full request path with file name.
|
java.lang.Object |
getAttribute(java.lang.String name)
Returns a named request attribute value.
|
Dict |
getAuthentication()
Returns the parsed "Authorization" request header data.
|
java.lang.String |
getContentType()
Returns the request content type value.
|
java.lang.String |
getHeader(java.lang.String name)
Returns an HTTP request header.
|
java.lang.String |
getHost()
Returns the host name in the request.
|
javax.servlet.http.HttpServletRequest |
getHttpRequest()
Returns the HTTP request object for direct access to the raw
request data.
|
javax.servlet.http.HttpServletResponse |
getHttpResponse()
Returns the HTTP response object for direct access to the raw
response data.
|
java.io.InputStream |
getInputStream()
Returns the request input stream.
|
java.lang.String |
getInputString()
Returns the request input stream data as a string.
|
java.lang.String |
getMethod()
Returns the request method name.
|
org.apache.commons.fileupload.FileItemStream |
getNextFile()
Returns the next available file item stream in the request.
|
java.lang.String |
getParameter(java.lang.String name)
Returns the value of a request parameter.
|
java.lang.String |
getParameter(java.lang.String name,
java.lang.String defVal)
Returns the value of a request parameter.
|
java.lang.String |
getPath()
Returns the local request path with file name.
|
int |
getPort()
Returns the port number in the request.
|
long |
getProcessTime()
Returns the time in milliseconds since this request wrapper
was created.
|
java.lang.String |
getProtocol()
Returns the protocol name in the request, i.e.
|
java.lang.String |
getRemoteAddr()
Returns the IP address of the request sender.
|
java.lang.String |
getSessionId()
Returns the request session id (as sent in an HTTP cookie).
|
java.lang.String |
getUrl()
Returns the full request URL with protocol, hostname, port and
path.
|
boolean |
hasMethod(java.lang.String method)
Checks if the request method is the specified one.
|
boolean |
hasResponse()
Checks if this request contains a response.
|
boolean |
isFileUpload()
Checks if this request contains a file upload.
|
boolean |
matchPath(java.lang.String prefix)
Matches and modifies the request path with the specified path
prefix.
|
void |
sendAuthenticationRequest(java.lang.String realm,
java.lang.String nonce)
Sends a digest authentication request as the request response.
|
void |
sendBinary(Binary data,
boolean limitCache)
Sends the contents of a file as the request response.
|
void |
sendClear()
Clears any previously sent but non-committed response.
|
void |
sendError(int code)
Sends the specified error code.
|
void |
sendError(int code,
java.lang.String mimeType,
java.lang.String text)
Sends the specified error code and data as the request
response.
|
void |
sendRedirect(java.lang.String location)
Redirects this request by sending a temporary redirection URL
to the browser.
|
void |
sendText(int code,
java.lang.String mimeType,
java.lang.String text)
Sends the specified text data as the request response.
|
void |
sendText(java.lang.String mimeType,
java.lang.String text)
Sends the specified text data as the request response.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets a request attribute value.
|
void |
setPath(java.lang.String path)
Sets the local request path.
|
void |
setResponseHeader(java.lang.String name,
java.lang.String value)
Sets an HTTP response header value.
|
void |
setResponseHeadersOnly(boolean value)
Sets or clears the response headers only flag.
|
void |
setSessionId(java.lang.String sessionId,
int expiry)
Sets the session id cookie in the HTTP response.
|
java.lang.String |
toString()
Returns a string representation of this request.
|
public static final java.lang.String SESSION_COOKIE
public Request(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- the servlet requestresponse
- the servlet responsepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean isFileUpload()
getNextFile()
public boolean hasMethod(java.lang.String method)
method
- the HTTP method namepublic boolean hasResponse()
public java.lang.String getUrl()
public java.lang.String getProtocol()
public java.lang.String getHost()
public int getPort()
public java.lang.String getMethod()
public java.lang.String getAbsolutePath()
public java.lang.String getPath()
public void setPath(java.lang.String path)
path
- the new local path, or null to resetpublic boolean matchPath(java.lang.String prefix)
prefix
- the path prefix to checkpublic java.lang.String getContentType()
public java.lang.String getRemoteAddr()
public Dict getAuthentication()
public java.lang.String getHeader(java.lang.String name)
name
- the request header namepublic java.lang.String getParameter(java.lang.String name)
name
- the request parameter namepublic java.lang.String getParameter(java.lang.String name, java.lang.String defVal)
name
- the request parameter namedefVal
- the default parameter valuepublic org.apache.commons.fileupload.FileItemStream getNextFile() throws java.io.IOException
The recommended way to implement file uploads is by sending them as the sole request parameter in a form and storing the file content for later processing. Preferably the form posting is also performed from an IFRAME in order to process in the background.
java.io.IOException
- if the file uploadpublic java.lang.Object getAttribute(java.lang.String name)
name
- the attribute namepublic void setAttribute(java.lang.String name, java.lang.Object value)
name
- the attribute namevalue
- the attribute valuepublic java.lang.String getSessionId()
public javax.servlet.http.HttpServletRequest getHttpRequest()
public javax.servlet.http.HttpServletResponse getHttpResponse()
public long getProcessTime()
public java.lang.String getInputString()
public java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
- if the input stream couldn't be readpublic void sendClear()
public void sendAuthenticationRequest(java.lang.String realm, java.lang.String nonce)
realm
- the security realm to usenonce
- the generated one-time code to usesendClear()
public void sendText(java.lang.String mimeType, java.lang.String text)
mimeType
- the data MIME typetext
- the text data to sendsendClear()
public void sendText(int code, java.lang.String mimeType, java.lang.String text)
code
- the HTTP response code to sendmimeType
- the optional MIME type, null for defaulttext
- the text data to sendsendClear()
public void sendBinary(Binary data, boolean limitCache)
data
- the file containing the responselimitCache
- the limited cache flagsendClear()
public void sendRedirect(java.lang.String location)
location
- the destination locationsendClear()
public void sendError(int code)
code
- the HTTP response code to sendsendClear()
,
sendError(int, String, String)
public void sendError(int code, java.lang.String mimeType, java.lang.String text)
code
- the HTTP response code to sendmimeType
- the optional MIME type, null for defaulttext
- the text data to send (error page content)sendClear()
public void setResponseHeader(java.lang.String name, java.lang.String value)
name
- the HTTP header namevalue
- the HTTP header valuepublic void setResponseHeadersOnly(boolean value)
value
- the new flag valuepublic void setSessionId(java.lang.String sessionId, int expiry)
sessionId
- the session identifierexpiry
- the maximum age of the cookie in secondspublic void dispose()
public void commit() throws java.io.IOException, javax.servlet.ServletException
java.io.IOException
- if an IO error occurred while attempting to
commit the responsejavax.servlet.ServletException
- if a configuration error was
encountered while sending the response