Class ResteasyParamCdiExtension
java.lang.Object
org.jboss.resteasy.cdi.ResteasyParamCdiExtension
- All Implemented Interfaces:
jakarta.enterprise.inject.spi.Extension
public class ResteasyParamCdiExtension
extends Object
implements jakarta.enterprise.inject.spi.Extension
A CDI
Extension that enables Jakarta REST parameter annotations (@CookieParam, @FormParam,
@HeaderParam, @MatrixParam, @PathParam, @QueryParam, and @BeanParam) to
function as CDI qualifiers. This allows Jakarta REST resource classes to receive parameter values via CDI
constructor injection rather than requiring a public no-arg constructor.
The extension operates in six CDI lifecycle phases:
BeforeBeanDiscovery— registers each@*Paramannotation as a CDI qualifierProcessAnnotatedType— adds@Injectto@*Param-annotated fields, setter methods, and constructors so that CDI resolves parameter values automatically. RESTEasy-specific annotations (org.jboss.resteasy.annotations.jaxrs.*Param) are also handled by adding the corresponding Jakarta REST annotation alongside@Inject. The@BeanParamaggregators of resources are recorded.AfterTypeDiscovery— makes each recorded@BeanParamaggregator which is not a bean a@DependentbeanProcessInjectionPoint— collects the types of all@*Param-annotated injection pointsAfterBeanDiscovery— registers synthetic beans that produce parameter values at request time by delegating toParameterExtractorsAfterDeploymentValidation— warns about@BeanParamaggregators with a normal scope
- Author:
- James R. Perkins
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBeanParamTypes(jakarta.enterprise.inject.spi.AfterTypeDiscovery event) Makes each@BeanParamaggregator of a resource which is not a bean a@Dependentbean, and adds@Injectto its@*Param-annotated members.<T> voidobserveBeanParamCandidates(jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event) Records the discovered types which may be@BeanParamaggregators, so thataddBeanParamTypes(AfterTypeDiscovery)does not add a type which is already a bean.<T> voidobserveParamResources(jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event) Observes Jakarta REST resource types and adds@Injectto fields, setter methods, and constructors annotated with@*Paramannotations so that CDI can resolve parameter values via the synthetic beans registered by this extension.<T,X> void processInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint<T, X> pip) Observes each injection point during bean discovery and records the types of any injection points annotated with a@*Paramqualifier.voidregisterParamQualifiers(jakarta.enterprise.inject.spi.AfterBeanDiscovery afd, jakarta.enterprise.inject.spi.BeanManager beanManager) Registers the@*Paramannotations as CDI qualifiers with producers.voidregisterQualifiers(jakarta.enterprise.inject.spi.BeforeBeanDiscovery event) Registers each@*Paramannotation as a CDI qualifier, marking all annotation members asNonbindingso that qualifier resolution matches on presence alone rather than on member values.voidvalidateBeanParamScopes(jakarta.enterprise.inject.spi.AfterDeploymentValidation event, jakarta.enterprise.inject.spi.BeanManager beanManager) Logs a warning for each@BeanParamaggregator whose bean has a normal scope.
-
Constructor Details
-
ResteasyParamCdiExtension
public ResteasyParamCdiExtension()
-
-
Method Details
-
registerQualifiers
public void registerQualifiers(@Observes jakarta.enterprise.inject.spi.BeforeBeanDiscovery event) Registers each@*Paramannotation as a CDI qualifier, marking all annotation members asNonbindingso that qualifier resolution matches on presence alone rather than on member values.- Parameters:
event- the before bean discovery event
-
observeParamResources
public <T> void observeParamResources(@Observes jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event) Observes Jakarta REST resource types and adds@Injectto fields, setter methods, and constructors annotated with@*Paramannotations so that CDI can resolve parameter values via the synthetic beans registered by this extension. This covers both Jakarta REST annotations (jakarta.ws.rs.*Param) and RESTEasy-specific annotations (org.jboss.resteasy.annotations.jaxrs.*Param).- Type Parameters:
T- the type being processed- Parameters:
event- the annotated type being processed
-
observeBeanParamCandidates
public <T> void observeBeanParamCandidates(@Observes jakarta.enterprise.inject.spi.ProcessAnnotatedType<T> event) Records the discovered types which may be@BeanParamaggregators, so thataddBeanParamTypes(AfterTypeDiscovery)does not add a type which is already a bean. The scope and stereotype meta-annotations match a type with a bean defining annotation, which may have only@Contextmembers or none. Any other type without these annotations has nothing for CDI to inject.- Type Parameters:
T- the type being processed- Parameters:
event- the annotated type being processed
-
addBeanParamTypes
public void addBeanParamTypes(@Observes jakarta.enterprise.inject.spi.AfterTypeDiscovery event) Makes each@BeanParamaggregator of a resource which is not a bean a@Dependentbean, and adds@Injectto its@*Param-annotated members. CDI then creates the aggregator, and injects all its members, as for an aggregator which is a bean. An aggregator which CDI cannot create, e.g. one without a no-argument or@Injectconstructor, is left to RESTEasy.- Parameters:
event- the after type discovery event
-
validateBeanParamScopes
public void validateBeanParamScopes(@Observes jakarta.enterprise.inject.spi.AfterDeploymentValidation event, jakarta.enterprise.inject.spi.BeanManager beanManager) Logs a warning for each@BeanParamaggregator whose bean has a normal scope. The aggregator is then a client proxy, whose fields do not hold the parameter values, e.g. when validating a@Validaggregator.- Parameters:
event- the after deployment validation eventbeanManager- the bean manager
-
registerParamQualifiers
public void registerParamQualifiers(@Observes jakarta.enterprise.inject.spi.AfterBeanDiscovery afd, jakarta.enterprise.inject.spi.BeanManager beanManager) Registers the@*Paramannotations as CDI qualifiers with producers.- Parameters:
afd- the after bean discovery eventbeanManager- the bean manager
-
processInjectionPoint
public <T,X> void processInjectionPoint(@Observes jakarta.enterprise.inject.spi.ProcessInjectionPoint<T, X> pip) Observes each injection point during bean discovery and records the types of any injection points annotated with a@*Paramqualifier. These types are later used to register synthetic producer beans.- Type Parameters:
T- the bean class of the bean that declares the injection pointX- the declared type of the injection point- Parameters:
pip- the process injection point event
-