Class ResourceConfig
- All Implemented Interfaces:
Configurable<ResourceConfig>
,Configuration
,ApplicationSupplier
,ExtendedConfig
,ServerConfig
- Author:
- Paul Sandoz, Martin Matula, Michal Gajdos, Marek Potociar
-
Constructor Summary
ConstructorDescriptionCreate a new resource configuration without any custom properties or resource and provider classes.ResourceConfig
(Class<?>... classes) Create a new resource configuration initialized with a given set of resource/provider classes.ResourceConfig
(Set<Class<?>> classes) Create a new resource configuration initialized with a given set of resource/provider classes.ResourceConfig
(ResourceConfig original) Create a defensive resource configuration copy initialized with a givenResourceConfig
. -
Method Summary
Modifier and TypeMethodDescriptionfinal ResourceConfig
addProperties
(Map<String, Object> properties) Add properties toResourceConfig
.final ResourceConfig
Adds array of file and directory names to scan for components.final ResourceConfig
Adds array of file and directory names to scan for components.static ResourceConfig
forApplication
(Application application) Returns aResourceConfig
instance for the supplied application.static ResourceConfig
forApplicationClass
(Class<? extends Application> applicationClass) Returns aResourceConfig
instance wrapping the application of the supplied class.static ResourceConfig
forApplicationClass
(Class<? extends Application> applicationClass, Set<Class<?>> defaultClasses) Returns aResourceConfig
instance wrapping the application of the supplied class.final Application
Returns JAX-RS application corresponding with this ResourceConfig.Get the name of the Jersey application.final String
Returns encoded value ofApplicationPath
annotation of the Application corresponding with this ResourceConfig ornull
when the annotation is not present.final ClassLoader
Get resource and provider class loader.final ServerConfig
getContracts
(Class<?> componentClass) final Object
getProperty
(String name) Get programmatically modeled resources.final boolean
hasProperty
(String name) boolean
boolean
final boolean
isProperty
(String name) Get the value of the property with a given name converted toboolean
.boolean
isRegistered
(Class<?> componentClass) boolean
isRegistered
(Object component) final ResourceConfig
packages
(boolean recursive, ClassLoader classLoader, String... packages) Adds array of package names which will be used to scan for components.final ResourceConfig
Adds array of package names which will be used to scan for components.final ResourceConfig
Adds array of package names which will be used to scan for components.final ResourceConfig
registerClasses
(Class<?>... classes) Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig
.final ResourceConfig
registerClasses
(Set<Class<?>> classes) Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig
.final ResourceConfig
registerFinder
(ResourceFinder resourceFinder) Add aResourceFinder
toResourceConfig
.final ResourceConfig
registerInstances
(Object... instances) Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature,Jersey Binder
instances (singletons) in theResourceConfig
.final ResourceConfig
registerInstances
(Set<Object> instances) Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS featureJersey Binder
instances (singletons) in theResourceConfig
.final ResourceConfig
registerResources
(Set<Resource> resources) Register new resource models in theResourceConfig
.final ResourceConfig
registerResources
(Resource... resources) Register new programmatic resource models in theResourceConfig
.final ResourceConfig
setApplicationName
(String applicationName) Set the name of the application.final ResourceConfig
setClassLoader
(ClassLoader classLoader) SetClassLoader
which will be used for resource discovery.setProperties
(Map<String, ?> properties) Set new configuration properties replacing all previously set properties.
-
Constructor Details
-
ResourceConfig
public ResourceConfig()Create a new resource configuration without any custom properties or resource and provider classes. -
ResourceConfig
Create a new resource configuration initialized with a given set of resource/provider classes.- Parameters:
classes
- application-specific resource and/or provider classes.
-
ResourceConfig
Create a new resource configuration initialized with a given set of resource/provider classes.- Parameters:
classes
- application-specific resource and/or provider classes.
-
ResourceConfig
Create a defensive resource configuration copy initialized with a givenResourceConfig
.- Parameters:
original
- resource configuration to createAndInitialize a defensive copy from.
-
-
Method Details
-
forApplication
Returns aResourceConfig
instance for the supplied application. If the application is an instance ofResourceConfig
the method returns defensive copy of the resource config. Otherwise it creates a newResourceConfig
from the application.- Parameters:
application
- Application to provide theResourceConfig
instance for.- Returns:
- ResourceConfig instance for the supplied application.
-
forApplicationClass
Returns aResourceConfig
instance wrapping the application of the supplied class.- Parameters:
applicationClass
- Class representing a JAX-RS application.- Returns:
- ResourceConfig wrapping the JAX-RS application defined by the supplied class.
-
forApplicationClass
public static ResourceConfig forApplicationClass(Class<? extends Application> applicationClass, Set<Class<?>> defaultClasses) Returns aResourceConfig
instance wrapping the application of the supplied class. This method provides an option of supplying the set of classes that should be returned fromgetClasses()
method if the application defined by the supplied application class returns empty sets fromApplication.getClasses()
andApplication.getSingletons()
methods.- Parameters:
applicationClass
- Class representing a JAX-RS application.defaultClasses
- Default set of classes that should be returned fromgetClasses()
if the underlying application does not provide any classes and singletons.- Returns:
- ResourceConfig wrapping the JAX-RS application defined by the supplied class.
-
addProperties
Add properties toResourceConfig
. If any of the added properties exists already, old values of existing properties will be replaced by new values.- Parameters:
properties
- properties to add.- Returns:
- updated resource configuration instance.
-
setProperties
Set new configuration properties replacing all previously set properties.- Parameters:
properties
- new set of configuration properties. The content of the map will replace any existing properties set on the configuration instance.- Returns:
- the updated configuration instance.
-
property
- Specified by:
property
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
register
- Specified by:
register
in interfaceConfigurable<ResourceConfig>
-
registerClasses
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig
.Note that registered JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManager
instance during application deployment, but are otherwise ignored by server-side runtime, unless they implement also another contract recognized by Jersey runtime.Also note that registration of
binder
classes is note supported. Binders must beregistered as instances
.- Parameters:
classes
- classes to register.- Returns:
- updated resource configuration instance.
-
registerClasses
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig
.Note that registered JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManager
instance during application deployment, but are otherwise ignored by server-side runtime, unless they implement also another contract recognized by Jersey runtime.Also note that registration of
binder
classes is note supported. Binders must beregistered as instances
.- Parameters:
classes
- classes to register.- Returns:
- updated resource configuration instance.
-
registerInstances
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS featureJersey Binder
instances (singletons) in theResourceConfig
.Note that registered binders and JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManager
instance during application deployment, but are otherwise ignored by server-side runtime, unless they implement also another contract recognized by Jersey runtime.- Parameters:
instances
- instances to register.- Returns:
- updated resource configuration instance.
-
registerInstances
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature,Jersey Binder
instances (singletons) in theResourceConfig
.Note that registered binders and JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManager
instance during application deployment, but are otherwise ignored by server-side runtime, unless they implement also another contract recognized by Jersey runtime.- Parameters:
instances
- instances to register.- Returns:
- updated resource configuration instance.
-
registerResources
Register new programmatic resource models in theResourceConfig
.- Parameters:
resources
- resource models to register.- Returns:
- updated resource configuration instance.
-
registerResources
Register new resource models in theResourceConfig
.- Parameters:
resources
- resource models to register.- Returns:
- updated resource configuration instance.
-
registerFinder
Add aResourceFinder
toResourceConfig
.- Parameters:
resourceFinder
-ResourceFinder
- Returns:
- updated resource configuration instance.
-
setApplicationName
Set the name of the application. The name is an arbitrary user defined name which is used to distinguish between Jersey applications in the case that more applications are deployed on the same runtime (container). The name can be used for example for purposes of monitoring by JMX when name identifies to which application deployed MBeans belong to. The name should be unique in the runtime.- Parameters:
applicationName
- Unique application name.- Returns:
- updated resource configuration instance.
-
setClassLoader
SetClassLoader
which will be used for resource discovery.- Parameters:
classLoader
- providedClassLoader
.- Returns:
- updated resource configuration instance.
-
packages
Adds array of package names which will be used to scan for components. Package scanning ignores inheritance and thereforePath
annotation on parent classes and interfaces will be ignored. Packages will be scanned recursively, including all nested packages.- Parameters:
packages
- array of package names.- Returns:
- updated resource configuration instance.
- See Also:
-
packages
Adds array of package names which will be used to scan for components. Package scanning ignores an inheritance and thereforePath
annotation on parent classes and interfaces will be ignored.- Parameters:
recursive
- defines whether any nested packages in the collection of specified package names should be recursively scanned (value oftrue
) as part of the package scanning or not (value offalse
).packages
- array of package names.- Returns:
- updated resource configuration instance.
- See Also:
-
packages
public final ResourceConfig packages(boolean recursive, ClassLoader classLoader, String... packages) Adds array of package names which will be used to scan for components. Package scanning ignores an inheritance and thereforePath
annotation on parent classes and interfaces will be ignored.- Parameters:
recursive
- defines whether any nested packages in the collection of specified package names should be recursively scanned (value oftrue
) as part of the package scanning or not (value offalse
).classLoader
- defines the classloader used for scanning the packages and loading the classes.packages
- array of package names.- Returns:
- updated resource configuration instance.
- See Also:
-
files
Adds array of file and directory names to scan for components. Any directories in the list will be scanned recursively, including their sub-directories.- Parameters:
files
- array of file and directory names.- Returns:
- updated resource configuration instance.
-
files
Adds array of file and directory names to scan for components.- Parameters:
recursive
- defines whether any sub-directories of the directories specified in the collection of file names should be recursively scanned (value oftrue
) as part of the file scanning or not (value offalse
).files
- array of file and directory names.- Returns:
- updated resource configuration instance.
-
getConfiguration
- Specified by:
getConfiguration
in interfaceConfigurable<ResourceConfig>
-
getProperties
- Specified by:
getProperties
in interfaceConfiguration
- Overrides:
getProperties
in classApplication
-
hasProperty
- Specified by:
hasProperty
in interfaceConfiguration
-
getProperty
- Specified by:
getProperty
in interfaceConfiguration
-
getPropertyNames
- Specified by:
getPropertyNames
in interfaceConfiguration
-
isProperty
Description copied from interface:ExtendedConfig
Get the value of the property with a given name converted toboolean
. Returnsfalse
if the value is not convertible.- Specified by:
isProperty
in interfaceExtendedConfig
- Parameters:
name
- property name.- Returns:
boolean
property value orfalse
if the property is not convertible.
-
getClasses
- Specified by:
getClasses
in interfaceConfiguration
- Overrides:
getClasses
in classApplication
-
getInstances
- Specified by:
getInstances
in interfaceConfiguration
-
getSingletons
- Overrides:
getSingletons
in classApplication
-
getRuntimeType
- Specified by:
getRuntimeType
in interfaceConfiguration
-
isEnabled
- Specified by:
isEnabled
in interfaceConfiguration
-
isEnabled
- Specified by:
isEnabled
in interfaceConfiguration
-
isRegistered
- Specified by:
isRegistered
in interfaceConfiguration
-
isRegistered
- Specified by:
isRegistered
in interfaceConfiguration
-
getContracts
- Specified by:
getContracts
in interfaceConfiguration
-
getResources
Description copied from interface:ServerConfig
Get programmatically modeled resources.- Specified by:
getResources
in interfaceServerConfig
- Returns:
- programmatically modeled resources.
-
getClassLoader
Get resource and provider class loader.- Returns:
- class loader to be used when looking up the resource classes and providers.
-
getApplication
Returns JAX-RS application corresponding with this ResourceConfig.- Specified by:
getApplication
in interfaceApplicationSupplier
- Returns:
- JAX-RS application corresponding with this ResourceConfig.
-
getApplicationPath
Returns encoded value ofApplicationPath
annotation of the Application corresponding with this ResourceConfig ornull
when the annotation is not present.- Returns:
- Returns encoded value of
ApplicationPath
annotation of the Application corresponding with this ResourceConfig.
-
getApplicationName
Get the name of the Jersey application.- Returns:
- Name of the application.
- See Also:
-