com.ibm.commerce.foundation.rest.utils

Class MediaTypeHelper

  • java.lang.Object
    • com.ibm.commerce.foundation.rest.utils.MediaTypeHelper


  • public class MediaTypeHelper
    extends java.lang.Object
    This class contains methods to read response format to media type mapping. It also read the "Accept" header if response format query parameter is not passed.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String COPYRIGHT
      IBM Copyright notice field.
      static java.lang.String FORMAT_ATOM
      The response format value for Atom feeds.
      static java.lang.String FORMAT_JSON
      The response format value for JSON.
      static java.lang.String FORMAT_XHTML
      The response format value for XHTML.
      static java.lang.String FORMAT_XML
      The response format value for XML.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static void createInstance(java.lang.String respFormatMappingLocation)
      Creates the instance based on configuration file.
      static MediaTypeHelper getInstance()
      Gets the single instance of MediaTypeHelper.
      javax.ws.rs.core.MediaType getResponseMediaType(java.lang.String responseFormatShortcut, javax.ws.rs.core.Request request)
      Returns a selected media type for the specified response format and request.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright notice field.
        See Also:
        Constant Field Values
      • FORMAT_ATOM

        public static final java.lang.String FORMAT_ATOM
        The response format value for Atom feeds. Value is "atom".
        See Also:
        Constant Field Values
      • FORMAT_JSON

        public static final java.lang.String FORMAT_JSON
        The response format value for JSON. Value is "json".
        See Also:
        Constant Field Values
      • FORMAT_XHTML

        public static final java.lang.String FORMAT_XHTML
        The response format value for XHTML. Value is "xhtml".
        See Also:
        Constant Field Values
      • FORMAT_XML

        public static final java.lang.String FORMAT_XML
        The response format value for XML. Value is "xml".
        See Also:
        Constant Field Values
    • Method Detail

      • getInstance

        public static MediaTypeHelper getInstance()
        Gets the single instance of MediaTypeHelper.
        Returns:
        single instance of MediaTypeHelper
      • createInstance

        public static void createInstance(java.lang.String respFormatMappingLocation)
        Creates the instance based on configuration file.
        Parameters:
        respFormatMappingLocation - the configuration file location
      • getResponseMediaType

        public javax.ws.rs.core.MediaType getResponseMediaType(java.lang.String responseFormatShortcut,
                                                               javax.ws.rs.core.Request request)
        Returns a selected media type for the specified response format and request.

        If response format shortcut is specified, then this method returns the media type corresponding to the response format shortcut using the response format shortcut mappings specified in the resource bundles /WEB-INF/config/responseformat-mapping and /WEB-INF/config/responseformat-mapping-ext.

        If response format shortcut is not specified, then this method uses the request object to select a media type. It checks the list of acceptable media types specified by the client in the Accept request header and returns a matching media type in the list of media types supported by the application. The list of supported media types are derived based on the media types supported by all the entity providers in the application using the javax.ws.rs.Produces annotation. The application entity providers are specified in the resource bundles /WEB-INF/config/providers and /WEB-INF/config/providers-ext.

        If a media type is not resolved using either of response format shortcut or the request object, then this method returns application/json as the media type.

        Parameters:
        responseFormatShortcut - the response format shortcut specified in the http request.
        request - the Request object in the javax.ws.rs.core.Context.
        Returns:
        the selected media type.