public class ClientConfiguration extends Object implements Configuration, Configurable<ClientConfiguration>, Providers, HeaderValueProcessor
Modifier and Type | Field and Description |
---|---|
protected ResteasyProviderFactory |
providerFactory |
Constructor and Description |
---|
ClientConfiguration(ClientConfiguration parent) |
ClientConfiguration(ResteasyProviderFactory factory) |
Modifier and Type | Method and Description |
---|---|
Set<Class<?>> |
getClasses()
Get the immutable set of registered JAX-RS component (such as provider or
feature ) classes to be instantiated, injected and utilized in the scope
of the configurable instance. |
Configuration |
getConfiguration()
Get a live view of an internal configuration state of this configurable instance.
|
<T> ContextResolver<T> |
getContextResolver(Class<T> contextType,
MediaType mediaType)
Get a context resolver for a particular type of context and media type.
|
Map<Class<?>,Integer> |
getContracts(Class<?> componentClass)
Get the extension contract registration information for a component of a given class.
|
Set<DynamicFeature> |
getDynamicFeatures() |
<T extends Throwable> |
getExceptionMapper(Class<T> type)
Get an exception mapping provider for a particular class of exception.
|
Set<Object> |
getInstances()
Get the immutable set of registered JAX-RS component (such as provider or
feature ) instances to be utilized by the configurable instance. |
<T> MessageBodyReader<T> |
getMessageBodyReader(Class<T> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
Get a message body reader that matches a set of criteria.
|
<T> MessageBodyWriter<T> |
getMessageBodyWriter(Class<T> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType)
Get a message body writer that matches a set of criteria.
|
Map<String,Object> |
getMutableProperties() |
Map<String,Object> |
getProperties()
Get the immutable bag of configuration properties.
|
Object |
getProperty(String name)
Get the value for the property with a given name.
|
Collection<String> |
getPropertyNames()
Returns an immutable
collection containing the
property names available within the context of the current configuration instance. |
protected ResteasyProviderFactory |
getProviderFactory() |
ReaderInterceptor[] |
getReaderInterceptors(Class declaring,
AccessibleObject target) |
ClientRequestFilter[] |
getRequestFilters(Class declaring,
AccessibleObject target) |
ClientResponseFilter[] |
getResponseFilters(Class declaring,
AccessibleObject target) |
RuntimeType |
getRuntimeType()
Get the runtime type of this configuration context.
|
WriterInterceptor[] |
getWriterInterceptors(Class declaring,
AccessibleObject target) |
boolean |
isEnabled(Class<? extends Feature> featureClass)
Check if a
feature instance of featureClass class has been
previously enabled in the runtime configuration context. |
boolean |
isEnabled(Feature feature)
Check if a particular
feature instance has been previously
enabled in the runtime configuration context. |
boolean |
isRegistered(Class<?> componentClass)
Check if a JAX-RS component of the supplied
componentClass class has been previously
registered in the runtime configuration context. |
boolean |
isRegistered(Object component)
Check if a particular JAX-RS
component instance (such as providers or
features ) has been previously registered in the runtime configuration context. |
ClientConfiguration |
property(String name,
Object value)
Set the new configuration property, if already set, the existing value of
the property will be updated.
|
ClientConfiguration |
register(Class<?> providerClass)
Register a class of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Class<?> componentClass,
Class<?>... contracts)
Register a class of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Class<?> providerClass,
int priority)
Register a class of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Class<?> componentClass,
Map<Class<?>,Integer> contracts)
Register a class of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Object provider)
Register an instance of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Object component,
Class<?>... contracts)
Register an instance of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Object provider,
int Priority)
Register an instance of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
ClientConfiguration |
register(Object component,
Map<Class<?>,Integer> contracts)
Register an instance of a custom JAX-RS component (such as an extension provider or
a
feature meta-provider) to be instantiated
and used in the scope of this configurable context. |
void |
setProperties(Map<String,Object> newProps) |
String |
toHeaderString(Object object)
Convert an object to a header string.
|
String |
toString(Object object) |
protected ResteasyProviderFactory providerFactory
public ClientConfiguration(ResteasyProviderFactory factory)
public ClientConfiguration(ClientConfiguration parent)
protected ResteasyProviderFactory getProviderFactory()
public String toHeaderString(Object object)
toHeaderString
in interface HeaderValueProcessor
object
- public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Providers
mediaType
with the value of each writer's
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 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.getMessageBodyWriter
in interface Providers
T
- type of the object that is to be written.type
- the class of the object that is to be written.genericType
- 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
- 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.null
if none is found.public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType)
Providers
mediaType
with the value of each reader's
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 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.getMessageBodyReader
in interface Providers
T
- type of the the object that is to be read.type
- the class of the object that is to be read.genericType
- 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
- 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.null
if none is found.public WriterInterceptor[] getWriterInterceptors(Class declaring, AccessibleObject target)
public ReaderInterceptor[] getReaderInterceptors(Class declaring, AccessibleObject target)
public ClientRequestFilter[] getRequestFilters(Class declaring, AccessibleObject target)
public ClientResponseFilter[] getResponseFilters(Class declaring, AccessibleObject target)
public Set<DynamicFeature> getDynamicFeatures()
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type)
Providers
type
.getExceptionMapper
in interface Providers
T
- type of the exception handled by the exception mapping provider.type
- the class of exception.ExceptionMapper
for the supplied type or null
if none is found.public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType)
Providers
mediaType
with the value of each resolver's
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 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.getContextResolver
in interface Providers
T
- type of the context.contextType
- the class of context desired.mediaType
- the media type of data for which a context is required.null
if no matching
context providers are found.public Map<String,Object> getProperties()
Configuration
getProperties
in interface Configuration
public Object getProperty(String name)
Configuration
getProperty
in interface Configuration
name
- property name.null
if the property with such name is not configured.public Set<Class<?>> getClasses()
Configuration
feature
) classes to be instantiated, injected and utilized in the scope
of the configurable instance.
For each component type, there can be only a single class-based or instance-based registration present in the configuration context at any given time.
getClasses
in interface Configuration
null
.Configuration.getInstances()
public Set<Object> getInstances()
Configuration
feature
) instances to be utilized by the configurable instance.
Fields and properties of returned instances are injected with their declared dependencies
(see Context
) by the runtime prior to use.
For each component type, there can be only a single class-based or instance-based registration present in the configuration context at any given time.
getInstances
in interface Configuration
null
.Configuration.getClasses()
public ClientConfiguration register(Class<?> providerClass)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
Implementations SHOULD warn about and ignore registrations that do not
conform to the requirements of supported JAX-RS component types in the
given configurable context. Any subsequent registration attempts for a component
type, for which a class or instance-based registration already exists in the system
MUST be rejected by the JAX-RS implementation and a warning SHOULD be raised to
inform the user about the rejected registration.
The registered JAX-RS component class is registered as a contract provider of
all the recognized JAX-RS or implementation-specific extension contracts including
meta-provider contracts, such as Feature
or DynamicFeature
.
As opposed to component instances registered via Configurable.register(Object)
method,
the lifecycle of components registered using this class-based register(...)
method is fully managed by the JAX-RS implementation or any underlying IoC
container supported by the implementation.
register
in interface Configurable<ClientConfiguration>
providerClass
- JAX-RS component class to be configured in the scope of this
configurable context.public ClientConfiguration register(Object provider)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
Implementations SHOULD warn about and ignore registrations that do not
conform to the requirements of supported JAX-RS component types in the
given configurable context. Any subsequent registration attempts for a component
type, for which a class or instance-based registration already exists in the system
MUST be rejected by the JAX-RS implementation and a warning SHOULD be raised to
inform the user about the rejected registration.
The registered JAX-RS component is registered as a contract provider of
all the recognized JAX-RS or implementation-specific extension contracts including
meta-provider contracts, such as Feature
or DynamicFeature
.
As opposed to components registered via Configurable.register(Class)
method,
the lifecycle of providers registered using this instance-based register(...)
is not managed by JAX-RS runtime. The same registered component instance is used during
the whole lifespan of the configurable context.
Fields and properties of all registered JAX-RS component instances are injected with their
declared dependencies (see Context
) by the JAX-RS runtime prior to use.
register
in interface Configurable<ClientConfiguration>
provider
- JAX-RS component instance to be configured in the scope of this
configurable context.public ClientConfiguration register(Class<?> providerClass, int priority)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides the same functionality as Configurable.register(Class)
except that any priority specified on the registered JAX-RS component class via
javax.annotation.Priority
annotation is overridden with the supplied
priority
value.
Note that in case the priority is not applicable to a particular
provider contract implemented by the class of the registered component, the supplied
priority
value will be ignored for that contract.
register
in interface Configurable<ClientConfiguration>
providerClass
- JAX-RS component class to be configured in the scope of this
configurable context.priority
- the overriding priority for the registered component
and all the provider contracts the component implements.public ClientConfiguration register(Object provider, int Priority)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides the same functionality as Configurable.register(Object)
except that any priority specified on the registered JAX-RS component class via
javax.annotation.Priority
annotation is overridden with the supplied
priority
value.
Note that in case the priority is not applicable to a particular
provider contract implemented by the class of the registered component, the supplied
priority
value will be ignored for that contract.
register
in interface Configurable<ClientConfiguration>
provider
- JAX-RS component instance to be configured in the scope of this
configurable context.Priority
- the overriding priority for the registered component
and all the provider contracts the component implements.public ClientConfiguration property(String name, Object value)
Configurable
null
value into a property
effectively removes the property from the property bag.property
in interface Configurable<ClientConfiguration>
name
- property name.value
- (new) property value. null
value removes the property
with the given name.public Configuration getConfiguration()
Configurable
Configurable
instance will be reflected
in the returned Configuration
instance.
The returned Configuration
instance and the collection data it provides are not
thread-safe wrt. modification made using methods on the parent configurable object.
getConfiguration
in interface Configurable<ClientConfiguration>
public ClientConfiguration register(Class<?> componentClass, Class<?>... contracts)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides the same functionality as Configurable.register(Class)
except the JAX-RS component class is only registered as a provider of the listed
extension provider or meta-provider contracts
.
All explicitly enumerated contract types must represent a class or an interface
implemented or extended by the registered component. Contracts that are not
assignable from
the registered component class
MUST be ignored and implementations SHOULD raise a warning to inform users about the
ignored contract(s).
register
in interface Configurable<ClientConfiguration>
componentClass
- JAX-RS component class to be configured in the scope of this
configurable context.contracts
- the specific extension provider or meta-provider contracts
implemented by the component for which the component should
be registered.
Implementations MUST ignore attempts to register a component
class for an empty or null
collection of contracts via
this method and SHOULD raise a warning about such event.public ClientConfiguration register(Class<?> componentClass, Map<Class<?>,Integer> contracts)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides same functionality as Configurable.register(Class, Class[])
except that any priority specified on the registered JAX-RS component class via
javax.annotation.Priority
annotation is overridden
for each extension provider contract type separately with an integer priority value
specified as a value in the supplied map of [contract type, priority] pairs.
Note that in case a priority is not applicable to a provider contract registered for the JAX-RS component, the supplied priority value is ignored for such contract.
register
in interface Configurable<ClientConfiguration>
componentClass
- JAX-RS component class to be configured in the scope of this
configurable context.contracts
- map of the specific extension provider and meta-provider contracts
and their associated priorities for which the JAX-RS component
is registered.
All contracts in the map must represent a class or an interface
implemented or extended by the JAX-RS component. Contracts that are
not assignable from
the registered
component class MUST be ignored and implementations SHOULD raise a warning
to inform users about the ignored contract(s).public ClientConfiguration register(Object component, Class<?>... contracts)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides the same functionality as Configurable.register(Object)
except the JAX-RS component class is only registered as a provider of the listed
extension provider or meta-provider contracts
.
All explicitly enumerated contract types must represent a class or an interface
implemented or extended by the registered component. Contracts that are not
assignable from
the registered component class
MUST be ignored and implementations SHOULD raise a warning to inform users about the
ignored contract(s).
register
in interface Configurable<ClientConfiguration>
component
- JAX-RS component instance to be configured in the scope of this
configurable context.contracts
- the specific extension provider or meta-provider contracts
implemented by the component for which the component should
be registered.
Implementations MUST ignore attempts to register a component
class for an empty or null
collection of contracts via
this method and SHOULD raise a warning about such event.public ClientConfiguration register(Object component, Map<Class<?>,Integer> contracts)
Configurable
feature
meta-provider) to be instantiated
and used in the scope of this configurable context.
This registration method provides same functionality as Configurable.register(Object, Class[])
except that any priority specified on the registered JAX-RS component class via
javax.annotation.Priority
annotation is overridden
for each extension provider contract type separately with an integer priority value
specified as a value in the supplied map of [contract type, priority] pairs.
Note that in case a priority is not applicable to a provider contract registered for the JAX-RS component, the supplied priority value is ignored for such contract.
register
in interface Configurable<ClientConfiguration>
component
- JAX-RS component instance to be configured in the scope of this
configurable context.contracts
- map of the specific extension provider and meta-provider contracts
and their associated priorities for which the JAX-RS component
is registered.
All contracts in the map must represent a class or an interface
implemented or extended by the JAX-RS component. Contracts that are
not assignable from
the registered
component class MUST be ignored and implementations SHOULD raise a warning
to inform users about the ignored contract(s).public RuntimeType getRuntimeType()
Configuration
getRuntimeType
in interface Configuration
public Collection<String> getPropertyNames()
Configuration
collection
containing the
property names available within the context of the current configuration instance.
Use the Configuration.getProperty(java.lang.String)
method with a property name to get the value of
a property.
getPropertyNames
in interface Configuration
collection
of property names.Configuration.getProperty(java.lang.String)
public boolean isEnabled(Feature feature)
Configuration
feature
instance has been previously
enabled in the runtime configuration context.
Method returns true
only in case an instance equal to the feature
instance is already present among the features previously successfully enabled in
the configuration context.
isEnabled
in interface Configuration
feature
- a feature instance to test for.true
if the feature instance has been previously enabled in this
configuration context, false
otherwise.public boolean isEnabled(Class<? extends Feature> featureClass)
Configuration
feature
instance of featureClass
class has been
previously enabled in the runtime configuration context.
Method returns true
in case any instance of the featureClass
class is
already present among the features previously successfully enabled in the configuration
context.
isEnabled
in interface Configuration
featureClass
- a feature class to test for.true
if a feature of a given class has been previously enabled in this
configuration context, false
otherwise.public boolean isRegistered(Object component)
Configuration
component
instance (such as providers or
features
) has been previously registered in the runtime configuration context.
Method returns true
only in case an instance equal to the component
instance is already present among the components previously registered in the configuration
context.
isRegistered
in interface Configuration
component
- a component instance to test for.true
if the component instance has been previously registered in this
configuration context, false
otherwise.Configuration.isEnabled(Feature)
public boolean isRegistered(Class<?> componentClass)
Configuration
componentClass
class has been previously
registered in the runtime configuration context.
Method returns true
in case a component of the supplied componentClass
class
is already present among the previously registered component classes or instances
in the configuration context.
isRegistered
in interface Configuration
componentClass
- a component class to test for.true
if a component of a given class has been previously registered in this
configuration context, false
otherwise.Configuration.isEnabled(Class)
public Map<Class<?>,Integer> getContracts(Class<?> componentClass)
Configuration
Map
. Method does not return null
.getContracts
in interface Configuration
Copyright © 2014. All Rights Reserved.