public class MessageBodyFactory extends Object implements MessageBodyWorkers
MessageBodyReader, MessageBodyWriter instances.| Modifier and Type | Class and Description |
|---|---|
static class |
MessageBodyFactory.MessageBodyWorkersConfigurator
Configurator which initializes and register
MessageBodyWorkers instance into InjectionManager and
BootstrapBag. |
| Modifier and Type | Field and Description |
|---|---|
static org.glassfish.jersey.internal.util.collection.KeyComparator<jakarta.ws.rs.core.MediaType> |
MEDIA_TYPE_KEY_COMPARATOR
Media type comparator.
|
| Constructor and Description |
|---|
MessageBodyFactory(jakarta.ws.rs.core.Configuration configuration)
Create a new message body factory.
|
| Modifier and Type | Method and Description |
|---|---|
<T> jakarta.ws.rs.ext.MessageBodyReader<T> |
getMessageBodyReader(Class<T> c,
Type t,
Annotation[] as,
jakarta.ws.rs.core.MediaType mediaType)
Get a message body reader that matches a set of criteria.
|
<T> jakarta.ws.rs.ext.MessageBodyReader<T> |
getMessageBodyReader(Class<T> c,
Type t,
Annotation[] as,
jakarta.ws.rs.core.MediaType mediaType,
PropertiesDelegate propertiesDelegate)
Get a message body reader that matches a set of criteria.
|
List<jakarta.ws.rs.core.MediaType> |
getMessageBodyReaderMediaTypes(Class<?> type,
Type genericType,
Annotation[] annotations)
Get the list of media types supported for a Java type.
|
List<jakarta.ws.rs.core.MediaType> |
getMessageBodyReaderMediaTypesByType(Class<?> type)
Get the list of media types supported for a Java type.
|
List<jakarta.ws.rs.ext.MessageBodyReader> |
getMessageBodyReadersForType(Class<?> type)
Get a list of
MessageBodyReaders that are suitable for the given type. |
<T> jakarta.ws.rs.ext.MessageBodyWriter<T> |
getMessageBodyWriter(Class<T> c,
Type t,
Annotation[] as,
jakarta.ws.rs.core.MediaType mediaType)
Get a message body writer that matches a set of criteria.
|
<T> jakarta.ws.rs.ext.MessageBodyWriter<T> |
getMessageBodyWriter(Class<T> c,
Type t,
Annotation[] as,
jakarta.ws.rs.core.MediaType mediaType,
PropertiesDelegate propertiesDelegate)
Get a message body writer that matches a set of criteria.
|
jakarta.ws.rs.core.MediaType |
getMessageBodyWriterMediaType(Class<?> c,
Type t,
Annotation[] as,
List<jakarta.ws.rs.core.MediaType> acceptableMediaTypes)
Get the most acceptable media type supported for a Java type given a set of
acceptable media types.
|
List<jakarta.ws.rs.core.MediaType> |
getMessageBodyWriterMediaTypes(Class<?> c,
Type t,
Annotation[] as)
Get the list of media types supported for a Java type.
|
List<jakarta.ws.rs.core.MediaType> |
getMessageBodyWriterMediaTypesByType(Class<?> type)
Get the list of media types supported for a Java type.
|
List<jakarta.ws.rs.ext.MessageBodyWriter> |
getMessageBodyWritersForType(Class<?> type)
Get a list of
MessageBodyWriters that are suitable for the given type. |
List<ReaderModel> |
getReaderModelsForType(Class<?> type)
Get a list of
MessageBodyReader models that are suitable for the given type. |
Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyReader>> |
getReaders(jakarta.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with
a media type.
|
Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyWriter>> |
getWriters(jakarta.ws.rs.core.MediaType mediaType)
Get the map of media type to list of message body writers that are compatible with
a media type.
|
List<WriterModel> |
getWritersModelsForType(Class<?> type)
Get a list of
MessageBodyWriter models that are suitable for the given type. |
void |
initialize(org.glassfish.jersey.internal.inject.InjectionManager injectionManager)
Must be initialize at the time of completed populated
InjectionManager. |
static boolean |
isReadable(jakarta.ws.rs.ext.MessageBodyReader<?> provider,
Class<?> type,
Type genericType,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType)
Safely invokes
isReadable method on the supplied provider. |
static boolean |
isWriteable(jakarta.ws.rs.ext.MessageBodyWriter<?> provider,
Class<?> type,
Type genericType,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType)
Safely invokes
isWriteable method on the supplied provider. |
String |
readersToString(Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyReader>> readers)
Convert a map media type to list of message body readers to a string.
|
Object |
readFrom(Class<?> rawType,
Type type,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType,
jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders,
PropertiesDelegate propertiesDelegate,
InputStream entityStream,
Iterable<jakarta.ws.rs.ext.ReaderInterceptor> readerInterceptors,
boolean translateNce)
Reads a type from the
entityStream using interceptors. |
String |
writersToString(Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyWriter>> writers)
Convert a map media type to list of message body writers to a string.
|
OutputStream |
writeTo(Object t,
Class<?> rawType,
Type type,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType,
jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
PropertiesDelegate propertiesDelegate,
OutputStream entityStream,
Iterable<jakarta.ws.rs.ext.WriterInterceptor> writerInterceptors)
Writers a type to the
entityStream using interceptors. |
public static final org.glassfish.jersey.internal.util.collection.KeyComparator<jakarta.ws.rs.core.MediaType> MEDIA_TYPE_KEY_COMPARATOR
public MessageBodyFactory(jakarta.ws.rs.core.Configuration configuration)
configuration - configuration. Optional - can be null.public void initialize(org.glassfish.jersey.internal.inject.InjectionManager injectionManager)
InjectionManager.injectionManager - completed injection manager.public Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyReader>> getReaders(jakarta.ws.rs.core.MediaType mediaType)
MessageBodyWorkersgetReaders in interface MessageBodyWorkersmediaType - the compatible media type.public Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyWriter>> getWriters(jakarta.ws.rs.core.MediaType mediaType)
MessageBodyWorkersgetWriters in interface MessageBodyWorkersmediaType - the compatible media type.public String readersToString(Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyReader>> readers)
MessageBodyWorkersreadersToString in interface MessageBodyWorkersreaders - the map media type to list of message body readerspublic String writersToString(Map<jakarta.ws.rs.core.MediaType,List<jakarta.ws.rs.ext.MessageBodyWriter>> writers)
MessageBodyWorkerswritersToString in interface MessageBodyWorkerswriters - the map media type to list of message body readerspublic <T> jakarta.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t, Annotation[] as, jakarta.ws.rs.core.MediaType mediaType)
MessageBodyWorkersgetMessageBodyReader in interface MessageBodyWorkersT - the type of object to be read.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.public <T> jakarta.ws.rs.ext.MessageBodyReader<T> getMessageBodyReader(Class<T> c, Type t, Annotation[] as, jakarta.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
MessageBodyWorkersgetMessageBodyReader in interface MessageBodyWorkersT - the type of object to be read.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.public List<jakarta.ws.rs.core.MediaType> getMessageBodyReaderMediaTypes(Class<?> type, Type genericType, Annotation[] annotations)
MessageBodyWorkersgetMessageBodyReaderMediaTypes in interface MessageBodyWorkerstype - 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.public <T> jakarta.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t, Annotation[] as, jakarta.ws.rs.core.MediaType mediaType)
MessageBodyWorkersgetMessageBodyWriter in interface MessageBodyWorkersT - the type of the object that is to be written.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.public <T> jakarta.ws.rs.ext.MessageBodyWriter<T> getMessageBodyWriter(Class<T> c, Type t, Annotation[] as, jakarta.ws.rs.core.MediaType mediaType, PropertiesDelegate propertiesDelegate)
MessageBodyWorkersgetMessageBodyWriter in interface MessageBodyWorkersT - the type of the object that is to be written.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.public List<jakarta.ws.rs.core.MediaType> getMessageBodyWriterMediaTypes(Class<?> c, Type t, Annotation[] as)
MessageBodyWorkersgetMessageBodyWriterMediaTypes in interface MessageBodyWorkersc - 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.public List<jakarta.ws.rs.ext.MessageBodyWriter> getMessageBodyWritersForType(Class<?> type)
MessageBodyWorkersMessageBodyWriters that are suitable for the given type. The list is sorted based on the
class hierarchy (most specific writers are first).getMessageBodyWritersForType in interface MessageBodyWorkerstype - the class of object writers are requested for.MessageBodyWriters for given class.public List<WriterModel> getWritersModelsForType(Class<?> type)
MessageBodyWorkersMessageBodyWriter models that are suitable for the given type.
The list is sorted based on the class hierarchy (most specific writers are first).getWritersModelsForType in interface MessageBodyWorkerstype - the class of object writers are requested for.MessageBodyWriter models for given class.public List<jakarta.ws.rs.core.MediaType> getMessageBodyWriterMediaTypesByType(Class<?> type)
MessageBodyWorkersgetMessageBodyWriterMediaTypesByType in interface MessageBodyWorkerstype - the class of object that is to be written.public List<jakarta.ws.rs.core.MediaType> getMessageBodyReaderMediaTypesByType(Class<?> type)
MessageBodyWorkersgetMessageBodyReaderMediaTypesByType in interface MessageBodyWorkerstype - the class of object that is to be read.public List<jakarta.ws.rs.ext.MessageBodyReader> getMessageBodyReadersForType(Class<?> type)
MessageBodyWorkersMessageBodyReaders that are suitable for the given type. The list is sorted based on the
class hierarchy (most specific readers are first).getMessageBodyReadersForType in interface MessageBodyWorkerstype - the class of object readers are requested for.MessageBodyReaders for given class.public List<ReaderModel> getReaderModelsForType(Class<?> type)
MessageBodyWorkersMessageBodyReader models that are suitable for the given type.
The list is sorted based on the class hierarchy (most specific readers are first).getReaderModelsForType in interface MessageBodyWorkerstype - the class of object readers are requested for.MessageBodyReader models for given class.public jakarta.ws.rs.core.MediaType getMessageBodyWriterMediaType(Class<?> c, Type t, Annotation[] as, List<jakarta.ws.rs.core.MediaType> acceptableMediaTypes)
MessageBodyWorkersgetMessageBodyWriterMediaType in interface MessageBodyWorkersc - 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.public Object readFrom(Class<?> rawType, Type type, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders, PropertiesDelegate propertiesDelegate, InputStream entityStream, Iterable<jakarta.ws.rs.ext.ReaderInterceptor> readerInterceptors, boolean translateNce) throws jakarta.ws.rs.WebApplicationException, IOException
MessageBodyWorkersentityStream 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.readFrom in interface MessageBodyWorkersrawType - 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.entityStream.jakarta.ws.rs.WebApplicationException - Thrown when message body
reader fails.IOException - Thrown when reading from the entityStream fails.public OutputStream writeTo(Object t, Class<?> rawType, Type type, Annotation[] annotations, jakarta.ws.rs.core.MediaType mediaType, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, PropertiesDelegate propertiesDelegate, OutputStream entityStream, Iterable<jakarta.ws.rs.ext.WriterInterceptor> writerInterceptors) throws IOException, jakarta.ws.rs.WebApplicationException
MessageBodyWorkersentityStream 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.writeTo in interface MessageBodyWorkerst - 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 - 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.IOException - Thrown when reading from the entityStream fails.jakarta.ws.rs.WebApplicationException - Thrown when message body
reader fails.public static boolean isWriteable(jakarta.ws.rs.ext.MessageBodyWriter<?> provider,
Class<?> type,
Type genericType,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType)
isWriteable method on the supplied provider.
Any exceptions will be logged at finer level.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.true if the type is supported, otherwise false.public static boolean isReadable(jakarta.ws.rs.ext.MessageBodyReader<?> provider,
Class<?> type,
Type genericType,
Annotation[] annotations,
jakarta.ws.rs.core.MediaType mediaType)
isReadable method on the supplied provider.
Any exceptions will be logged at finer level.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.true if the type is supported, otherwise false.Copyright © 2007-2021, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.