Class ResourceConfig
- All Implemented Interfaces:
javax.ws.rs.core.Configurable<ResourceConfig>
,javax.ws.rs.core.Configuration
,ExtendedConfig
,ServerConfig
- Direct Known Subclasses:
ResourceConfig.RuntimeConfig
,ResourceConfig.WrappingResourceConfig
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static class
private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Logger
private boolean
private ResourceConfig.State
-
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 TypeMethodDescription(package private) javax.ws.rs.core.Application
Allows overriding thegetApplication()
method functionality inResourceConfig.WrappingResourceConfig
.Get configured resource and/or provider classes.Get configured resource and/or provider instances.(package private) ResourceConfig
_setApplication
(javax.ws.rs.core.Application app) Allows overriding the setApplication() method functionality in WrappingResourceConfig.final ResourceConfig
addProperties
(Map<String, Object> properties) Add properties toResourceConfig
.(package private) final void
configureAutoDiscoverableProviders
(InjectionManager injectionManager, Collection<AutoDiscoverable> autoDiscoverables) Configure auto-discoverables.(package private) final void
configureForcedAutoDiscoverableProviders
(InjectionManager injectionManager) Configure forced auto-discoverables.(package private) final void
configureMetaProviders
(InjectionManager injectionManager, ManagedObjectsFinalizer finalizer) (package private) static ResourceConfig
createRuntimeConfig
(javax.ws.rs.core.Application application) Create runtime configuration initialized from a given deploy-time JAX-RS/Jersey application configuration.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
(javax.ws.rs.core.Application application) Returns aResourceConfig
instance for the supplied application.static ResourceConfig
forApplicationClass
(Class<? extends javax.ws.rs.core.Application> applicationClass) Returns aResourceConfig
instance wrapping the application of the supplied class.static ResourceConfig
forApplicationClass
(Class<? extends javax.ws.rs.core.Application> applicationClass, Set<Class<?>> defaultClasses) Returns aResourceConfig
instance wrapping the application of the supplied class.final javax.ws.rs.core.Application
Returns JAX-RS application corresponding with this ResourceConfig.(package private) Class<? extends javax.ws.rs.core.Application>
Method used by ApplicationHandler to retrieve application class (this method is overridden byResourceConfig.WrappingResourceConfig
).Get the name of the Jersey application.final ClassLoader
Get resource and provider class loader.(package private) final ComponentBag
Get the internal component bag.final ServerConfig
getContracts
(Class<?> componentClass) final Object
getProperty
(String name) Return classes which were registered by the user and not found by class path scanning (or any other scanning).Get programmatically modeled resources.javax.ws.rs.RuntimeType
(package private) final void
Invalidate cached component instances and classes.boolean
boolean
isEnabled
(javax.ws.rs.core.Feature feature) 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) (package private) final void
lock()
Switches the ResourceConfig to read-only state.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.private String[]
parsePropertyValue
(String propertyName) 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
.(package private) final ResourceConfig
setApplication
(javax.ws.rs.core.Application app) This method is used by ApplicationHandler to set application instance to the resource config (should always be called on WrappingResourceConfig instance, never on plain instances of ResourceConfig unless we have a bug in the code).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.private void
(package private) static javax.ws.rs.core.Application
unwrapApplication
(javax.ws.rs.core.Application application) Get the most internal wrappedapplication
class.private static javax.ws.rs.core.Application
unwrapCustomRootApplication
(ResourceConfig resourceConfig)
-
Field Details
-
LOGGER
-
cachedClasses
-
cachedClassesView
-
cachedSingletons
-
cachedSingletonsView
-
resetFinders
private transient boolean resetFinders -
state
-
-
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
public static ResourceConfig forApplicationClass(Class<? extends javax.ws.rs.core.Application> applicationClass) 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 javax.ws.rs.core.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 interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
register
- Specified by:
register
in interfacejavax.ws.rs.core.Configurable<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:
-
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.
-
invalidateCache
final void invalidateCache()Invalidate cached component instances and classes. -
lock
final void lock()Switches the ResourceConfig to read-only state. Called by the WrappingResourceConfig if this ResourceConfig is set as the application. Also called by ApplicationHandler on WrappingResourceConfig at the point when it is going to build the resource model. The method also sets the application name from properties if the name is not defined yer and the propertyServerProperties.APPLICATION_NAME
is defined. -
getConfiguration
- Specified by:
getConfiguration
in interfacejavax.ws.rs.core.Configurable<ResourceConfig>
-
getProperties
- Specified by:
getProperties
in interfacejavax.ws.rs.core.Configuration
- Overrides:
getProperties
in classjavax.ws.rs.core.Application
-
getProperty
- Specified by:
getProperty
in interfacejavax.ws.rs.core.Configuration
-
getPropertyNames
- Specified by:
getPropertyNames
in interfacejavax.ws.rs.core.Configuration
-
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 interfacejavax.ws.rs.core.Configuration
- Overrides:
getClasses
in classjavax.ws.rs.core.Application
-
getInstances
- Specified by:
getInstances
in interfacejavax.ws.rs.core.Configuration
-
getSingletons
- Overrides:
getSingletons
in classjavax.ws.rs.core.Application
-
getComponentBag
Get the internal component bag.- Returns:
- internal component bag.
-
configureAutoDiscoverableProviders
final void configureAutoDiscoverableProviders(InjectionManager injectionManager, Collection<AutoDiscoverable> autoDiscoverables) Configure auto-discoverables.- Parameters:
injectionManager
- injection manager to obtain auto-discoverables from.autoDiscoverables
- list of registered auto discoverable components.
-
configureForcedAutoDiscoverableProviders
Configure forced auto-discoverables.- Parameters:
injectionManager
- injection manager to obtain auto-discoverables from.
-
configureMetaProviders
final void configureMetaProviders(InjectionManager injectionManager, ManagedObjectsFinalizer finalizer) -
getRuntimeType
public javax.ws.rs.RuntimeType getRuntimeType()- Specified by:
getRuntimeType
in interfacejavax.ws.rs.core.Configuration
-
isEnabled
public boolean isEnabled(javax.ws.rs.core.Feature feature) - Specified by:
isEnabled
in interfacejavax.ws.rs.core.Configuration
-
isEnabled
- Specified by:
isEnabled
in interfacejavax.ws.rs.core.Configuration
-
isRegistered
- Specified by:
isRegistered
in interfacejavax.ws.rs.core.Configuration
-
isRegistered
- Specified by:
isRegistered
in interfacejavax.ws.rs.core.Configuration
-
getContracts
- Specified by:
getContracts
in interfacejavax.ws.rs.core.Configuration
-
_getClasses
Get configured resource and/or provider classes. The method is overridden in aprivate sub-type
.- Returns:
- set of configured resource and/or provider classes.
-
scanClasses
-
parsePropertyValue
-
getRegisteredClasses
Return classes which were registered by the user and not found by class path scanning (or any other scanning).- Returns:
- Set of classes registered by the user.
-
_getSingletons
Get configured resource and/or provider instances. The method is overridden in aprivate sub-type
.- Returns:
- set of configured resource and/or provider instances.
-
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
public final javax.ws.rs.core.Application getApplication()Returns JAX-RS application corresponding with this ResourceConfig.- Returns:
- JAX-RS application corresponding with this ResourceConfig.
-
_getApplication
javax.ws.rs.core.Application _getApplication()Allows overriding thegetApplication()
method functionality inResourceConfig.WrappingResourceConfig
.- Returns:
- JAX-RS application corresponding with this ResourceConfig.
-
getApplicationName
Get the name of the Jersey application.- Returns:
- Name of the application.
- See Also:
-
getApplicationClass
Class<? extends javax.ws.rs.core.Application> getApplicationClass()Method used by ApplicationHandler to retrieve application class (this method is overridden byResourceConfig.WrappingResourceConfig
).- Returns:
- application class
-
setApplication
This method is used by ApplicationHandler to set application instance to the resource config (should always be called on WrappingResourceConfig instance, never on plain instances of ResourceConfig unless we have a bug in the code).- Parameters:
app
- JAX-RS application- Returns:
- this ResourceConfig instance (for convenience)
-
_setApplication
Allows overriding the setApplication() method functionality in WrappingResourceConfig.- Parameters:
app
- application to be set for this ResourceConfig- Returns:
- this resource config instance
-
createRuntimeConfig
Create runtime configuration initialized from a given deploy-time JAX-RS/Jersey application configuration.- Parameters:
application
- deploy-time JAX-RS/Jersey application configuration.- Returns:
- initialized run-time resource config.
-
unwrapCustomRootApplication
private static javax.ws.rs.core.Application unwrapCustomRootApplication(ResourceConfig resourceConfig) -
unwrapApplication
static javax.ws.rs.core.Application unwrapApplication(javax.ws.rs.core.Application application) Get the most internal wrappedapplication
class.This method is similar to
getApplication()
except if provided application was created by wrapping multipleResourceConfig
instances, this method will return the original (inner-most) JAX-RSApplication
sub-class rather than a potentially intermediateResourceConfig
wrapper.- Parameters:
application
- application that is potentially wrapped.- Returns:
- the original, inner-most
Application
subclass. May return the same instance directly, in case the suppliedapplication
instance is not a wrapperResourceConfig
instance.
-
setupApplicationName
private void setupApplicationName()
-