public class HTTPRequestImpl extends java.lang.Object implements HTTPRequest
| Modifier and Type | Class and Description |
|---|---|
static class |
HTTPRequestImpl.HTTPUploadedFileImpl
Container for uploaded files in HTTP POST requests.
|
| Constructor and Description |
|---|
HTTPRequestImpl(java.lang.String path,
java.lang.String encodedQueryString,
java.lang.String method)
Creates a new HTTPRequest for the given path and url-encoded query string
|
HTTPRequestImpl(java.net.URI uri,
Bucket d,
ToadletContext ctx,
java.lang.String method)
Creates a new HTTPRequest for the given URI and data.
|
HTTPRequestImpl(java.net.URI uri,
java.lang.String method)
Create a new HTTPRequest for the given URI and parse its request
parameters.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
createQueryString(java.util.Map<java.lang.String,java.util.List<java.lang.String>> parameterValues,
boolean doUrlEncoding)
Creates a query string from the given parameters.
|
void |
freeParts()
Free all the parts.
|
int |
getContentLength()
Get the length of the original uploaded raw data for a POST.
|
java.lang.String |
getHeader(java.lang.String name)
Get the value of a specific header on the request.
|
int |
getIntParam(java.lang.String name)
Get the value of a request parameter converted to an int, using 0 as
default value.
|
int |
getIntParam(java.lang.String name,
int defaultValue)
Get the value of a request parameter converted to an
int,
using the specified default value. |
int |
getIntPart(java.lang.String name,
int defaultValue)
Get a part as an integer with a default value if it is not set.
|
long |
getLongParam(java.lang.String name,
long defaultValue)
Get a part as a long, with a default value if it is not set.
|
java.lang.String |
getMethod()
Get the HTTP method, typically GET or POST.
|
int[] |
getMultipleIntParam(java.lang.String name)
Get all values of a request parameter as int array, ignoring all values
that can not be parsed.
|
java.lang.String[] |
getMultipleParam(java.lang.String name)
Get all values of a request parameter as a string array.
|
java.lang.String |
getParam(java.lang.String name)
Get the value of a request parameter, using an empty string as default
value if the parameter was not set.
|
java.lang.String |
getParam(java.lang.String name,
java.lang.String defaultValue)
Get the value of a request parameter, using the specified default value
if the parameter was not set or has an empty value.
|
java.util.Collection<java.lang.String> |
getParameterNames()
Returns the names of all parameters.
|
RandomAccessBucket |
getPart(java.lang.String name)
Get a part as a Bucket.
|
byte[] |
getPartAsBytes(java.lang.String name,
int maxlength)
Deprecated.
|
byte[] |
getPartAsBytesFailsafe(java.lang.String name,
int maxLength)
Gets up to maxLength bytes from the part, ignores any bytes after the limit.
|
byte[] |
getPartAsBytesThrowing(java.lang.String name,
int maxLength) |
java.lang.String |
getPartAsString(java.lang.String name,
int maxlength)
Deprecated.
|
java.lang.String |
getPartAsStringFailsafe(java.lang.String name,
int maxLength)
Gets up to maxLength characters from the part, ignores any characters after the limit.
|
java.lang.String |
getPartAsStringThrowing(java.lang.String name,
int maxLength) |
java.lang.String[] |
getParts() |
java.lang.String |
getPath()
The path of this request, where the part of the path the specified the
plugin has already been removed..
|
Bucket |
getRawData()
Get the original uploaded raw data for a POST.
|
HTTPUploadedFile |
getUploadedFile(java.lang.String name)
Get a file uploaded in the HTTP request.
|
boolean |
hasParameters() |
boolean |
isChrome()
Is the browser Chrome according to User-Agent?
|
boolean |
isIncognito()
Is the incognito=true boolean set? Sadly this does not prove that
it is actually running incognito mode...
|
boolean |
isParameterSet(java.lang.String name)
Check if a parameter was set in the request at all, either with or
without a value.
|
boolean |
isPartSet(java.lang.String name)
Is a part set with the given name?
|
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
parseUriParameters(java.lang.String queryString,
boolean doUrlDecoding)
Parses the parameters from the given query string, optionally decoding
the parameters using UTF-8.
|
public HTTPRequestImpl(java.net.URI uri,
java.lang.String method)
uri - the URI being requestedpublic HTTPRequestImpl(java.lang.String path,
java.lang.String encodedQueryString,
java.lang.String method)
throws java.net.URISyntaxException
path - i.e. /test/test.htmlencodedQueryString - a=some+text&b=abc%40def.dejava.net.URISyntaxException - if the URI is invalidpublic HTTPRequestImpl(java.net.URI uri,
Bucket d,
ToadletContext ctx,
java.lang.String method)
uri - The URI being requestedh - Client headersd - The datactx - The toadlet context (for headers and bucket factory)java.net.URISyntaxException - if the URI is invalidpublic java.lang.String getPath()
HTTPRequestgetPath in interface HTTPRequestpublic boolean hasParameters()
hasParameters in interface HTTPRequestpublic java.util.Collection<java.lang.String> getParameterNames()
getParameterNames in interface HTTPRequestpublic static java.util.Map<java.lang.String,java.util.List<java.lang.String>> parseUriParameters(java.lang.String queryString,
boolean doUrlDecoding)
queryString - The query string to decodedoUrlDecoding - true to decode the parameter names and valuespublic static java.lang.String createQueryString(java.util.Map<java.lang.String,java.util.List<java.lang.String>> parameterValues,
boolean doUrlEncoding)
parameterValues - The parameters to create a query string fromdoUrlEncoding - true if encoding for HTTP headers, false to
only encode unsafe characterspublic boolean isParameterSet(java.lang.String name)
HTTPRequestisParameterSet in interface HTTPRequestname - the name of the parameter to checkpublic java.lang.String getParam(java.lang.String name)
HTTPRequest
if (request.getParam("abc").equals("def"))
getParam in interface HTTPRequestname - the name of the parameter to getpublic java.lang.String getParam(java.lang.String name,
java.lang.String defaultValue)
HTTPRequestgetParam in interface HTTPRequestname - the name of the parameter to getdefaultValue - the default value to be returned if the parameter is missing
or emptypublic int getIntParam(java.lang.String name)
HTTPRequestgetIntParam in interface HTTPRequestname - the name of the parameter to getpublic int getIntParam(java.lang.String name,
int defaultValue)
HTTPRequestint,
using the specified default value. If there are multiple values for this
parameter, the first value is used.getIntParam in interface HTTPRequestname - the name of the parameter to getdefaultValue - the default value to be returned if the parameter is missing,
empty or invalidpublic int getIntPart(java.lang.String name,
int defaultValue)
HTTPRequestgetIntPart in interface HTTPRequestpublic java.lang.String[] getMultipleParam(java.lang.String name)
HTTPRequestnull.getMultipleParam in interface HTTPRequestname - the name of the parameter to getpublic int[] getMultipleIntParam(java.lang.String name)
HTTPRequestnull.getMultipleIntParam in interface HTTPRequestname - the name of the parameter to getpublic HTTPUploadedFile getUploadedFile(java.lang.String name)
HTTPRequestgetUploadedFile in interface HTTPRequestpublic RandomAccessBucket getPart(java.lang.String name)
HTTPRequestgetPart in interface HTTPRequestpublic boolean isPartSet(java.lang.String name)
HTTPRequestisPartSet in interface HTTPRequest@Deprecated
public java.lang.String getPartAsString(java.lang.String name,
int maxlength)
HTTPRequestgetPartAsString in interface HTTPRequestpublic java.lang.String getPartAsStringThrowing(java.lang.String name,
int maxLength)
throws java.util.NoSuchElementException,
javax.naming.SizeLimitExceededException
getPartAsStringThrowing in interface HTTPRequestjava.util.NoSuchElementExceptionjavax.naming.SizeLimitExceededExceptionpublic java.lang.String getPartAsStringFailsafe(java.lang.String name,
int maxLength)
HTTPRequestgetPartAsStringFailsafe in interface HTTPRequest@Deprecated
public byte[] getPartAsBytes(java.lang.String name,
int maxlength)
HTTPRequestgetPartAsBytes in interface HTTPRequestpublic byte[] getPartAsBytesThrowing(java.lang.String name,
int maxLength)
throws java.util.NoSuchElementException,
javax.naming.SizeLimitExceededException
getPartAsBytesThrowing in interface HTTPRequestjava.util.NoSuchElementExceptionjavax.naming.SizeLimitExceededExceptionpublic byte[] getPartAsBytesFailsafe(java.lang.String name,
int maxLength)
HTTPRequestgetPartAsBytesFailsafe in interface HTTPRequestpublic void freeParts()
HTTPRequestfreeParts in interface HTTPRequestpublic long getLongParam(java.lang.String name,
long defaultValue)
HTTPRequestgetLongParam in interface HTTPRequestpublic java.lang.String getMethod()
HTTPRequestgetMethod in interface HTTPRequestpublic Bucket getRawData()
HTTPRequestgetRawData in interface HTTPRequestpublic java.lang.String getHeader(java.lang.String name)
HTTPRequestgetHeader in interface HTTPRequestpublic int getContentLength()
HTTPRequestgetContentLength in interface HTTPRequestpublic java.lang.String[] getParts()
getParts in interface HTTPRequestpublic boolean isIncognito()
HTTPRequestisIncognito in interface HTTPRequestpublic boolean isChrome()
HTTPRequestisChrome in interface HTTPRequest