Class MediaTypeUtils


  • public class MediaTypeUtils
    extends Object
    Utilities for MediaType.
    Author:
    poirigui
    • Constructor Summary

      Constructors 
      Constructor Description
      MediaTypeUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.ws.rs.core.MediaType negotiate​(javax.ws.rs.core.HttpHeaders headers, javax.ws.rs.core.MediaType... types)
      Perform content negotiation of a given set of HTTP headers against a list of possible media types.
      static javax.ws.rs.core.MediaType withoutQuality​(javax.ws.rs.core.MediaType mediaType)
      Create a media type without a quality indicator.
      static javax.ws.rs.core.MediaType withQuality​(javax.ws.rs.core.MediaType mediaType, double quality)
      Create a media type with a quality indicator.
    • Constructor Detail

      • MediaTypeUtils

        public MediaTypeUtils()
    • Method Detail

      • withQuality

        public static javax.ws.rs.core.MediaType withQuality​(javax.ws.rs.core.MediaType mediaType,
                                                             double quality)
        Create a media type with a quality indicator.
      • withoutQuality

        public static javax.ws.rs.core.MediaType withoutQuality​(javax.ws.rs.core.MediaType mediaType)
        Create a media type without a quality indicator.
      • negotiate

        public static javax.ws.rs.core.MediaType negotiate​(javax.ws.rs.core.HttpHeaders headers,
                                                           javax.ws.rs.core.MediaType... types)
                                                    throws javax.ws.rs.NotAcceptableException
        Perform content negotiation of a given set of HTTP headers against a list of possible media types.

        Media type may include a quality score by setting the q parameter. If omitted, this score defaults to 1.0. The pair of compatible accepted and produced types with the highest product is returned.

        Parameters:
        headers - HTTP headers from the client, HttpHeaders.getAcceptableMediaTypes() is used to determine acceptable media types
        types - an array of produced media types
        Returns:
        one of the produced media type, stripped if its quality score with withoutQuality(MediaType)
        Throws:
        javax.ws.rs.NotAcceptableException - if the negotiation fails (i.e. no media types can be satisfied)