Class RequestContent
   The RequestContent object is the API for accessing the content of an HTTP request.
   It can be accessed by passing it as a parameter on your REST Java method:
 
   
Example:
   
Some important methods on this class are:
- RequestContent- Methods for accessing the raw contents of the request content:
- Methods for parsing the contents of the request content:
- Other methods:
 
See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription<T> TReads the input from the HTTP request parsed into a POJO.<T> TReads the input from the HTTP request parsed into a POJO.byte[]asBytes()Returns the HTTP content content as a plain string.asHex()Returns the HTTP content content as a simple hexadecimal character string.Returns the HTTP content content as a simple space-delimited hexadecimal character string.asString()Returns the HTTP content content as a plain string.cache()Caches the content in memory for reuse.content(byte[] value) Sets the contents of this content.encoders(EncoderSet value) Sets the encoders to use for decoding this content.intReturns the content length of the content.jakarta.servlet.ServletInputStreamReturns the HTTP content content as anInputStream.Returns the parser and media type matching the requestContent-Type header.Returns the HTTP content content as aReader.protected ReaderSame asgetReader(), but doesn't encapsulate the result in aBufferedReader;maxInput(long value) Sets the max input value for this content.Sets the media type of this content.Sets the parser to use for this content.Sets the parsers to use for parsing this content.setSchema(HttpPartSchema schema) Sets the schema for this content.
- 
Constructor Details- 
RequestContentConstructor.- Parameters:
- req- The request creating this bean.
 
 
- 
- 
Method Details- 
encodersSets the encoders to use for decoding this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
parsersSets the parsers to use for parsing this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
setSchemaSets the schema for this content.- Parameters:
- schema- The new schema for this content.
- Returns:
- This object.
 
- 
maxInputSets the max input value for this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
mediaTypeSets the media type of this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
parserSets the parser to use for this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
contentSets the contents of this content.- Parameters:
- value- The new value for this setting.
- Returns:
- This object.
 
- 
asReads the input from the HTTP request parsed into a POJO.The parser used is determined by the matching Content-Type header on the request.If type is null orObject., then the actual type will be determined automatically based on the following input:class Type JSON input XML input Return type object "{...}" <object> ...</object> <x type ='object' > ...</x> JsonMaparray "[...]" <array> ...</array> <x type ='array' > ...</x> JsonListstring "'...'" <string> ...</string> <x type ='string' > ...</x> Stringnumber 123 <number> 123</number> <x type ='number' > ...</x> Numberboolean true <boolean> true</boolean> <x type ='boolean' > ...</x> Booleannull null or blank<null/> <x type ='null' /> null Refer to POJO Categories for a complete definition of supported POJOs. Examples:// Parse into an integer. int content1 =req .getContent().as(int .class );// Parse into an int array. int []content2 =req .getContent().as(int [].class );// Parse into a bean. MyBeancontent3 =req .getContent().as(MyBean.class );// Parse into a linked-list of objects. Listcontent4 =req .getContent().as(LinkedList.class );// Parse into a map of object keys/values. Mapcontent5 =req .getContent().as(TreeMap.class );Notes:- 
      If allowContentParaminit parameter is true, then first looks for&content=xxxin the URL query string.
 - Type Parameters:
- T- The class type to instantiate.
- Parameters:
- type- The class type to instantiate.
- Returns:
- The input parsed to a POJO.
- Throws:
- 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- IOExceptionoccurs.
 
- 
      If 
- 
aspublic <T> T as(Type type, Type... args) throws BadRequest, UnsupportedMediaType, InternalServerError Reads the input from the HTTP request parsed into a POJO.This is similar to as(Class)but allows for complex collections of POJOs to be created.Examples:// Parse into a linked-list of strings. List<String>content1 =req .getContent().as(LinkedList.class , String.class );// Parse into a linked-list of linked-lists of strings. List<List<String>>content2 =req .getContent().as(LinkedList.class , LinkedList.class , String.class );// Parse into a map of string keys/values. Map<String,String>content3 =req .getContent().as(TreeMap.class , String.class , String.class );// Parse into a map containing string keys and values of lists containing beans. Map<String,List<MyBean>>content4 =req .getContent().as(TreeMap.class , String.class , List.class , MyBean.class );Notes:- 
      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.
- 
      If allowContentParaminit parameter is true, then first looks for&content=xxxin the URL query string.
 - Type Parameters:
- T- The class type to instantiate.
- Parameters:
- type- The type of object to create.
 Can be any of the following:- ClassMeta,- Class,- ParameterizedType,- GenericArrayType
- args- The type arguments of the class if it's a collection or map.
 Can be any of the following:- ClassMeta,- Class,- ParameterizedType,- GenericArrayType
 Ignored if the main type is not a map or collection.
- Returns:
- The input parsed to a POJO.
- Throws:
- 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- IOExceptionoccurs.
 
- 
      
- 
asStringReturns the HTTP content content as a plain string.Notes:- 
      If allowContentParaminit parameter is true, then first looks for&content=xxxin the URL query string.
 - Returns:
- The incoming input from the connection as a plain string.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
      If 
- 
asBytesReturns the HTTP content content as a plain string.Notes:- 
      If allowContentParaminit parameter is true, then first looks for&content=xxxin the URL query string.
 - Returns:
- The incoming input from the connection as a plain string.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
      If 
- 
asHexReturns the HTTP content content as a simple hexadecimal character string.Example:0123456789ABCDEF - Returns:
- The incoming input from the connection as a plain string.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
asSpacedHexReturns the HTTP content content as a simple space-delimited hexadecimal character string.Example:01 23 45 67 89 AB CD EF - Returns:
- The incoming input from the connection as a plain string.
- Throws:
- IOException- If a problem occurred trying to read from the reader.
 
- 
getReaderReturns the HTTP content content as aReader.Notes:- 
      If allowContentParaminit parameter is true, then first looks for&content=xxxin the URL query string.
- Automatically handles GZipped input streams.
 - Returns:
- The content contents as a reader.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
      If 
- 
getUnbufferedReaderSame asgetReader(), but doesn't encapsulate the result in aBufferedReader;- Returns:
- An unbuffered reader.
- Throws:
- IOException- Thrown by underlying stream.
 
- 
getInputStreamReturns the HTTP content content as anInputStream.- Returns:
- The negotiated input stream.
- Throws:
- IOException- If any error occurred while trying to get the input stream or wrap it in the GZIP wrapper.
 
- 
getParserMatchReturns the parser and media type matching the requestContent-Type header.- Returns:
- The parser matching the request Content-Type header, orOptional.empty()if no matching parser was found. Includes the matching media type.
 
- 
getContentLengthReturns the content length of the content.- Returns:
- The content length of the content in bytes.
 
- 
cacheCaches the content in memory for reuse.- Returns:
- This object.
- Throws:
- IOException- If error occurs while reading stream.
 
 
-