org.glassfish.jersey.client
Class ClientConfig

java.lang.Object
  extended by org.glassfish.jersey.client.ClientConfig
All Implemented Interfaces:
Configuration, Configurable, Config

public class ClientConfig
extends java.lang.Object
implements Configuration, Config, Configurable

Jersey implementation of JAX-RS client configuration contract.

Author:
Marek Potociar (marek.potociar at oracle.com), Martin Matula (martin.matula at oracle.com)

Constructor Summary
ClientConfig()
          Construct a new Jersey configuration instance with the default features and property values.
ClientConfig(java.lang.Class<?>... providerClasses)
          Construct a new Jersey configuration instance and register the provided list of provider classes.
ClientConfig(java.lang.Object... providers)
          Construct a new Jersey configuration instance and register the provided list of provider instances.
 
Method Summary
 ClientConfig binders(Binder... binders)
          Register custom HK2 binders.
 ClientConfig connector(Connector connector)
          Set Jersey client transport connector.
 boolean equals(java.lang.Object obj)
           
 JerseyClient getClient()
          Get the parent Jersey client this configuration is bound to.
 Connector getConnector()
          Get the client transport connector.
 java.util.Set<Feature> getFeatures()
          Get the immutable set of configured features.
 java.util.Map<java.lang.String,java.lang.Object> getProperties()
          Get the immutable bag of configuration properties.
 java.lang.Object getProperty(java.lang.String name)
          Get the value for the property with a given name.
 java.util.Set<java.lang.Class<?>> getProviderClasses()
          Get the immutable set of registered provider classes to be instantiated, injected and utilized in the scope of the configured instance (excluding features).
 java.util.Set<java.lang.Object> getProviderInstances()
          Get the immutable set of registered provider instances to be utilized by the configured instance (excluding features).
 int hashCode()
           
 boolean isEnabled(java.lang.Class<? extends Feature> feature)
          Check if the given feature is enabled or not.
 boolean isProperty(java.lang.String name)
          Get the value of the property with a given name converted to Java boolean type.
 ClientConfig register(java.lang.Class<?> providerClass)
          Register a provider or a feature class to be instantiated and used in the scope of the configured instance.
 ClientConfig register(java.lang.Class<?> providerClass, int bindingPriority)
          Register a provider or a feature class to be instantiated and used in the scope of the configured instance.
<T> ClientConfig
register(java.lang.Class<T> providerClass, java.lang.Class<? super T>... contracts)
          Register a provider or a feature class to be instantiated and used in the scope of the configured instance.
<T> ClientConfig
register(java.lang.Class<T> providerClass, int bindingPriority, java.lang.Class<? super T>... contracts)
          Register a provider or a feature class to be instantiated and used in the scope of the configured instance.
 ClientConfig register(java.lang.Object provider)
          Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.
<T> ClientConfig
register(java.lang.Object provider, java.lang.Class<? super T>... contracts)
          Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.
 ClientConfig register(java.lang.Object provider, int bindingPriority)
          Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.
<T> ClientConfig
register(java.lang.Object provider, int bindingPriority, java.lang.Class<? super T>... contracts)
          Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.
 ClientConfig setProperties(java.util.Map<java.lang.String,?> properties)
          Set new configuration properties replacing all previously set properties.
 ClientConfig setProperty(java.lang.String name, java.lang.Object value)
          Set the new configuration property, if already set, the existing value of the property will be updated.
 ClientConfig updateFrom(Configurable configuration)
          Replace the existing configuration state with the configuration state of the externally provided configuration.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientConfig

public ClientConfig()
Construct a new Jersey configuration instance with the default features and property values.


ClientConfig

public ClientConfig(java.lang.Class<?>... providerClasses)
Construct a new Jersey configuration instance and register the provided list of provider classes.

Parameters:
providerClasses - provider classes to be registered with this client configuration.

ClientConfig

public ClientConfig(java.lang.Object... providers)
Construct a new Jersey configuration instance and register the provided list of provider instances.

Parameters:
providers - provider instances to be registered with this client configuration.
Method Detail

getProperties

public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Description copied from interface: Configurable
Get the immutable bag of configuration properties.

Specified by:
getProperties in interface Configurable
Specified by:
getProperties in interface Config
Returns:
the immutable view of configuration properties.

getProperty

public java.lang.Object getProperty(java.lang.String name)
Description copied from interface: Configurable
Get the value for the property with a given name.

Specified by:
getProperty in interface Configurable
Specified by:
getProperty in interface Config
Parameters:
name - property name.
Returns:
the property value for the specified property name or null if the property with such name is not configured.

isProperty

public boolean isProperty(java.lang.String name)
Description copied from interface: Config
Get the value of the property with a given name converted to Java boolean type. Returns false if the value is not convertible.

Specified by:
isProperty in interface Config
Parameters:
name - property name.
Returns:
boolean property value or false if the property is not convertible.

getFeatures

public java.util.Set<Feature> getFeatures()
Description copied from interface: Configurable
Get the immutable set of configured features.

The returned set contains the features that have already been successfully configured in this configuration context.

Specified by:
getFeatures in interface Configurable
Returns:
the enabled feature set. The returned value shall never be null.
See Also:
Feature.configure(Configurable)

isEnabled

public boolean isEnabled(java.lang.Class<? extends Feature> feature)
Check if the given feature is enabled or not.

Parameters:
feature - tested feature.
Returns:
true in case

getProviderClasses

public java.util.Set<java.lang.Class<?>> getProviderClasses()
Description copied from interface: Configurable
Get the immutable set of registered provider classes to be instantiated, injected and utilized in the scope of the configured instance (excluding features).

Specified by:
getProviderClasses in interface Configurable
Returns:
the immutable set of registered provider classes. The returned value shall never be null.
See Also:
Configurable.getProviderInstances()

getProviderInstances

public java.util.Set<java.lang.Object> getProviderInstances()
Description copied from interface: Configurable
Get the immutable set of registered provider instances to be utilized by the configured instance (excluding features).

When the configured instance is initialized the set of provider instances will be combined and take precedence over the instantiated registered provider classes.

Specified by:
getProviderInstances in interface Configurable
Returns:
the immutable set of registered provider instances. The returned value shall never be null.
See Also:
Configurable.getProviderClasses()

updateFrom

public ClientConfig updateFrom(Configurable configuration)
Description copied from interface: Configuration
Replace the existing configuration state with the configuration state of the externally provided configuration.

Specified by:
updateFrom in interface Configuration
Parameters:
configuration - configuration to be used to update the instance.
Returns:
the updated configuration.

register

public ClientConfig register(java.lang.Class<?> providerClass)
Description copied from interface: Configurable
Register a provider or a feature class to be instantiated and used in the scope of the configured instance. The registered provider class is registered as a provider of all the recognized JAX-RS or implementation-specific extension contracts.

As opposed to the providers registered by the provider instances, providers registered using this method are instantiated and properly injected by the JAX-RS implementation provider. In case of a conflict between a registered provider instance and instantiated registered provider class, the registered provider instance takes precedence and the registered provider class will not be instantiated in such case.

In case the registered class represents a feature, this Configurable context instantiates the feature and invokes the Feature.configure(javax.ws.rs.core.Configurable) method and lets the feature update the configurable context. If the invocation of Feature.configure(javax.ws.rs.core.Configurable) returns true the feature is added to the collection of enabled features, otherwise the feature instance is discarded.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
providerClass - provider class to be instantiated and used in the scope of the configured instance.
Returns:
the updated configurable instance.

register

public ClientConfig register(java.lang.Object provider)
Description copied from interface: Configurable
Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance. The registered provider is registered as a provider of all the recognized JAX-RS or implementation-specific extension contracts.

As opposed to the providers registered by the provider classes, provider instances registered using this method are used "as is, i.e. are not managed or injected by the JAX-RS implementation provider. In case of a conflict between a registered provider instance and instantiated registered provider class, the registered provider instance takes precedence and the registered provider class will not be instantiated in such case.

In case the registered class represents a feature, this Configurable context instantiates the feature and invokes the Feature.configure(javax.ws.rs.core.Configurable) method and lets the feature update the configurable context. If the invocation of Feature.configure(javax.ws.rs.core.Configurable) returns true the feature is added to the collection of enabled features, otherwise the feature instance is discarded.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
provider - a provider instance to be registered in the scope of the configured instance.
Returns:
the updated configurable instance.

register

public ClientConfig register(java.lang.Class<?> providerClass,
                             int bindingPriority)
Description copied from interface: Configurable
Register a provider or a feature class to be instantiated and used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Class) except that any provider binding priority specified on the provider class using @BindingPriority annotation is overridden with the supplied bindingPriority value.

Note that in case the binding priority cannot be applied to a particular provider contract registered for the provider class, the supplied bindingPriority value is ignored.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
providerClass - provider class to be instantiated and used in the scope of the configured instance.
bindingPriority - the overriding binding priority for the registered contract(s).
Returns:
the updated configurable instance.

register

public <T> ClientConfig register(java.lang.Class<T> providerClass,
                                 java.lang.Class<? super T>... contracts)
Description copied from interface: Configurable
Register a provider or a feature class to be instantiated and used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Class) except the provider class is only registered as a provider of the listed contracts. Note that in case the Feature interface is not listed explicitly, the provider class is not recognized as a JAX-RS feature.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
providerClass - provider class to be instantiated and used in the scope of the configured instance.
contracts - the specific set of contracts implemented by the provider class for which the provider should be registered. If omitted, the provider class will be registered as a provider of all recognized contracts implemented by the provider class.
Returns:
the updated configurable instance.

register

public <T> ClientConfig register(java.lang.Class<T> providerClass,
                                 int bindingPriority,
                                 java.lang.Class<? super T>... contracts)
Description copied from interface: Configurable
Register a provider or a feature class to be instantiated and used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Class, Class[]) except that any provider binding priority specified on the provider class using @BindingPriority annotation is overridden with the supplied bindingPriority value.

Note that in case the binding priority cannot be applied to a particular provider contract registered for the provider class, the supplied bindingPriority value is ignored.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
providerClass - provider class to be instantiated and used in the scope of the configured instance.
bindingPriority - the overriding binding priority for the registered contract(s).
contracts - the specific set of contracts implemented by the provider class for which the provider should be registered. If omitted, the provider class will be registered as a provider of all recognized contracts implemented by the provider class.
Returns:
the updated configurable instance.

register

public ClientConfig register(java.lang.Object provider,
                             int bindingPriority)
Description copied from interface: Configurable
Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Object) except that any provider binding priority specified on the provider using @BindingPriority annotation is overridden with the supplied bindingPriority value.

Note that in case the binding priority cannot be applied to a particular provider contract registered for the provider, the supplied bindingPriority value is ignored.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
provider - provider class to be instantiated and used in the scope of the configured instance.
bindingPriority - the overriding binding priority for the registered contract(s).
Returns:
the updated configurable instance.

register

public <T> ClientConfig register(java.lang.Object provider,
                                 java.lang.Class<? super T>... contracts)
Description copied from interface: Configurable
Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Object) except the provider is only registered as a provider of the listed contracts. Note that in case the Feature interface is not listed explicitly, the provider is not recognized as a JAX-RS feature.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
provider - a provider instance to be registered in the scope of the configured instance.
contracts - the specific set of contracts implemented by the provider class for which the provider should be registered. If omitted, the provider class will be registered as a provider of all recognized contracts implemented by the provider class.
Returns:
the updated configurable instance.

register

public <T> ClientConfig register(java.lang.Object provider,
                                 int bindingPriority,
                                 java.lang.Class<? super T>... contracts)
Description copied from interface: Configurable
Register a provider or a feature ("singleton") instance to be used in the scope of the configured instance.

This registration method provides same functionality as Configurable.register(Object, Class[]) except that any provider binding priority specified on the provider using @BindingPriority annotation is overridden with the supplied bindingPriority value.

Note that in case the binding priority cannot be applied to a particular provider contract registered for the provider, the supplied bindingPriority value is ignored.

Specified by:
register in interface Configuration
Specified by:
register in interface Configurable
Parameters:
provider - a provider instance to be registered in the scope of the configured instance.
bindingPriority - the overriding binding priority for the registered contract(s).
contracts - the specific set of contracts implemented by the provider class for which the provider should be registered. If omitted, the provider class will be registered as a provider of all recognized contracts implemented by the provider class.
Returns:
the updated configurable instance.

setProperties

public ClientConfig setProperties(java.util.Map<java.lang.String,?> properties)
Description copied from interface: Configurable
Set new configuration properties replacing all previously set properties.

Specified by:
setProperties in interface Configuration
Specified by:
setProperties in interface Configurable
Parameters:
properties - new set of configuration properties. The content of the map will replace any existing properties set on the configurable instance.
Returns:
the updated configurable instance.

setProperty

public ClientConfig setProperty(java.lang.String name,
                                java.lang.Object value)
Description copied from interface: Configurable
Set the new configuration property, if already set, the existing value of the property will be updated. Setting a null value into a property effectively removes the property from the property bag.

Specified by:
setProperty in interface Configuration
Specified by:
setProperty in interface Configurable
Parameters:
name - property name.
value - (new) property value. null value removes the property with the given name.
Returns:
the updated configurable instance.

connector

public ClientConfig connector(Connector connector)
Set Jersey client transport connector.

Parameters:
connector - client transport connector.
Returns:
this client config instance.

binders

public ClientConfig binders(Binder... binders)
Register custom HK2 binders.

Parameters:
binders - custom HK2 binders to be registered with the Jersey client.
Returns:
this client config instance.

getConnector

public Connector getConnector()
Get the client transport connector. May return null if no connector has been set.

Returns:
client transport connector or {code null} if not set.

getClient

public JerseyClient getClient()
Get the parent Jersey client this configuration is bound to. May return null if no parent client has been bound.

Returns:
bound parent Jersey client or null if not bound.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.