public class RequestBody extends Object
Modifier and Type | Method and Description |
---|---|
String |
asHex()
Returns the HTTP body content as a simple hexadecimal character string.
|
String |
asSpacedHex()
Returns the HTTP body content as a simple space-delimited hexadecimal character string.
|
String |
asString()
Returns the HTTP body content as a plain string.
|
<T> T |
asType(Class<T> type)
Reads the input from the HTTP request parsed into a POJO.
|
<T> T |
asType(Type type,
Type... args)
Reads the input from the HTTP request parsed into a POJO.
|
int |
getContentLength()
Returns the content length of the body.
|
javax.servlet.ServletInputStream |
getInputStream()
Returns the HTTP body content as an
InputStream . |
Parser |
getParser()
Returns the parser matching the request
Content-Type header. |
ParserMatch |
getParserMatch()
Returns the parser and media type matching the request
Content-Type header. |
BufferedReader |
getReader()
Returns the HTTP body content as a
Reader . |
ReaderParser |
getReaderParser()
Returns the reader parser matching the request
Content-Type header. |
protected Reader |
getUnbufferedReader()
Same as
getReader() , but doesn't encapsulate the result in a BufferedReader ; |
public <T> T asType(Class<T> type) throws IOException, ParseException
The parser used is determined by the matching Content-Type
header on the request.
If type is Object.
, then the actual type will be determined
automatically based on the following input:
Type | JSON input | XML input | Return type |
---|---|---|---|
object |
|
ObjectMap |
|
array |
|
ObjectList |
|
string |
|
String |
|
number | 123 |
|
Number |
boolean |
|
Boolean |
|
null | or blank
|
Refer to POJO Categories for a complete definition of supported POJOs.
allowHeaderParams
init parameter is true, then first looks for &body=xxx
in the URL query string.
T
- The class type to instantiate.type
- The class type to instantiate.IOException
- If a problem occurred trying to read from the reader.ParseException
- If the input contains a syntax error or is malformed for the requested Accept
header or is not valid
for the specified type.public <T> T asType(Type type, Type... args)
This is similar to asType(Class)
but allows for complex collections of POJOs to be created.
Collections
must be followed by zero or one parameter representing the value type.
Maps
must be followed by zero or two parameters representing the key and value types.
allowHeaderParams
init parameter is true, then first looks for &body=xxx
in the URL query string.
T
- The class type to instantiate.type
- The type of object to create.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
args
- The type arguments of the class if it's a collection or map.
ClassMeta
, Class
, ParameterizedType
, GenericArrayType
public String asString() throws IOException
allowHeaderParams
init parameter is true, then first looks for &body=xxx
in the URL query string.
IOException
- If a problem occurred trying to read from the reader.public String asHex() throws IOException
0123456789ABCDEF
IOException
- If a problem occurred trying to read from the reader.public String asSpacedHex() throws IOException
01 23 45 67 89 AB CD EF
IOException
- If a problem occurred trying to read from the reader.public BufferedReader getReader() throws IOException
Reader
.
allowHeaderParams
init parameter is true, then first looks for &body=xxx
in the URL query string.
IOException
protected Reader getUnbufferedReader() throws IOException
getReader()
, but doesn't encapsulate the result in a BufferedReader
;IOException
public javax.servlet.ServletInputStream getInputStream() throws IOException
InputStream
.IOException
- If any error occurred while trying to get the input stream or wrap it in the GZIP wrapper.public ParserMatch getParserMatch()
Content-Type
header.Content-Type
header, or public Parser getParser()
Content-Type
header.Content-Type
header, or public ReaderParser getReaderParser()
Content-Type
header.Content-Type
header, or public int getContentLength()
Copyright © 2018 Apache. All rights reserved.