Class ResourceConfig
- java.lang.Object
-
- jakarta.ws.rs.core.Application
-
- org.glassfish.jersey.server.ResourceConfig
-
- All Implemented Interfaces:
jakarta.ws.rs.core.Configurable<ResourceConfig>,jakarta.ws.rs.core.Configuration,ExtendedConfig,ServerConfig
public class ResourceConfig extends jakarta.ws.rs.core.Application implements jakarta.ws.rs.core.Configurable<ResourceConfig>, ServerConfig
The resource configuration for configuring a web application.- Author:
- Paul Sandoz, Martin Matula, Michal Gajdos, Marek Potociar
-
-
Constructor Summary
Constructors Constructor Description ResourceConfig()Create 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceConfigaddProperties(Map<String,Object> properties)Add properties toResourceConfig.ResourceConfigfiles(boolean recursive, String... files)Adds array of file and directory names to scan for components.ResourceConfigfiles(String... files)Adds array of file and directory names to scan for components.static ResourceConfigforApplication(jakarta.ws.rs.core.Application application)Returns aResourceConfiginstance for the supplied application.static ResourceConfigforApplicationClass(Class<? extends jakarta.ws.rs.core.Application> applicationClass)Returns aResourceConfiginstance wrapping the application of the supplied class.static ResourceConfigforApplicationClass(Class<? extends jakarta.ws.rs.core.Application> applicationClass, Set<Class<?>> defaultClasses)Returns aResourceConfiginstance wrapping the application of the supplied class.jakarta.ws.rs.core.ApplicationgetApplication()Returns JAX-RS application corresponding with this ResourceConfig.StringgetApplicationName()Get the name of the Jersey application.StringgetApplicationPath()Returns encoded value ofApplicationPathannotation of the Application corresponding with this ResourceConfig ornullwhen the annotation is not present.Set<Class<?>>getClasses()ClassLoadergetClassLoader()Get resource and provider class loader.ServerConfiggetConfiguration()Map<Class<?>,Integer>getContracts(Class<?> componentClass)Set<Object>getInstances()Map<String,Object>getProperties()ObjectgetProperty(String name)Collection<String>getPropertyNames()Set<Resource>getResources()Get programmatically modeled resources.jakarta.ws.rs.RuntimeTypegetRuntimeType()Set<Object>getSingletons()booleanhasProperty(String name)booleanisEnabled(jakarta.ws.rs.core.Feature feature)booleanisEnabled(Class<? extends jakarta.ws.rs.core.Feature> featureClass)booleanisProperty(String name)booleanisRegistered(Class<?> componentClass)booleanisRegistered(Object component)ResourceConfigpackages(boolean recursive, ClassLoader classLoader, String... packages)Adds array of package names which will be used to scan for components.ResourceConfigpackages(boolean recursive, String... packages)Adds array of package names which will be used to scan for components.ResourceConfigpackages(String... packages)Adds array of package names which will be used to scan for components.ResourceConfigproperty(String name, Object value)ResourceConfigregister(Class<?> componentClass)ResourceConfigregister(Class<?> componentClass, int bindingPriority)ResourceConfigregister(Class<?> componentClass, Class<?>... contracts)ResourceConfigregister(Class<?> componentClass, Map<Class<?>,Integer> contracts)ResourceConfigregister(Object component)ResourceConfigregister(Object component, int bindingPriority)ResourceConfigregister(Object component, Class<?>... contracts)ResourceConfigregister(Object component, Map<Class<?>,Integer> contracts)ResourceConfigregisterClasses(Class<?>... classes)Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig.ResourceConfigregisterClasses(Set<Class<?>> classes)Register annotated JAX-RS resource, JAX-RS or Jersey contract provider or JAX-RS feature in theResourceConfig.ResourceConfigregisterFinder(ResourceFinder resourceFinder)Add aResourceFindertoResourceConfig.ResourceConfigregisterInstances(Object... instances)Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature,Jersey Binderinstances (singletons) in theResourceConfig.ResourceConfigregisterInstances(Set<Object> instances)Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS featureJersey Binderinstances (singletons) in theResourceConfig.ResourceConfigregisterResources(Set<Resource> resources)Register new resource models in theResourceConfig.ResourceConfigregisterResources(Resource... resources)Register new programmatic resource models in theResourceConfig.ResourceConfigsetApplicationName(String applicationName)Set the name of the application.ResourceConfigsetClassLoader(ClassLoader classLoader)SetClassLoaderwhich will be used for resource discovery.ResourceConfigsetProperties(Map<String,?> properties)Set new configuration properties replacing all previously set properties.
-
-
-
Constructor Detail
-
ResourceConfig
public ResourceConfig()
Create a new resource configuration without any custom properties or resource and provider classes.
-
ResourceConfig
public ResourceConfig(Set<Class<?>> classes)
Create a new resource configuration initialized with a given set of resource/provider classes.- Parameters:
classes- application-specific resource and/or provider classes.
-
ResourceConfig
public ResourceConfig(Class<?>... classes)
Create a new resource configuration initialized with a given set of resource/provider classes.- Parameters:
classes- application-specific resource and/or provider classes.
-
ResourceConfig
public ResourceConfig(ResourceConfig original)
Create a defensive resource configuration copy initialized with a givenResourceConfig.- Parameters:
original- resource configuration to createAndInitialize a defensive copy from.
-
-
Method Detail
-
forApplication
public static ResourceConfig forApplication(jakarta.ws.rs.core.Application application)
Returns aResourceConfiginstance for the supplied application. If the application is an instance ofResourceConfigthe method returns defensive copy of the resource config. Otherwise it creates a newResourceConfigfrom the application.- Parameters:
application- Application to provide theResourceConfiginstance for.- Returns:
- ResourceConfig instance for the supplied application.
-
forApplicationClass
public static ResourceConfig forApplicationClass(Class<? extends jakarta.ws.rs.core.Application> applicationClass)
Returns aResourceConfiginstance 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 jakarta.ws.rs.core.Application> applicationClass, Set<Class<?>> defaultClasses)
Returns aResourceConfiginstance 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
public final ResourceConfig addProperties(Map<String,Object> properties)
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
public ResourceConfig setProperties(Map<String,?> properties)
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
public ResourceConfig property(String name, Object value)
- Specified by:
propertyin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Class<?> componentClass)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Class<?> componentClass, int bindingPriority)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Class<?> componentClass, Class<?>... contracts)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Class<?> componentClass, Map<Class<?>,Integer> contracts)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Object component)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Object component, int bindingPriority)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Object component, Class<?>... contracts)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
register
public ResourceConfig register(Object component, Map<Class<?>,Integer> contracts)
- Specified by:
registerin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
registerClasses
public final ResourceConfig registerClasses(Set<Class<?>> classes)
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
InjectionManagerinstance 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
binderclasses is note supported. Binders must beregistered as instances.- Parameters:
classes- classes to register.- Returns:
- updated resource configuration instance.
-
registerClasses
public final ResourceConfig registerClasses(Class<?>... classes)
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
InjectionManagerinstance 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
binderclasses is note supported. Binders must beregistered as instances.- Parameters:
classes- classes to register.- Returns:
- updated resource configuration instance.
-
registerInstances
public final ResourceConfig registerInstances(Set<Object> instances)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS featureJersey Binderinstances (singletons) in theResourceConfig.Note that registered binders and JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManagerinstance 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
public final ResourceConfig registerInstances(Object... instances)
Register annotated JAX-RS resource, JAX-RS or Jersey contract provider, JAX-RS feature,Jersey Binderinstances (singletons) in theResourceConfig.Note that registered binders and JAX-RS features are used to initialize and configure the Jersey runtime
InjectionManagerinstance 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
public final ResourceConfig registerResources(Resource... resources)
Register new programmatic resource models in theResourceConfig.- Parameters:
resources- resource models to register.- Returns:
- updated resource configuration instance.
-
registerResources
public final ResourceConfig registerResources(Set<Resource> resources)
Register new resource models in theResourceConfig.- Parameters:
resources- resource models to register.- Returns:
- updated resource configuration instance.
-
registerFinder
public final ResourceConfig registerFinder(ResourceFinder resourceFinder)
Add aResourceFindertoResourceConfig.- Parameters:
resourceFinder-ResourceFinder- Returns:
- updated resource configuration instance.
-
setApplicationName
public final ResourceConfig setApplicationName(String applicationName)
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
public final ResourceConfig setClassLoader(ClassLoader classLoader)
SetClassLoaderwhich will be used for resource discovery.- Parameters:
classLoader- providedClassLoader.- Returns:
- updated resource configuration instance.
-
packages
public final ResourceConfig packages(String... packages)
Adds array of package names which will be used to scan for components. Package scanning ignores inheritance and thereforePathannotation 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(boolean, String...)
-
packages
public final ResourceConfig packages(boolean recursive, String... packages)
Adds array of package names which will be used to scan for components. Package scanning ignores an inheritance and thereforePathannotation 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(String...)
-
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 thereforePathannotation 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:
packages(String...)
-
files
public final ResourceConfig files(String... 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
public final ResourceConfig files(boolean recursive, String... 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
public final ServerConfig getConfiguration()
- Specified by:
getConfigurationin interfacejakarta.ws.rs.core.Configurable<ResourceConfig>
-
getProperties
public final Map<String,Object> getProperties()
- Specified by:
getPropertiesin interfacejakarta.ws.rs.core.Configuration- Overrides:
getPropertiesin classjakarta.ws.rs.core.Application
-
hasProperty
public final boolean hasProperty(String name)
- Specified by:
hasPropertyin interfacejakarta.ws.rs.core.Configuration
-
getProperty
public final Object getProperty(String name)
- Specified by:
getPropertyin interfacejakarta.ws.rs.core.Configuration
-
getPropertyNames
public Collection<String> getPropertyNames()
- Specified by:
getPropertyNamesin interfacejakarta.ws.rs.core.Configuration
-
isProperty
public final boolean isProperty(String name)
- Specified by:
isPropertyin interfaceExtendedConfig
-
getClasses
public final Set<Class<?>> getClasses()
- Specified by:
getClassesin interfacejakarta.ws.rs.core.Configuration- Overrides:
getClassesin classjakarta.ws.rs.core.Application
-
getInstances
public final Set<Object> getInstances()
- Specified by:
getInstancesin interfacejakarta.ws.rs.core.Configuration
-
getSingletons
public final Set<Object> getSingletons()
- Overrides:
getSingletonsin classjakarta.ws.rs.core.Application
-
getRuntimeType
public jakarta.ws.rs.RuntimeType getRuntimeType()
- Specified by:
getRuntimeTypein interfacejakarta.ws.rs.core.Configuration
-
isEnabled
public boolean isEnabled(jakarta.ws.rs.core.Feature feature)
- Specified by:
isEnabledin interfacejakarta.ws.rs.core.Configuration
-
isEnabled
public boolean isEnabled(Class<? extends jakarta.ws.rs.core.Feature> featureClass)
- Specified by:
isEnabledin interfacejakarta.ws.rs.core.Configuration
-
isRegistered
public boolean isRegistered(Object component)
- Specified by:
isRegisteredin interfacejakarta.ws.rs.core.Configuration
-
isRegistered
public boolean isRegistered(Class<?> componentClass)
- Specified by:
isRegisteredin interfacejakarta.ws.rs.core.Configuration
-
getContracts
public Map<Class<?>,Integer> getContracts(Class<?> componentClass)
- Specified by:
getContractsin interfacejakarta.ws.rs.core.Configuration
-
getResources
public final Set<Resource> getResources()
Description copied from interface:ServerConfigGet programmatically modeled resources.- Specified by:
getResourcesin interfaceServerConfig- Returns:
- programmatically modeled resources.
-
getClassLoader
public final ClassLoader getClassLoader()
Get resource and provider class loader.- Returns:
- class loader to be used when looking up the resource classes and providers.
-
getApplication
public final jakarta.ws.rs.core.Application getApplication()
Returns JAX-RS application corresponding with this ResourceConfig.- Returns:
- JAX-RS application corresponding with this ResourceConfig.
-
getApplicationPath
public final String getApplicationPath()
Returns encoded value ofApplicationPathannotation of the Application corresponding with this ResourceConfig ornullwhen the annotation is not present.- Returns:
- Returns encoded value of
ApplicationPathannotation of the Application corresponding with this ResourceConfig.
-
getApplicationName
public String getApplicationName()
Get the name of the Jersey application.- Returns:
- Name of the application.
- See Also:
setApplicationName(String)
-
-