public class ResourceConfig extends javax.ws.rs.core.Application implements javax.ws.rs.core.Configurable<ResourceConfig>, ServerConfig
Modifier and Type | Class and Description |
---|---|
private static class |
ResourceConfig.ImmutableState |
private static class |
ResourceConfig.RuntimeConfig |
private static class |
ResourceConfig.State |
private static class |
ResourceConfig.WrappingResourceConfig |
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.Class<?>> |
cachedClasses |
private java.util.Set<java.lang.Class<?>> |
cachedClassesView |
private java.util.Set<java.lang.Object> |
cachedSingletons |
private java.util.Set<java.lang.Object> |
cachedSingletonsView |
private static java.util.logging.Logger |
LOGGER |
private boolean |
resetFinders |
private ResourceConfig.State |
state |
Constructor and Description |
---|
ResourceConfig()
Create a new resource configuration without any custom properties or
resource and provider classes.
|
ResourceConfig(java.lang.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 given
ResourceConfig . |
ResourceConfig(java.util.Set<java.lang.Class<?>> classes)
Create a new resource configuration initialized with a given set of
resource/provider classes.
|
Modifier and Type | Method and Description |
---|---|
(package private) javax.ws.rs.core.Application |
_getApplication()
Allows overriding the
getApplication() method functionality in ResourceConfig.WrappingResourceConfig . |
(package private) java.util.Set<java.lang.Class<?>> |
_getClasses()
Get configured resource and/or provider classes.
|
(package private) java.util.Set<java.lang.Object> |
_getSingletons()
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.
|
ResourceConfig |
addProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Add properties to
ResourceConfig . |
(package private) void |
configureAutoDiscoverableProviders(org.glassfish.hk2.api.ServiceLocator locator)
Configure auto-discoverables.
|
(package private) void |
configureForcedAutoDiscoverableProviders(org.glassfish.hk2.api.ServiceLocator locator)
Configure forced auto-discoverables.
|
(package private) void |
configureMetaProviders(org.glassfish.hk2.api.ServiceLocator locator)
Configure custom binders registered in the resource config.
|
(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.
|
ResourceConfig |
files(boolean recursive,
java.lang.String... files)
Adds array of file and directory names to scan for components.
|
ResourceConfig |
files(java.lang.String... files)
Adds array of file and directory names to scan for components.
|
static ResourceConfig |
forApplication(javax.ws.rs.core.Application application)
Returns a
ResourceConfig instance for the supplied application. |
static ResourceConfig |
forApplicationClass(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass)
Returns a
ResourceConfig instance wrapping the application of the supplied class. |
static ResourceConfig |
forApplicationClass(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass,
java.util.Set<java.lang.Class<?>> defaultClasses)
Returns a
ResourceConfig instance wrapping the application of the supplied class. |
javax.ws.rs.core.Application |
getApplication()
Returns JAX-RS application corresponding with this ResourceConfig.
|
(package private) java.lang.Class<? extends javax.ws.rs.core.Application> |
getApplicationClass()
Method used by ApplicationHandler to retrieve application class
(this method is overridden by
ResourceConfig.WrappingResourceConfig ). |
java.lang.String |
getApplicationName()
Get the name of the Jersey application.
|
java.util.Set<java.lang.Class<?>> |
getClasses() |
java.lang.ClassLoader |
getClassLoader()
Get resource and provider class loader.
|
(package private) ComponentBag |
getComponentBag()
Get the internal component bag.
|
ServerConfig |
getConfiguration() |
java.util.Map<java.lang.Class<?>,java.lang.Integer> |
getContracts(java.lang.Class<?> componentClass) |
java.util.Set<java.lang.Object> |
getInstances() |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties() |
java.lang.Object |
getProperty(java.lang.String name) |
java.util.Collection<java.lang.String> |
getPropertyNames() |
(package private) java.util.Set<java.lang.Class<?>> |
getRegisteredClasses()
Return classes which were registered by the user and not found by class path scanning (or any other scanning).
|
java.util.Set<Resource> |
getResources()
Get programmatically modeled resources.
|
javax.ws.rs.RuntimeType |
getRuntimeType() |
java.util.Set<java.lang.Object> |
getSingletons() |
(package private) void |
invalidateCache()
Invalidate cached component instances and classes.
|
boolean |
isEnabled(java.lang.Class<? extends javax.ws.rs.core.Feature> featureClass) |
boolean |
isEnabled(javax.ws.rs.core.Feature feature) |
boolean |
isProperty(java.lang.String name)
Get the value of the property with a given name converted to
boolean . |
boolean |
isRegistered(java.lang.Class<?> componentClass) |
boolean |
isRegistered(java.lang.Object component) |
(package private) void |
lock()
Switches the ResourceConfig to read-only state.
|
ResourceConfig |
packages(boolean recursive,
java.lang.String... packages)
Adds array of package names which will be used to scan for components.
|
ResourceConfig |
packages(java.lang.String... packages)
Adds array of package names which will be used to scan for components.
|
private java.lang.String[] |
parsePropertyValue(java.lang.String propertyName) |
ResourceConfig |
property(java.lang.String name,
java.lang.Object value) |
ResourceConfig |
register(java.lang.Class<?> componentClass) |
ResourceConfig |
register(java.lang.Class<?> componentClass,
java.lang.Class<?>... contracts) |
ResourceConfig |
register(java.lang.Class<?> componentClass,
int bindingPriority) |
ResourceConfig |
register(java.lang.Class<?> componentClass,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts) |
ResourceConfig |
register(java.lang.Object component) |
ResourceConfig |
register(java.lang.Object component,
java.lang.Class<?>... contracts) |
ResourceConfig |
register(java.lang.Object component,
int bindingPriority) |
ResourceConfig |
register(java.lang.Object component,
java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts) |
ResourceConfig |
registerClasses(java.lang.Class<?>... classes)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature
in the
ResourceConfig . |
ResourceConfig |
registerClasses(java.util.Set<java.lang.Class<?>> classes)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature
in the
ResourceConfig . |
ResourceConfig |
registerFinder(ResourceFinder resourceFinder)
Add a
ResourceFinder to ResourceConfig . |
ResourceConfig |
registerInstances(java.lang.Object... instances)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature
or
HK2 binder instances (singletons) in the ResourceConfig . |
ResourceConfig |
registerInstances(java.util.Set<java.lang.Object> instances)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature
or
HK2 binder instances (singletons) in the ResourceConfig . |
ResourceConfig |
registerResources(Resource... resources)
Register new programmatic resource models in the
ResourceConfig . |
ResourceConfig |
registerResources(java.util.Set<Resource> resources)
Register new resource models in the
ResourceConfig . |
private java.util.Set<java.lang.Class<?>> |
scanClasses() |
(package private) 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).
|
ResourceConfig |
setApplicationName(java.lang.String applicationName)
Set the name of the application.
|
ResourceConfig |
setClassLoader(java.lang.ClassLoader classLoader)
Set
ClassLoader which will be used for resource discovery. |
ResourceConfig |
setProperties(java.util.Map<java.lang.String,?> properties)
Set new configuration properties replacing all previously set properties.
|
private void |
setupApplicationName() |
(package private) static javax.ws.rs.core.Application |
unwrapApplication(javax.ws.rs.core.Application application)
Get the most internal wrapped
application class. |
private static javax.ws.rs.core.Application |
unwrapCustomRootApplication(ResourceConfig resourceConfig) |
private static final java.util.logging.Logger LOGGER
private transient java.util.Set<java.lang.Class<?>> cachedClasses
private transient java.util.Set<java.lang.Class<?>> cachedClassesView
private transient java.util.Set<java.lang.Object> cachedSingletons
private transient java.util.Set<java.lang.Object> cachedSingletonsView
private transient boolean resetFinders
private volatile ResourceConfig.State state
public ResourceConfig()
public ResourceConfig(java.util.Set<java.lang.Class<?>> classes)
classes
- application-specific resource and/or provider classes.public ResourceConfig(java.lang.Class<?>... classes)
classes
- application-specific resource and/or provider classes.public ResourceConfig(ResourceConfig original)
ResourceConfig
.original
- resource configuration to create a defensive copy from.public static ResourceConfig forApplication(javax.ws.rs.core.Application application)
ResourceConfig
instance for the supplied application.
If the application is an instance of ResourceConfig
the method returns defensive copy of the resource config.
Otherwise it creates a new ResourceConfig
from the application.application
- Application to provide the ResourceConfig
instance for.public static ResourceConfig forApplicationClass(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass)
ResourceConfig
instance wrapping the application of the supplied class.applicationClass
- Class representing a JAX-RS application.public static ResourceConfig forApplicationClass(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass, java.util.Set<java.lang.Class<?>> defaultClasses)
ResourceConfig
instance wrapping the application of the supplied class.
This method provides an option of supplying the set of classes that should be returned from getClasses()
method if the application defined by the supplied application class returns empty sets from
Application.getClasses()
and Application.getSingletons()
methods.applicationClass
- Class representing a JAX-RS application.defaultClasses
- Default set of classes that should be returned from getClasses()
if the underlying
application does not provide any classes and singletons.public final ResourceConfig addProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
ResourceConfig
.
If any of the added properties exists already, he values of the existing
properties will be replaced with new values.properties
- properties to add.public ResourceConfig setProperties(java.util.Map<java.lang.String,?> properties)
properties
- new set of configuration properties. The content of
the map will replace any existing properties set on the configuration
instance.public ResourceConfig property(java.lang.String name, java.lang.Object value)
property
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Class<?> componentClass)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Class<?> componentClass, int bindingPriority)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Class<?> componentClass, java.lang.Class<?>... contracts)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Class<?> componentClass, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Object component)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Object component, int bindingPriority)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Object component, java.lang.Class<?>... contracts)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public ResourceConfig register(java.lang.Object component, java.util.Map<java.lang.Class<?>,java.lang.Integer> contracts)
register
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public final ResourceConfig registerClasses(java.util.Set<java.lang.Class<?>> classes)
ResourceConfig
.
Note that registered JAX-RS features are used to initialize and configure
the Jersey runtime ServiceLocator
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 HK2 binder
classes is note supported. HK2 binders
must be registered as instances
.
classes
- classes to register.public final ResourceConfig registerClasses(java.lang.Class<?>... classes)
ResourceConfig
.
Note that registered JAX-RS features are used to initialize and configure
the Jersey runtime ServiceLocator
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 HK2 binder
classes is note supported. HK2 binders
must be registered as instances
.
classes
- classes to register.public final ResourceConfig registerInstances(java.util.Set<java.lang.Object> instances)
HK2 binder
instances (singletons) in the ResourceConfig
.
Note that registered HK2 binders and JAX-RS features are used to initialize and configure
the Jersey runtime ServiceLocator
instance during application deployment, but are
otherwise ignored by server-side runtime, unless they implement also another contract
recognized by Jersey runtime.
instances
- instances to register.public final ResourceConfig registerInstances(java.lang.Object... instances)
HK2 binder
instances (singletons) in the ResourceConfig
.
Note that registered HK2 binders and JAX-RS features are used to initialize and configure
the Jersey runtime ServiceLocator
instance during application deployment, but are
otherwise ignored by server-side runtime, unless they implement also another contract
recognized by Jersey runtime.
instances
- instances to register.public final ResourceConfig registerResources(Resource... resources)
ResourceConfig
.resources
- resource models to register.public final ResourceConfig registerResources(java.util.Set<Resource> resources)
ResourceConfig
.resources
- resource models to register.public final ResourceConfig registerFinder(ResourceFinder resourceFinder)
ResourceFinder
to ResourceConfig
.resourceFinder
- ResourceFinder
public final ResourceConfig setApplicationName(java.lang.String applicationName)
applicationName
- Unique application name.public final ResourceConfig setClassLoader(java.lang.ClassLoader classLoader)
ClassLoader
which will be used for resource discovery.classLoader
- provided ClassLoader
.public final ResourceConfig packages(java.lang.String... packages)
Path
annotation
on parent classes and interfaces will be ignored.
Packages will be scanned recursively, including all nested packages.packages
- array of package names.packages(boolean, String...)
public final ResourceConfig packages(boolean recursive, java.lang.String... packages)
Path
annotation
on parent classes and interfaces will be ignored.
recursive
- defines whether any nested packages in the collection of specified
package names should be recursively scanned (value of true
)
as part of the package scanning or not (value of false
).packages
- array of package names.packages(String...)
public final ResourceConfig files(java.lang.String... files)
files
- array of file and directory names.public final ResourceConfig files(boolean recursive, java.lang.String... files)
recursive
- defines whether any sub-directories of the directories specified
in the collection of file names should be recursively scanned (value of true
)
as part of the file scanning or not (value of false
).files
- array of file and directory names.final void invalidateCache()
final void lock()
ServerProperties.APPLICATION_NAME
is defined.public final ServerConfig getConfiguration()
getConfiguration
in interface javax.ws.rs.core.Configurable<ResourceConfig>
public final java.util.Map<java.lang.String,java.lang.Object> getProperties()
getProperties
in interface javax.ws.rs.core.Configuration
getProperties
in class javax.ws.rs.core.Application
public final java.lang.Object getProperty(java.lang.String name)
getProperty
in interface javax.ws.rs.core.Configuration
public java.util.Collection<java.lang.String> getPropertyNames()
getPropertyNames
in interface javax.ws.rs.core.Configuration
public final boolean isProperty(java.lang.String name)
ExtendedConfig
boolean
.
Returns false
if the value is not convertible.isProperty
in interface ExtendedConfig
name
- property name.boolean
property value or false
if the property is not
convertible.public final java.util.Set<java.lang.Class<?>> getClasses()
getClasses
in interface javax.ws.rs.core.Configuration
getClasses
in class javax.ws.rs.core.Application
public final java.util.Set<java.lang.Object> getInstances()
getInstances
in interface javax.ws.rs.core.Configuration
public final java.util.Set<java.lang.Object> getSingletons()
getSingletons
in class javax.ws.rs.core.Application
final ComponentBag getComponentBag()
final void configureAutoDiscoverableProviders(org.glassfish.hk2.api.ServiceLocator locator)
locator
- service locator to obtain auto-discoverables from.final void configureForcedAutoDiscoverableProviders(org.glassfish.hk2.api.ServiceLocator locator)
locator
- service locator to obtain auto-discoverables from.final void configureMetaProviders(org.glassfish.hk2.api.ServiceLocator locator)
locator
- service locator to update with the custom binders.public javax.ws.rs.RuntimeType getRuntimeType()
getRuntimeType
in interface javax.ws.rs.core.Configuration
public boolean isEnabled(javax.ws.rs.core.Feature feature)
isEnabled
in interface javax.ws.rs.core.Configuration
public boolean isEnabled(java.lang.Class<? extends javax.ws.rs.core.Feature> featureClass)
isEnabled
in interface javax.ws.rs.core.Configuration
public boolean isRegistered(java.lang.Object component)
isRegistered
in interface javax.ws.rs.core.Configuration
public boolean isRegistered(java.lang.Class<?> componentClass)
isRegistered
in interface javax.ws.rs.core.Configuration
public java.util.Map<java.lang.Class<?>,java.lang.Integer> getContracts(java.lang.Class<?> componentClass)
getContracts
in interface javax.ws.rs.core.Configuration
java.util.Set<java.lang.Class<?>> _getClasses()
private sub-type
.private java.util.Set<java.lang.Class<?>> scanClasses()
private java.lang.String[] parsePropertyValue(java.lang.String propertyName)
java.util.Set<java.lang.Class<?>> getRegisteredClasses()
java.util.Set<java.lang.Object> _getSingletons()
private sub-type
.public final java.util.Set<Resource> getResources()
ServerConfig
getResources
in interface ServerConfig
public final java.lang.ClassLoader getClassLoader()
public final javax.ws.rs.core.Application getApplication()
javax.ws.rs.core.Application _getApplication()
getApplication()
method functionality in ResourceConfig.WrappingResourceConfig
.public java.lang.String getApplicationName()
setApplicationName(String)
java.lang.Class<? extends javax.ws.rs.core.Application> getApplicationClass()
ResourceConfig.WrappingResourceConfig
).final ResourceConfig setApplication(javax.ws.rs.core.Application app)
app
- JAX-RS applicationResourceConfig _setApplication(javax.ws.rs.core.Application app)
app
- application to be set for this ResourceConfigstatic ResourceConfig createRuntimeConfig(javax.ws.rs.core.Application application)
application
- deploy-time JAX-RS/Jersey application configuration.private static javax.ws.rs.core.Application unwrapCustomRootApplication(ResourceConfig resourceConfig)
static javax.ws.rs.core.Application unwrapApplication(javax.ws.rs.core.Application application)
application
class.
This method is similar to getApplication()
except if provided application was
created by wrapping multiple ResourceConfig
instances, this method will return the original (inner-most)
JAX-RS Application
sub-class rather than a potentially intermediate ResourceConfig
wrapper.
application
- application that is potentially wrapped.Application
subclass. May return the same instance directly,
in case the supplied application
instance is not a wrapper ResourceConfig
instance.private void setupApplicationName()