Class ContentAnalyser
- java.lang.Object
-
- io.vertx.openapi.validation.analyser.ContentAnalyser
-
- Direct Known Subclasses:
ApplicationJsonAnalyser,MultipartFormAnalyser
public abstract class ContentAnalyser extends Object
The content analyser is responsible for checking if the content is syntactically correct, and transforming the content.These two methods are intentionally bundled in
ContentAnalyserto prevent some operations from having to be performed twice. This is particularly helpful if a library is used that cannot distinguish between these steps. In this case, an intermediate result that was generated incheckSyntacticalCorrectness(), for example, can be reused.Therefore, it is very important to ensure that the
checkSyntacticalCorrectness()method is always called before.
-
-
Field Summary
Fields Modifier and Type Field Description protected Buffercontentprotected StringcontentTypeprotected ValidationContextrequestOrResponse
-
Constructor Summary
Constructors Constructor Description ContentAnalyser(String contentType, Buffer content, ValidationContext context)Creates a new content analyser.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static ValidatorExceptionbuildSyntaxException(String message)Builds aValidatorExceptionfor the case that the content is syntactically incorrect.abstract voidcheckSyntacticalCorrectness()Checks if the content is syntactically correct.protected static ObjectdecodeJsonContent(Buffer content, ValidationContext requestOrResponse)Decodes the passed content as JSON.static ContentAnalysergetContentAnalyser(MediaType mediaType, String contentType, Buffer content, ValidationContext context)Returns the content analyser for the given content type.abstract Objecttransform()Transforms the content into a format that can be validated by theRequestValidator, orResponseValidator.
-
-
-
Field Detail
-
contentType
protected final String contentType
-
content
protected final Buffer content
-
requestOrResponse
protected final ValidationContext requestOrResponse
-
-
Constructor Detail
-
ContentAnalyser
public ContentAnalyser(String contentType, Buffer content, ValidationContext context)
Creates a new content analyser.- Parameters:
contentType- the content type.content- the content to be analysed.context- the context in which the content is used.
-
-
Method Detail
-
getContentAnalyser
public static ContentAnalyser getContentAnalyser(MediaType mediaType, String contentType, Buffer content, ValidationContext context)
Returns the content analyser for the given content type.- Parameters:
mediaType- the media type to determine the content analyser.contentType- the raw content type value from the HTTP header field.content- the content to be analysed.- Returns:
- the content analyser for the given content type.
-
checkSyntacticalCorrectness
public abstract void checkSyntacticalCorrectness()
Checks if the content is syntactically correct.Throws a
ValidatorExceptionif the content is syntactically incorrect.
-
transform
public abstract Object transform()
Transforms the content into a format that can be validated by theRequestValidator, orResponseValidator.Throws a
ValidatorExceptionif the content can't be transformed.- Returns:
- the transformed content.
-
buildSyntaxException
protected static ValidatorException buildSyntaxException(String message)
Builds aValidatorExceptionfor the case that the content is syntactically incorrect.- Parameters:
message- the error message.- Returns:
- the
ValidatorException.
-
decodeJsonContent
protected static Object decodeJsonContent(Buffer content, ValidationContext requestOrResponse)
Decodes the passed content as JSON.- Returns:
- an object representing the passed JSON content.
- Throws:
ValidatorException- if the content can't be decoded.
-
-