Top Description Methods
javax.ws.rs.ext

public Interface Providers

Imports
java.lang.annotation.Annotation, java.lang.reflect.Type, javax.ws.rs.core.MediaType

An injectable interface providing runtime lookup of provider instances.
Authors
Paul Sandoz, Marc Hadley
Since
1.0
See Also
javax.ws.rs.core.Context, MessageBodyReader, MessageBodyWriter, ContextResolver, ExceptionMapper

Method Summary

Modifier and TypeMethod and Description
public <
type of the context.
T
>
ContextResolver<T>

Returns:

a matching context resolver instance or null if no matching context providers are found.
getContextResolver
(Class<T>
the class of context desired.
contextType
,
MediaType
the media type of data for which a context is required.
mediaType
)

Get a context resolver for a particular type of context and media type.

public <
type of the exception handled by the exception mapping provider.
T extends Throwable
>
ExceptionMapper<T>

Returns:

an ExceptionMapper for the supplied type or null if none is found.
getExceptionMapper
(Class<T>
the class of exception.
type
)

Get an exception mapping provider for a particular class of exception.

public <
type of the the object that is to be read.
T
>
MessageBodyReader<T>

Returns:

a MessageBodyReader that matches the supplied criteria or null if none is found.
getMessageBodyReader
(Class<T>
the class of the object that is to be read.
type
,
Type
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.
genericType
,
Annotation[]
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.
annotations
,
MediaType
the media type of the data that will be read.
mediaType
)

Get a message body reader that matches a set of criteria.

public <
type of the object that is to be written.
T
>
MessageBodyWriter<T>

Returns:

a MessageBodyReader that matches the supplied criteria or null if none is found.
getMessageBodyWriter
(Class<T>
the class of the object that is to be written.
type
,
Type
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.
genericType
,
Annotation[]
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.
annotations
,
MediaType
the media type of the data that will be written.
mediaType
)

Get a message body writer that matches a set of criteria.

Method Detail

getContextResolverback to summary
public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType)

Get a context resolver for a particular type of context and media type. The set of resolvers is first filtered by comparing the supplied value of mediaType with the value of each resolver's javax.ws.rs.Produces, ensuring the generic type of the context resolver is assignable to the supplied value of contextType, and eliminating those that do not match. If only one resolver matches the criteria then it is returned. If more than one resolver matches then the list of matching resolvers is ordered with those with the best matching values of javax.ws.rs.Produces (x/y > x/* > */*) sorted first. A proxy is returned that delegates calls to ContextResolver#getContext(java.lang.Class) to each matching context resolver in order and returns the first non-null value it obtains or null if all matching context resolvers return null.

Parameters
<T>
type of the context.
contextType:Class<T>

the class of context desired.

mediaType:MediaType

the media type of data for which a context is required.

Returns:ContextResolver<T>

a matching context resolver instance or null if no matching context providers are found.

getExceptionMapperback to summary
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type)

Get an exception mapping provider for a particular class of exception. Returns the provider whose generic type is the nearest superclass of type.

Parameters
<T>
type of the exception handled by the exception mapping provider.
type:Class<T>

the class of exception.

Returns:ExceptionMapper<T>

an ExceptionMapper for the supplied type or null if none is found.

getMessageBodyReaderback to summary
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Get a message body reader that matches a set of criteria. The set of readers is first filtered by comparing the supplied value of mediaType with the value of each reader's javax.ws.rs.Consumes, ensuring the supplied value of type is assignable to the generic type of the reader, and eliminating those that do not match. The list of matching readers is then ordered with those with the best matching values of javax.ws.rs.Consumes (x/y > x/* > */*) sorted first. Finally, the MessageBodyReader#isReadable(Class, Type, Annotation[], MediaType) method is called on each reader in order using the supplied criteria and the first reader that returns true is selected and returned.

Parameters
<T>
type of the the object that is to be read.
type:Class<T>

the class of the object that is to be read.

genericType:Type

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.

annotations:Annotation[]

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:MediaType

the media type of the data that will be read.

Returns:MessageBodyReader<T>

a MessageBodyReader that matches the supplied criteria or null if none is found.

getMessageBodyWriterback to summary
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)

Get a message body writer that matches a set of criteria. The set of writers is first filtered by comparing the supplied value of mediaType with the value of each writer's javax.ws.rs.Produces, ensuring the supplied value of type is assignable to the generic type of the reader, and eliminating those that do not match. The list of matching writers is then ordered with those with the best matching values of javax.ws.rs.Produces (x/y > x/* > */*) sorted first. Finally, the MessageBodyWriter#isWriteable(Class, Type, Annotation[], MediaType) method is called on each writer in order using the supplied criteria and the first writer that returns true is selected and returned.

Parameters
<T>
type of the object that is to be written.
type:Class<T>

the class of the object that is to be written.

genericType:Type

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.

annotations:Annotation[]

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:MediaType

the media type of the data that will be written.

Returns:MessageBodyWriter<T>

a MessageBodyReader that matches the supplied criteria or null if none is found.