Class 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 ContentAnalyser to 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 in checkSyntacticalCorrectness(), for example, can be reused.

    Therefore, it is very important to ensure that the checkSyntacticalCorrectness() method is always called before.

    • Field Detail

      • contentType

        protected final String contentType
      • content

        protected final Buffer content
    • 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 ValidatorException if the content is syntactically incorrect.

      • 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.