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.
|
ServletInputStream |
getInputStream()
Returns the HTTP body content as an
InputStream . |
InputStreamParser |
getInputStreamParser()
Returns the input stream parser matching the request
|
Parser |
getParser()
Returns the parser matching the request
|
ParserMatch |
getParserMatch()
Returns the parser and media type matching the request
|
BufferedReader |
getReader()
Returns the HTTP body content as a
Reader . |
ReaderParser |
getReaderParser()
Returns the reader parser matching the request
|
protected Reader |
getUnbufferedReader()
Same as
getReader() , but doesn't encapsulate the result in a BufferedReader ; |
public <T> T asType(Class<T> type) throws BadRequest, UnsupportedMediaType, InternalServerError
The parser used is determined by the matching
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 |
|
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.BadRequest
- Thrown if input could not be parsed or fails schema validation.UnsupportedMediaType
- Thrown if the Content-Type header value is not supported by one of the parsers.InternalServerError
- Thrown if an IOException
occurs.public <T> T asType(Type type, Type... args) throws BadRequest, UnsupportedMediaType, InternalServerError
This is similar to asType(Class)
but allows for complex collections of POJOs to be created.
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
BadRequest
- Thrown if input could not be parsed or fails schema validation.UnsupportedMediaType
- Thrown if the Content-Type header value is not supported by one of the parsers.InternalServerError
- Thrown if an IOException
occurs.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
- Thrown by underlying stream.protected Reader getUnbufferedReader() throws IOException
getReader()
, but doesn't encapsulate the result in a BufferedReader
;IOException
- Thrown by underlying stream.public 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()
public Parser getParser()
public ReaderParser getReaderParser()
public InputStreamParser getInputStreamParser()
public int getContentLength()
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.