Class MessageBodyFactory

  • All Implemented Interfaces:
    MessageBodyWorkers

    public class MessageBodyFactory
    extends java.lang.Object
    implements MessageBodyWorkers
    A factory for managing MessageBodyReader, MessageBodyWriter instances.
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageBodyFactory​(javax.ws.rs.core.Configuration configuration)
      Create a new message body factory.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, java.util.List<ReaderModel> models, PropertiesDelegate propertiesDelegate)  
      private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MediaType lookup, PropertiesDelegate propertiesDelegate)  
      private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, java.util.List<WriterModel> models, PropertiesDelegate propertiesDelegate)  
      private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MediaType lookup, PropertiesDelegate propertiesDelegate)  
      private static void addReaders​(java.util.List<ReaderModel> models, java.util.Set<javax.ws.rs.ext.MessageBodyReader> readers, boolean custom)  
      private static void addWriters​(java.util.List<WriterModel> models, java.util.Set<javax.ws.rs.ext.MessageBodyWriter> writers, boolean custom)  
      private static <T> void getCompatibleProvidersList​(javax.ws.rs.core.MediaType mediaType, java.util.List<? extends AbstractEntityProviderModel<T>> set, java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> subSet)  
      private static <T> void getCompatibleProvidersMap​(javax.ws.rs.core.MediaType mediaType, java.util.List<? extends AbstractEntityProviderModel<T>> set, java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> subSet)  
      <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType)
      Get a message body reader that matches a set of criteria.
      <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
      Get a message body reader that matches a set of criteria.
      java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes​(java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations)
      Get the list of media types supported for a Java type.
      java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypesByType​(java.lang.Class<?> type)
      Get the list of media types supported for a Java type.
      java.util.List<javax.ws.rs.ext.MessageBodyReader> getMessageBodyReadersForType​(java.lang.Class<?> type)
      Get a list of MessageBodyReaders that are suitable for the given type.
      private static <T> java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWorkersMediaTypesByType​(java.util.List<? extends AbstractEntityProviderModel<T>> workerModels)  
      <T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType)
      Get a message body writer that matches a set of criteria.
      <T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter​(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
      Get a message body writer that matches a set of criteria.
      javax.ws.rs.core.MediaType getMessageBodyWriterMediaType​(java.lang.Class<?> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, java.util.List<javax.ws.rs.core.MediaType> acceptableMediaTypes)
      Get the most acceptable media type supported for a Java type given a set of acceptable media types.
      java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes​(java.lang.Class<?> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as)
      Get the list of media types supported for a Java type.
      java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypesByType​(java.lang.Class<?> type)
      Get the list of media types supported for a Java type.
      java.util.List<javax.ws.rs.ext.MessageBodyWriter> getMessageBodyWritersForType​(java.lang.Class<?> type)
      Get a list of MessageBodyWriters that are suitable for the given type.
      java.util.List<ReaderModel> getReaderModelsForType​(java.lang.Class<?> type)
      Get a list of MessageBodyReader models that are suitable for the given type.
      java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyReader>> getReaders​(javax.ws.rs.core.MediaType mediaType)
      Get the map of media type to list of message body writers that are compatible with a media type.
      java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyWriter>> getWriters​(javax.ws.rs.core.MediaType mediaType)
      Get the map of media type to list of message body writers that are compatible with a media type.
      java.util.List<WriterModel> getWritersModelsForType​(java.lang.Class<?> type)
      Get a list of MessageBodyWriter models that are suitable for the given type.
      void initialize​(InjectionManager injectionManager)
      Must be initialize at the time of completed populated InjectionManager.
      private <T> boolean isCompatible​(AbstractEntityProviderModel<T> model, java.lang.Class c, javax.ws.rs.core.MediaType mediaType)  
      static boolean isReadable​(javax.ws.rs.ext.MessageBodyReader<?> provider, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Safely invokes isReadable method on the supplied provider.
      static boolean isWriteable​(javax.ws.rs.ext.MessageBodyWriter<?> provider, java.lang.Class<?> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
      Safely invokes isWriteable method on the supplied provider.
      private java.util.List<ReaderModel> processMessageBodyReadersForType​(java.lang.Class<?> clazz)  
      private java.util.List<WriterModel> processMessageBodyWritersForType​(java.lang.Class<?> clazz)  
      java.lang.String readersToString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyReader>> readers)
      Convert a map media type to list of message body readers to a string.
      java.lang.Object readFrom​(java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.InputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce)
      Reads a type from the entityStream using interceptors.
      private <T> java.lang.String toString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> set)  
      java.lang.String writersToString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyWriter>> writers)
      Convert a map media type to list of message body writers to a string.
      java.io.OutputStream writeTo​(java.lang.Object t, java.lang.Class<?> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> httpHeaders, PropertiesDelegate propertiesDelegate, java.io.OutputStream entityStream, java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
      Writers a type to the entityStream using interceptors.
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • MEDIA_TYPE_KEY_COMPARATOR

        public static final KeyComparator<javax.ws.rs.core.MediaType> MEDIA_TYPE_KEY_COMPARATOR
        Media type comparator.
      • WORKER_BY_TYPE_COMPARATOR

        private static final java.util.Comparator<AbstractEntityProviderModel<?>> WORKER_BY_TYPE_COMPARATOR
        Compares entity providers by the provided class (most specific first) and then by the declared supported media types, if the provided classes are the same.
      • legacyProviderOrdering

        private final java.lang.Boolean legacyProviderOrdering
      • readersCache

        private final java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyReader>> readersCache
      • writersCache

        private final java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyWriter>> writersCache
      • LOOKUP_CACHE_INITIAL_CAPACITY

        private static final int LOOKUP_CACHE_INITIAL_CAPACITY
        See Also:
        Constant Field Values
      • LOOKUP_CACHE_LOAD_FACTOR

        private static final float LOOKUP_CACHE_LOAD_FACTOR
        See Also:
        Constant Field Values
      • mbrTypeLookupCache

        private final java.util.Map<java.lang.Class<?>,​java.util.List<ReaderModel>> mbrTypeLookupCache
      • mbwTypeLookupCache

        private final java.util.Map<java.lang.Class<?>,​java.util.List<WriterModel>> mbwTypeLookupCache
      • typeToMediaTypeReadersCache

        private final java.util.Map<java.lang.Class<?>,​java.util.List<javax.ws.rs.core.MediaType>> typeToMediaTypeReadersCache
      • typeToMediaTypeWritersCache

        private final java.util.Map<java.lang.Class<?>,​java.util.List<javax.ws.rs.core.MediaType>> typeToMediaTypeWritersCache
      • MODEL_TO_WRITER

        private static final java.util.function.Function<WriterModel,​javax.ws.rs.ext.MessageBodyWriter> MODEL_TO_WRITER
      • MODEL_TO_READER

        private static final java.util.function.Function<ReaderModel,​javax.ws.rs.ext.MessageBodyReader> MODEL_TO_READER
    • Constructor Detail

      • MessageBodyFactory

        public MessageBodyFactory​(javax.ws.rs.core.Configuration configuration)
        Create a new message body factory.
        Parameters:
        configuration - configuration. Optional - can be null.
    • Method Detail

      • initialize

        public void initialize​(InjectionManager injectionManager)
        Must be initialize at the time of completed populated InjectionManager.
        Parameters:
        injectionManager - completed injection manager.
      • addReaders

        private static void addReaders​(java.util.List<ReaderModel> models,
                                       java.util.Set<javax.ws.rs.ext.MessageBodyReader> readers,
                                       boolean custom)
      • addWriters

        private static void addWriters​(java.util.List<WriterModel> models,
                                       java.util.Set<javax.ws.rs.ext.MessageBodyWriter> writers,
                                       boolean custom)
      • getReaders

        public java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyReader>> getReaders​(javax.ws.rs.core.MediaType mediaType)
        Description copied from interface: MessageBodyWorkers
        Get the map of media type to list of message body writers that are compatible with a media type.
        Specified by:
        getReaders in interface MessageBodyWorkers
        Parameters:
        mediaType - the compatible media type.
        Returns:
        the map of media type to list of message body writers.
      • getWriters

        public java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyWriter>> getWriters​(javax.ws.rs.core.MediaType mediaType)
        Description copied from interface: MessageBodyWorkers
        Get the map of media type to list of message body writers that are compatible with a media type.
        Specified by:
        getWriters in interface MessageBodyWorkers
        Parameters:
        mediaType - the compatible media type.
        Returns:
        the map of media type to list of message body writers.
      • readersToString

        public java.lang.String readersToString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyReader>> readers)
        Description copied from interface: MessageBodyWorkers
        Convert a map media type to list of message body readers to a string.
        Specified by:
        readersToString in interface MessageBodyWorkers
        Parameters:
        readers - the map media type to list of message body readers
        Returns:
        the string representation.
      • writersToString

        public java.lang.String writersToString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<javax.ws.rs.ext.MessageBodyWriter>> writers)
        Description copied from interface: MessageBodyWorkers
        Convert a map media type to list of message body writers to a string.
        Specified by:
        writersToString in interface MessageBodyWorkers
        Parameters:
        writers - the map media type to list of message body readers
        Returns:
        the string representation.
      • toString

        private <T> java.lang.String toString​(java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> set)
      • getMessageBodyReader

        public <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader​(java.lang.Class<T> c,
                                                                             java.lang.reflect.Type t,
                                                                             java.lang.annotation.Annotation[] as,
                                                                             javax.ws.rs.core.MediaType mediaType)
        Description copied from interface: MessageBodyWorkers
        Get a message body reader that matches a set of criteria.
        Specified by:
        getMessageBodyReader in interface MessageBodyWorkers
        Type Parameters:
        T - the type of object to be read.
        Parameters:
        c - the class of object to be read.
        t - the type of object to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Class.getGenericParameterTypes.
        as - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Class.getParameterAnnotations.
        mediaType - the media type of the data that will be read, this will be compared to the values of Consumes for each candidate reader and only matching readers will be queried.
        Returns:
        a MessageBodyReader that matches the supplied criteria or null if none is found.
      • getMessageBodyReader

        public <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader​(java.lang.Class<T> c,
                                                                             java.lang.reflect.Type t,
                                                                             java.lang.annotation.Annotation[] as,
                                                                             javax.ws.rs.core.MediaType mediaType,
                                                                             PropertiesDelegate propertiesDelegate)
        Description copied from interface: MessageBodyWorkers
        Get a message body reader that matches a set of criteria.
        Specified by:
        getMessageBodyReader in interface MessageBodyWorkers
        Type Parameters:
        T - the type of object to be read.
        Parameters:
        c - the class of object to be read.
        t - the type of object to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Class.getGenericParameterTypes.
        as - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Class.getParameterAnnotations.
        mediaType - the media type of the data that will be read, this will be compared to the values of Consumes for each candidate reader and only matching readers will be queried.
        propertiesDelegate - request-scoped properties delegate.
        Returns:
        a MessageBodyReader that matches the supplied criteria or null if none is found.
      • getMessageBodyReaderMediaTypes

        public java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes​(java.lang.Class<?> type,
                                                                                         java.lang.reflect.Type genericType,
                                                                                         java.lang.annotation.Annotation[] annotations)
        Description copied from interface: MessageBodyWorkers
        Get the list of media types supported for a Java type.
        Specified by:
        getMessageBodyReaderMediaTypes in interface MessageBodyWorkers
        Parameters:
        type - the class of object that is to be read.
        genericType - the type of object to be read. E.g. if the message body is to be read as a method parameter, this will be the declared type of the parameter as returned by Method.getGenericParameterTypes.
        annotations - an array of the annotations on the declaration of the artifact that will be read. E.g. if the message body is to be consumed as a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
        Returns:
        the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
      • isCompatible

        private <T> boolean isCompatible​(AbstractEntityProviderModel<T> model,
                                         java.lang.Class c,
                                         javax.ws.rs.core.MediaType mediaType)
      • _getMessageBodyReader

        private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader​(java.lang.Class<T> c,
                                                                               java.lang.reflect.Type t,
                                                                               java.lang.annotation.Annotation[] as,
                                                                               javax.ws.rs.core.MediaType mediaType,
                                                                               java.util.List<ReaderModel> models,
                                                                               PropertiesDelegate propertiesDelegate)
      • _getMessageBodyReader

        private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader​(java.lang.Class<T> c,
                                                                               java.lang.reflect.Type t,
                                                                               java.lang.annotation.Annotation[] as,
                                                                               javax.ws.rs.core.MediaType mediaType,
                                                                               javax.ws.rs.core.MediaType lookup,
                                                                               PropertiesDelegate propertiesDelegate)
      • getMessageBodyWriter

        public <T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter​(java.lang.Class<T> c,
                                                                             java.lang.reflect.Type t,
                                                                             java.lang.annotation.Annotation[] as,
                                                                             javax.ws.rs.core.MediaType mediaType)
        Description copied from interface: MessageBodyWorkers
        Get a message body writer that matches a set of criteria.
        Specified by:
        getMessageBodyWriter in interface MessageBodyWorkers
        Type Parameters:
        T - the type of the object that is to be written.
        Parameters:
        c - the class of object that is to be written.
        t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
        as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
        mediaType - the media type of the data that will be written, this will be compared to the values of Produces for each candidate writer and only matching writers will be queried.
        Returns:
        a MessageBodyReader that matches the supplied criteria or null if none is found.
      • getMessageBodyWriter

        public <T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter​(java.lang.Class<T> c,
                                                                             java.lang.reflect.Type t,
                                                                             java.lang.annotation.Annotation[] as,
                                                                             javax.ws.rs.core.MediaType mediaType,
                                                                             PropertiesDelegate propertiesDelegate)
        Description copied from interface: MessageBodyWorkers
        Get a message body writer that matches a set of criteria.
        Specified by:
        getMessageBodyWriter in interface MessageBodyWorkers
        Type Parameters:
        T - the type of the object that is to be written.
        Parameters:
        c - the class of object that is to be written.
        t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
        as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
        mediaType - the media type of the data that will be written, this will be compared to the values of Produces for each candidate writer and only matching writers will be queried.
        propertiesDelegate - request-scoped properties delegate.
        Returns:
        a MessageBodyReader that matches the supplied criteria or null if none is found.
      • _getMessageBodyWriter

        private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter​(java.lang.Class<T> c,
                                                                               java.lang.reflect.Type t,
                                                                               java.lang.annotation.Annotation[] as,
                                                                               javax.ws.rs.core.MediaType mediaType,
                                                                               java.util.List<WriterModel> models,
                                                                               PropertiesDelegate propertiesDelegate)
      • _getMessageBodyWriter

        private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter​(java.lang.Class<T> c,
                                                                               java.lang.reflect.Type t,
                                                                               java.lang.annotation.Annotation[] as,
                                                                               javax.ws.rs.core.MediaType mediaType,
                                                                               javax.ws.rs.core.MediaType lookup,
                                                                               PropertiesDelegate propertiesDelegate)
      • getCompatibleProvidersMap

        private static <T> void getCompatibleProvidersMap​(javax.ws.rs.core.MediaType mediaType,
                                                          java.util.List<? extends AbstractEntityProviderModel<T>> set,
                                                          java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> subSet)
      • getCompatibleProvidersList

        private static <T> void getCompatibleProvidersList​(javax.ws.rs.core.MediaType mediaType,
                                                           java.util.List<? extends AbstractEntityProviderModel<T>> set,
                                                           java.util.Map<javax.ws.rs.core.MediaType,​java.util.List<T>> subSet)
      • getMessageBodyWriterMediaTypes

        public java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes​(java.lang.Class<?> c,
                                                                                         java.lang.reflect.Type t,
                                                                                         java.lang.annotation.Annotation[] as)
        Description copied from interface: MessageBodyWorkers
        Get the list of media types supported for a Java type.
        Specified by:
        getMessageBodyWriterMediaTypes in interface MessageBodyWorkers
        Parameters:
        c - the class of object that is to be written.
        t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
        as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
        Returns:
        the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
      • getMessageBodyWritersForType

        public java.util.List<javax.ws.rs.ext.MessageBodyWriter> getMessageBodyWritersForType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get a list of MessageBodyWriters that are suitable for the given type. The list is sorted based on the class hierarchy (most specific writers are first).
        Specified by:
        getMessageBodyWritersForType in interface MessageBodyWorkers
        Parameters:
        type - the class of object writers are requested for.
        Returns:
        the list of supported MessageBodyWriters for given class.
      • getWritersModelsForType

        public java.util.List<WriterModel> getWritersModelsForType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get a list of MessageBodyWriter models that are suitable for the given type. The list is sorted based on the class hierarchy (most specific writers are first).
        Specified by:
        getWritersModelsForType in interface MessageBodyWorkers
        Parameters:
        type - the class of object writers are requested for.
        Returns:
        the list of supported MessageBodyWriter models for given class.
      • processMessageBodyWritersForType

        private java.util.List<WriterModel> processMessageBodyWritersForType​(java.lang.Class<?> clazz)
      • getMessageBodyWriterMediaTypesByType

        public java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypesByType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get the list of media types supported for a Java type.
        Specified by:
        getMessageBodyWriterMediaTypesByType in interface MessageBodyWorkers
        Parameters:
        type - the class of object that is to be written.
        Returns:
        the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
      • getMessageBodyReaderMediaTypesByType

        public java.util.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypesByType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get the list of media types supported for a Java type.
        Specified by:
        getMessageBodyReaderMediaTypesByType in interface MessageBodyWorkers
        Parameters:
        type - the class of object that is to be read.
        Returns:
        the list of supported media types, the list is ordered as follows: a/b < a/* < *\\/*
      • getMessageBodyWorkersMediaTypesByType

        private static <T> java.util.List<javax.ws.rs.core.MediaType> getMessageBodyWorkersMediaTypesByType​(java.util.List<? extends AbstractEntityProviderModel<T>> workerModels)
      • getMessageBodyReadersForType

        public java.util.List<javax.ws.rs.ext.MessageBodyReader> getMessageBodyReadersForType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get a list of MessageBodyReaders that are suitable for the given type. The list is sorted based on the class hierarchy (most specific readers are first).
        Specified by:
        getMessageBodyReadersForType in interface MessageBodyWorkers
        Parameters:
        type - the class of object readers are requested for.
        Returns:
        the list of supported MessageBodyReaders for given class.
      • getReaderModelsForType

        public java.util.List<ReaderModel> getReaderModelsForType​(java.lang.Class<?> type)
        Description copied from interface: MessageBodyWorkers
        Get a list of MessageBodyReader models that are suitable for the given type. The list is sorted based on the class hierarchy (most specific readers are first).
        Specified by:
        getReaderModelsForType in interface MessageBodyWorkers
        Parameters:
        type - the class of object readers are requested for.
        Returns:
        the list of supported MessageBodyReader models for given class.
      • processMessageBodyReadersForType

        private java.util.List<ReaderModel> processMessageBodyReadersForType​(java.lang.Class<?> clazz)
      • getMessageBodyWriterMediaType

        public javax.ws.rs.core.MediaType getMessageBodyWriterMediaType​(java.lang.Class<?> c,
                                                                        java.lang.reflect.Type t,
                                                                        java.lang.annotation.Annotation[] as,
                                                                        java.util.List<javax.ws.rs.core.MediaType> acceptableMediaTypes)
        Description copied from interface: MessageBodyWorkers
        Get the most acceptable media type supported for a Java type given a set of acceptable media types.
        Specified by:
        getMessageBodyWriterMediaType in interface MessageBodyWorkers
        Parameters:
        c - the class of object that is to be written.
        t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
        as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
        acceptableMediaTypes - the list of acceptable media types, sorted according to the quality with the media type of highest quality occurring first first.
        Returns:
        the best media types
      • readFrom

        public java.lang.Object readFrom​(java.lang.Class<?> rawType,
                                         java.lang.reflect.Type type,
                                         java.lang.annotation.Annotation[] annotations,
                                         javax.ws.rs.core.MediaType mediaType,
                                         javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.String> httpHeaders,
                                         PropertiesDelegate propertiesDelegate,
                                         java.io.InputStream entityStream,
                                         java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors,
                                         boolean translateNce)
                                  throws javax.ws.rs.WebApplicationException,
                                         java.io.IOException
        Description copied from interface: MessageBodyWorkers
        Reads a type from the entityStream using interceptors. If the parameter intercept is true then reader interceptors are executed before calling the message body reader. The appropriate message body reader is chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.
        Specified by:
        readFrom in interface MessageBodyWorkers
        Parameters:
        rawType - raw Java entity type.
        type - generic Java entity type.
        annotations - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
        mediaType - the media type of the HTTP entity.
        httpHeaders - the mutable HTTP headers associated with HTTP entity.
        propertiesDelegate - request-scoped properties delegate.
        entityStream - the InputStream of the HTTP entity. The stream is not closed after reading the entity.
        readerInterceptors - Reader interceptor that are to be used to intercept the reading of an entity. The interceptors will be executed in the same order as given in this parameter.
        translateNce - if true, the NoContentException thrown by a selected message body reader will be translated into a BadRequestException as required by JAX-RS specification on the server side.
        Returns:
        the entity that was read from the entityStream.
        Throws:
        javax.ws.rs.WebApplicationException - Thrown when message body reader fails.
        java.io.IOException - Thrown when reading from the entityStream fails.
      • writeTo

        public java.io.OutputStream writeTo​(java.lang.Object t,
                                            java.lang.Class<?> rawType,
                                            java.lang.reflect.Type type,
                                            java.lang.annotation.Annotation[] annotations,
                                            javax.ws.rs.core.MediaType mediaType,
                                            javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> httpHeaders,
                                            PropertiesDelegate propertiesDelegate,
                                            java.io.OutputStream entityStream,
                                            java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors)
                                     throws java.io.IOException,
                                            javax.ws.rs.WebApplicationException
        Description copied from interface: MessageBodyWorkers
        Writers a type to the entityStream using interceptors. If the parameter intercept is true then writer interceptors are executed before calling the message body writer. The appropriate message body writer is chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.
        Specified by:
        writeTo in interface MessageBodyWorkers
        Parameters:
        t - Entity to be written to the entityStream
        rawType - raw Java entity type.
        type - generic Java entity type.
        annotations - an array of the annotations on the resource method that returns the object.
        mediaType - the media type of the HTTP entity.
        httpHeaders - the mutable HTTP headers associated with HTTP entity.
        propertiesDelegate - request-scoped properties delegate.
        entityStream - the OutputStream for the HTTP entity.
        writerInterceptors - Writer interceptor that are to be used to intercept the writing of an entity. The interceptors will be executed in the same order as given in this parameter.
        Returns:
        Outer output stream that should be closed by the caller.
        Throws:
        java.io.IOException - Thrown when reading from the entityStream fails.
        javax.ws.rs.WebApplicationException - Thrown when message body reader fails.
      • isWriteable

        public static boolean isWriteable​(javax.ws.rs.ext.MessageBodyWriter<?> provider,
                                          java.lang.Class<?> type,
                                          java.lang.reflect.Type genericType,
                                          java.lang.annotation.Annotation[] annotations,
                                          javax.ws.rs.core.MediaType mediaType)
        Safely invokes isWriteable method on the supplied provider. Any exceptions will be logged at finer level.
        Parameters:
        provider - message body writer on which the isWriteable should be invoked.
        type - the class of instance that is to be written.
        genericType - the type of instance to be written, obtained either by reflection of a resource method return type or via inspection of the returned instance. GenericEntity provides a way to specify this information at runtime.
        annotations - an array of the annotations attached to the message entity instance.
        mediaType - the media type of the HTTP entity.
        Returns:
        true if the type is supported, otherwise false.
      • isReadable

        public static boolean isReadable​(javax.ws.rs.ext.MessageBodyReader<?> provider,
                                         java.lang.Class<?> type,
                                         java.lang.reflect.Type genericType,
                                         java.lang.annotation.Annotation[] annotations,
                                         javax.ws.rs.core.MediaType mediaType)
        Safely invokes isReadable method on the supplied provider. Any exceptions will be logged at finer level.
        Parameters:
        provider - message body reader on which the isReadable should be invoked. Safely invokes isReadable method on the underlying provider.
        type - the class of instance to be produced.
        genericType - the type of instance to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Method.getGenericParameterTypes.
        annotations - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Method.getParameterAnnotations.
        mediaType - the media type of the HTTP entity, if one is not specified in the request then application/octet-stream is used.
        Returns:
        true if the type is supported, otherwise false.