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()
HTTPRequest
getPath
in interface HTTPRequest
public boolean hasParameters()
hasParameters
in interface HTTPRequest
public java.util.Collection<java.lang.String> getParameterNames()
getParameterNames
in interface HTTPRequest
public 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)
HTTPRequest
isParameterSet
in interface HTTPRequest
name
- 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 HTTPRequest
name
- the name of the parameter to getpublic java.lang.String getParam(java.lang.String name, java.lang.String defaultValue)
HTTPRequest
getParam
in interface HTTPRequest
name
- 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)
HTTPRequest
getIntParam
in interface HTTPRequest
name
- the name of the parameter to getpublic int getIntParam(java.lang.String name, int defaultValue)
HTTPRequest
int
,
using the specified default value. If there are multiple values for this
parameter, the first value is used.getIntParam
in interface HTTPRequest
name
- 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)
HTTPRequest
getIntPart
in interface HTTPRequest
public java.lang.String[] getMultipleParam(java.lang.String name)
HTTPRequest
null
.getMultipleParam
in interface HTTPRequest
name
- the name of the parameter to getpublic int[] getMultipleIntParam(java.lang.String name)
HTTPRequest
null
.getMultipleIntParam
in interface HTTPRequest
name
- the name of the parameter to getpublic HTTPUploadedFile getUploadedFile(java.lang.String name)
HTTPRequest
getUploadedFile
in interface HTTPRequest
public RandomAccessBucket getPart(java.lang.String name)
HTTPRequest
getPart
in interface HTTPRequest
public boolean isPartSet(java.lang.String name)
HTTPRequest
isPartSet
in interface HTTPRequest
@Deprecated public java.lang.String getPartAsString(java.lang.String name, int maxlength)
HTTPRequest
getPartAsString
in interface HTTPRequest
public java.lang.String getPartAsStringThrowing(java.lang.String name, int maxLength) throws java.util.NoSuchElementException, javax.naming.SizeLimitExceededException
getPartAsStringThrowing
in interface HTTPRequest
java.util.NoSuchElementException
javax.naming.SizeLimitExceededException
public java.lang.String getPartAsStringFailsafe(java.lang.String name, int maxLength)
HTTPRequest
getPartAsStringFailsafe
in interface HTTPRequest
@Deprecated public byte[] getPartAsBytes(java.lang.String name, int maxlength)
HTTPRequest
getPartAsBytes
in interface HTTPRequest
public byte[] getPartAsBytesThrowing(java.lang.String name, int maxLength) throws java.util.NoSuchElementException, javax.naming.SizeLimitExceededException
getPartAsBytesThrowing
in interface HTTPRequest
java.util.NoSuchElementException
javax.naming.SizeLimitExceededException
public byte[] getPartAsBytesFailsafe(java.lang.String name, int maxLength)
HTTPRequest
getPartAsBytesFailsafe
in interface HTTPRequest
public void freeParts()
HTTPRequest
freeParts
in interface HTTPRequest
public long getLongParam(java.lang.String name, long defaultValue)
HTTPRequest
getLongParam
in interface HTTPRequest
public java.lang.String getMethod()
HTTPRequest
getMethod
in interface HTTPRequest
public Bucket getRawData()
HTTPRequest
getRawData
in interface HTTPRequest
public java.lang.String getHeader(java.lang.String name)
HTTPRequest
getHeader
in interface HTTPRequest
public int getContentLength()
HTTPRequest
getContentLength
in interface HTTPRequest
public java.lang.String[] getParts()
getParts
in interface HTTPRequest
public boolean isIncognito()
HTTPRequest
isIncognito
in interface HTTPRequest
public boolean isChrome()
HTTPRequest
isChrome
in interface HTTPRequest