Class MessageBodyFactory
java.lang.Object
org.glassfish.jersey.message.internal.MessageBodyFactory
- All Implemented Interfaces:
MessageBodyWorkers
A factory for managing
MessageBodyReader, MessageBodyWriter instances.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCompares 2 instances implementing/inheriting the same super-type and returns which of the two instances has the super-type declaration closer in it's inheritance hierarchy tree.private static classAbstractEntityProviderModelcomparator which works as it is described in JAX-RS 1.x specification.static classConfigurator which initializes and registerMessageBodyWorkersinstance intoInjectionManagerandBootstrapBag.private static classprivate static classAbstractEntityProviderModelcomparator which works as it is described in JAX-RS 2.x specification. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate InjectionManagerprivate final Booleanprivate static final Loggerprivate static final intprivate static final floatprivate final Map<MessageBodyFactory.ModelLookupKey, List<ReaderModel>> private final Map<Class<?>, List<ReaderModel>> private final Map<MessageBodyFactory.ModelLookupKey, List<WriterModel>> private final Map<Class<?>, List<WriterModel>> static final KeyComparator<javax.ws.rs.core.MediaType> Media type comparator.private static final Function<ReaderModel, javax.ws.rs.ext.MessageBodyReader> private static final Function<WriterModel, javax.ws.rs.ext.MessageBodyWriter> private List<ReaderModel> private static final Comparator<AbstractEntityProviderModel<?>> 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.private List<WriterModel> -
Constructor Summary
ConstructorsConstructorDescriptionMessageBodyFactory(javax.ws.rs.core.Configuration configuration) Create a new message body factory. -
Method Summary
Modifier and TypeMethodDescriptionprivate <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, List<ReaderModel> models, PropertiesDelegate propertiesDelegate) private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t, 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, List<WriterModel> models, PropertiesDelegate propertiesDelegate) private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MediaType lookup, PropertiesDelegate propertiesDelegate) private static voidaddReaders(List<ReaderModel> models, Set<javax.ws.rs.ext.MessageBodyReader> readers, boolean custom) private static voidaddWriters(List<WriterModel> models, Set<javax.ws.rs.ext.MessageBodyWriter> writers, boolean custom) private static <T> voidgetCompatibleProvidersList(javax.ws.rs.core.MediaType mediaType, List<? extends AbstractEntityProviderModel<T>> set, Map<javax.ws.rs.core.MediaType, List<T>> subSet) private static <T> voidgetCompatibleProvidersMap(javax.ws.rs.core.MediaType mediaType, List<? extends AbstractEntityProviderModel<T>> set, Map<javax.ws.rs.core.MediaType, List<T>> subSet) <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t, 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate) Get a message body reader that matches a set of criteria.List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes(Class<?> type, Type genericType, Annotation[] annotations) Get the list of media types supported for a Java type.List<javax.ws.rs.core.MediaType> Get the list of media types supported for a Java type.List<javax.ws.rs.ext.MessageBodyReader> getMessageBodyReadersForType(Class<?> type) Get a list ofMessageBodyReaders that are suitable for the giventype.private static <T> List<javax.ws.rs.core.MediaType> getMessageBodyWorkersMediaTypesByType(List<? extends AbstractEntityProviderModel<T>> workerModels) <T> javax.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t, 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(Class<T> c, Type t, 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.MediaTypegetMessageBodyWriterMediaType(Class<?> c, Type t, Annotation[] as, 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.List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes(Class<?> c, Type t, Annotation[] as) Get the list of media types supported for a Java type.List<javax.ws.rs.core.MediaType> Get the list of media types supported for a Java type.List<javax.ws.rs.ext.MessageBodyWriter> getMessageBodyWritersForType(Class<?> type) Get a list ofMessageBodyWriters that are suitable for the giventype.getReaderModelsForType(Class<?> type) Get a list ofMessageBodyReadermodels that are suitable for the giventype.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.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.getWritersModelsForType(Class<?> type) Get a list ofMessageBodyWritermodels that are suitable for the giventype.voidinitialize(InjectionManager injectionManager) Must be initialize at the time of completed populatedInjectionManager.private <T> booleanisCompatible(AbstractEntityProviderModel<T> model, Class c, javax.ws.rs.core.MediaType mediaType) static booleanisReadable(javax.ws.rs.ext.MessageBodyReader<?> provider, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Safely invokesisReadablemethod on the supplied provider.static booleanisWriteable(javax.ws.rs.ext.MessageBodyWriter<?> provider, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Safely invokesisWriteablemethod on the supplied provider.private List<ReaderModel> processMessageBodyReadersForType(Class<?> clazz) private List<WriterModel> processMessageBodyWritersForType(Class<?> clazz) readersToString(Map<javax.ws.rs.core.MediaType, List<javax.ws.rs.ext.MessageBodyReader>> readers) Convert a map media type to list of message body readers to a string.readFrom(Class<?> rawType, Type type, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, String> httpHeaders, PropertiesDelegate propertiesDelegate, InputStream entityStream, Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce) Reads a type from theentityStreamusing interceptors.private <T> StringwritersToString(Map<javax.ws.rs.core.MediaType, List<javax.ws.rs.ext.MessageBodyWriter>> writers) Convert a map media type to list of message body writers to a string.writeTo(Object t, Class<?> rawType, Type type, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, PropertiesDelegate propertiesDelegate, OutputStream entityStream, Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors) Writers a type to theentityStreamusing interceptors.
-
Field Details
-
LOGGER
-
MEDIA_TYPE_KEY_COMPARATOR
Media type comparator. -
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. -
injectionManager
-
legacyProviderOrdering
-
readers
-
writers
-
readersCache
-
writersCache
-
LOOKUP_CACHE_INITIAL_CAPACITY
private static final int LOOKUP_CACHE_INITIAL_CAPACITY- See Also:
-
LOOKUP_CACHE_LOAD_FACTOR
private static final float LOOKUP_CACHE_LOAD_FACTOR- See Also:
-
mbrTypeLookupCache
-
mbwTypeLookupCache
-
typeToMediaTypeReadersCache
-
typeToMediaTypeWritersCache
-
mbrLookupCache
-
mbwLookupCache
-
MODEL_TO_WRITER
-
MODEL_TO_READER
-
-
Constructor Details
-
MessageBodyFactory
public MessageBodyFactory(javax.ws.rs.core.Configuration configuration) Create a new message body factory.- Parameters:
configuration- configuration. Optional - can be null.
-
-
Method Details
-
initialize
Must be initialize at the time of completed populatedInjectionManager.- Parameters:
injectionManager- completed injection manager.
-
addReaders
private static void addReaders(List<ReaderModel> models, Set<javax.ws.rs.ext.MessageBodyReader> readers, boolean custom) -
addWriters
private static void addWriters(List<WriterModel> models, Set<javax.ws.rs.ext.MessageBodyWriter> writers, boolean custom) -
getReaders
public Map<javax.ws.rs.core.MediaType,List<javax.ws.rs.ext.MessageBodyReader>> getReaders(javax.ws.rs.core.MediaType mediaType) Description copied from interface:MessageBodyWorkersGet the map of media type to list of message body writers that are compatible with a media type.- Specified by:
getReadersin interfaceMessageBodyWorkers- Parameters:
mediaType- the compatible media type.- Returns:
- the map of media type to list of message body writers.
-
getWriters
public Map<javax.ws.rs.core.MediaType,List<javax.ws.rs.ext.MessageBodyWriter>> getWriters(javax.ws.rs.core.MediaType mediaType) Description copied from interface:MessageBodyWorkersGet the map of media type to list of message body writers that are compatible with a media type.- Specified by:
getWritersin interfaceMessageBodyWorkers- Parameters:
mediaType- the compatible media type.- Returns:
- the map of media type to list of message body writers.
-
readersToString
public String readersToString(Map<javax.ws.rs.core.MediaType, List<javax.ws.rs.ext.MessageBodyReader>> readers) Description copied from interface:MessageBodyWorkersConvert a map media type to list of message body readers to a string.- Specified by:
readersToStringin interfaceMessageBodyWorkers- Parameters:
readers- the map media type to list of message body readers- Returns:
- the string representation.
-
writersToString
public String writersToString(Map<javax.ws.rs.core.MediaType, List<javax.ws.rs.ext.MessageBodyWriter>> writers) Description copied from interface:MessageBodyWorkersConvert a map media type to list of message body writers to a string.- Specified by:
writersToStringin interfaceMessageBodyWorkers- Parameters:
writers- the map media type to list of message body readers- Returns:
- the string representation.
-
toString
-
getMessageBodyReader
public <T> javax.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType) Description copied from interface:MessageBodyWorkersGet a message body reader that matches a set of criteria.- Specified by:
getMessageBodyReaderin interfaceMessageBodyWorkers- 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 byClass.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 byClass.getParameterAnnotations.mediaType- the media type of the data that will be read, this will be compared to the values ofConsumesfor 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate) Description copied from interface:MessageBodyWorkersGet a message body reader that matches a set of criteria.- Specified by:
getMessageBodyReaderin interfaceMessageBodyWorkers- 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 byClass.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 byClass.getParameterAnnotations.mediaType- the media type of the data that will be read, this will be compared to the values ofConsumesfor 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 List<javax.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes(Class<?> type, Type genericType, Annotation[] annotations) Description copied from interface:MessageBodyWorkersGet the list of media types supported for a Java type.- Specified by:
getMessageBodyReaderMediaTypesin interfaceMessageBodyWorkers- 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 byMethod.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 byMethod.getParameterAnnotations.- Returns:
- the list of supported media types, the list is ordered as follows: a/b invalid input: '<' a/* invalid input: '<' *\\/*
-
isCompatible
private <T> boolean isCompatible(AbstractEntityProviderModel<T> model, Class c, javax.ws.rs.core.MediaType mediaType) -
_getMessageBodyReader
private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, List<ReaderModel> models, PropertiesDelegate propertiesDelegate) -
_getMessageBodyReader
private <T> javax.ws.rs.ext.MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t, 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType) Description copied from interface:MessageBodyWorkersGet a message body writer that matches a set of criteria.- Specified by:
getMessageBodyWriterin interfaceMessageBodyWorkers- 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 byField.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 byField.getDeclaredAnnotations.mediaType- the media type of the data that will be written, this will be compared to the values ofProducesfor 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate) Description copied from interface:MessageBodyWorkersGet a message body writer that matches a set of criteria.- Specified by:
getMessageBodyWriterin interfaceMessageBodyWorkers- 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 byField.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 byField.getDeclaredAnnotations.mediaType- the media type of the data that will be written, this will be compared to the values ofProducesfor 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(Class<T> c, Type t, Annotation[] as, javax.ws.rs.core.MediaType mediaType, List<WriterModel> models, PropertiesDelegate propertiesDelegate) -
_getMessageBodyWriter
private <T> javax.ws.rs.ext.MessageBodyWriter<T> _getMessageBodyWriter(Class<T> c, Type t, 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, List<? extends AbstractEntityProviderModel<T>> set, Map<javax.ws.rs.core.MediaType, List<T>> subSet) -
getCompatibleProvidersList
private static <T> void getCompatibleProvidersList(javax.ws.rs.core.MediaType mediaType, List<? extends AbstractEntityProviderModel<T>> set, Map<javax.ws.rs.core.MediaType, List<T>> subSet) -
getMessageBodyWriterMediaTypes
public List<javax.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes(Class<?> c, Type t, Annotation[] as) Description copied from interface:MessageBodyWorkersGet the list of media types supported for a Java type.- Specified by:
getMessageBodyWriterMediaTypesin interfaceMessageBodyWorkers- 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 byField.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 byField.getDeclaredAnnotations.- Returns:
- the list of supported media types, the list is ordered as follows: a/b invalid input: '<' a/* invalid input: '<' *\\/*
-
getMessageBodyWritersForType
Description copied from interface:MessageBodyWorkersGet a list ofMessageBodyWriters that are suitable for the giventype. The list is sorted based on the class hierarchy (most specific writers are first).- Specified by:
getMessageBodyWritersForTypein interfaceMessageBodyWorkers- Parameters:
type- the class of object writers are requested for.- Returns:
- the list of supported
MessageBodyWriters for given class.
-
getWritersModelsForType
Description copied from interface:MessageBodyWorkersGet a list ofMessageBodyWritermodels that are suitable for the giventype. The list is sorted based on the class hierarchy (most specific writers are first).- Specified by:
getWritersModelsForTypein interfaceMessageBodyWorkers- Parameters:
type- the class of object writers are requested for.- Returns:
- the list of supported
MessageBodyWritermodels for given class.
-
processMessageBodyWritersForType
-
getMessageBodyWriterMediaTypesByType
Description copied from interface:MessageBodyWorkersGet the list of media types supported for a Java type.- Specified by:
getMessageBodyWriterMediaTypesByTypein interfaceMessageBodyWorkers- 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 invalid input: '<' a/* invalid input: '<' *\\/*
-
getMessageBodyReaderMediaTypesByType
Description copied from interface:MessageBodyWorkersGet the list of media types supported for a Java type.- Specified by:
getMessageBodyReaderMediaTypesByTypein interfaceMessageBodyWorkers- 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 invalid input: '<' a/* invalid input: '<' *\\/*
-
getMessageBodyWorkersMediaTypesByType
private static <T> List<javax.ws.rs.core.MediaType> getMessageBodyWorkersMediaTypesByType(List<? extends AbstractEntityProviderModel<T>> workerModels) -
getMessageBodyReadersForType
Description copied from interface:MessageBodyWorkersGet a list ofMessageBodyReaders that are suitable for the giventype. The list is sorted based on the class hierarchy (most specific readers are first).- Specified by:
getMessageBodyReadersForTypein interfaceMessageBodyWorkers- Parameters:
type- the class of object readers are requested for.- Returns:
- the list of supported
MessageBodyReaders for given class.
-
getReaderModelsForType
Description copied from interface:MessageBodyWorkersGet a list ofMessageBodyReadermodels that are suitable for the giventype. The list is sorted based on the class hierarchy (most specific readers are first).- Specified by:
getReaderModelsForTypein interfaceMessageBodyWorkers- Parameters:
type- the class of object readers are requested for.- Returns:
- the list of supported
MessageBodyReadermodels for given class.
-
processMessageBodyReadersForType
-
getMessageBodyWriterMediaType
public javax.ws.rs.core.MediaType getMessageBodyWriterMediaType(Class<?> c, Type t, Annotation[] as, List<javax.ws.rs.core.MediaType> acceptableMediaTypes) Description copied from interface:MessageBodyWorkersGet the most acceptable media type supported for a Java type given a set of acceptable media types.- Specified by:
getMessageBodyWriterMediaTypein interfaceMessageBodyWorkers- 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 byField.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 byField.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 Object readFrom(Class<?> rawType, Type type, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, String> httpHeaders, PropertiesDelegate propertiesDelegate, InputStream entityStream, Iterable<javax.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce) throws javax.ws.rs.WebApplicationException, IOExceptionDescription copied from interface:MessageBodyWorkersReads a type from theentityStreamusing interceptors. If the parameterinterceptis true thenreader interceptorsare executed before calling themessage body reader. The appropriatemessage body readeris chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.- Specified by:
readFromin interfaceMessageBodyWorkers- 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 byMethod.getParameterAnnotations.mediaType- the media type of the HTTP entity.httpHeaders- the mutable HTTP headers associated with HTTP entity.propertiesDelegate- request-scoped properties delegate.entityStream- theInputStreamof 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- iftrue, theNoContentExceptionthrown by a selected message body reader will be translated into aBadRequestExceptionas required by JAX-RS specification on the server side.- Returns:
- the entity that was read from the
entityStream. - Throws:
javax.ws.rs.WebApplicationException- Thrown whenmessage body readerfails.IOException- Thrown when reading from theentityStreamfails.
-
writeTo
public OutputStream writeTo(Object t, Class<?> rawType, Type type, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, PropertiesDelegate propertiesDelegate, OutputStream entityStream, Iterable<javax.ws.rs.ext.WriterInterceptor> writerInterceptors) throws IOException, javax.ws.rs.WebApplicationExceptionDescription copied from interface:MessageBodyWorkersWriters a type to theentityStreamusing interceptors. If the parameterinterceptis true thenwriter interceptorsare executed before calling themessage body writer. The appropriatemessage body writeris chosen after the interceptor execution based on parameter passed to this method and modified by the interceptors.- Specified by:
writeToin interfaceMessageBodyWorkers- Parameters:
t- Entity to be written to the entityStreamrawType- 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- theOutputStreamfor 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:
IOException- Thrown when reading from theentityStreamfails.javax.ws.rs.WebApplicationException- Thrown whenmessage body readerfails.
-
isWriteable
public static boolean isWriteable(javax.ws.rs.ext.MessageBodyWriter<?> provider, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Safely invokesisWriteablemethod on the supplied provider. Any exceptions will be logged at finer level.- Parameters:
provider- message body writer on which theisWriteableshould 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.GenericEntityprovides 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:
trueif the type is supported, otherwisefalse.
-
isReadable
public static boolean isReadable(javax.ws.rs.ext.MessageBodyReader<?> provider, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Safely invokesisReadablemethod on the supplied provider. Any exceptions will be logged at finer level.- Parameters:
provider- message body reader on which theisReadableshould be invoked. Safely invokesisReadablemethod 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 byMethod.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 byMethod.getParameterAnnotations.mediaType- the media type of the HTTP entity, if one is not specified in the request thenapplication/octet-streamis used.- Returns:
trueif the type is supported, otherwisefalse.
-