[
https://issues.apache.org/jira/browse/CXF-8824?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17698132#comment-17698132
]
Andriy Redko edited comment on CXF-8824 at 3/9/23 1:15 AM:
-----------------------------------------------------------
[~dmaplesden] thanks for reporting the issue. Apache CXF CDI extension always
inspect the classpath in order to discover JAX-RS annotated resources
(providers / features / filters / ...). The use of @Produces interfere with
that mechanism although the specification is very clear on handling providers
and applications (section 11.2.3, JSR-370):
> Providers and Application subclasses MUST be singletons or use application
> scope.
Which basically means the right way to use the @Produces would be with
@Singleton (or just use the automatic discovery but I assume you have reasons
to not doing that):
{noformat}
@Produces @Singleton
public ContainerRequestFilter containerRequestFilter () {
...
}
{noformat}
Sadly there is still an issue with that on CXF side - the singletons are added
multiple times, the fix is on the way.
was (Author: reta):
[~dmaplesden] thanks for reporting the issue. Apache CXF CDI extension always
inspect the classpath in order to discover JAX-RS annotated resources
(providers / features / filters / ...). The use of @Produces interfere with
that mechanism although the specification is very clear on handling providers
and applications (section 11.2.3, JSR-370):
> Providers and Application subclasses MUST be singletons or use application
> scope.
Which basically means the right way to use the @Produces would be with
@Singleton (or just use the automatic discovery but I assume you have reasons
to not doing that):
{noformat}
@Produces @Singleton
public ContainerRequestFilter containerRequestFilter () {
...
}
{noformat}
> CDI beans produced by @Produces methods are generated twice
> -----------------------------------------------------------
>
> Key: CXF-8824
> URL: https://issues.apache.org/jira/browse/CXF-8824
> Project: CXF
> Issue Type: Bug
> Components: Integration, JAX-RS
> Affects Versions: 3.2.0, 3.5.5
> Environment: CXF 3.5.5 running in Tomcat 9.0.70 using JBoss Weld
> 3.1.9 as the CDI implementation. Using cxf-integration-cdi and CXFCdiServlet
> Reporter: David Maplesden
> Priority: Major
>
> We recently upgraded from CXF 3.1.9 to 3.5.5 and after upgrade encountered
> this bug.
> Specifically we have some {{javax.ws.rs.container.ContainerRequestFilter}}
> implementations that are built using {{@Produces}} methods on our base
> {{javax.ws.rs.core.Application}} class. Since the upgrade we have discovered
> that these filters are being added to the request interceptor chain twice.
> After debugging I found that all CDI managed beans built by {{@Produces}}
> methods that use the {{@Provider}} annotation for discovery are now processed
> twice.
> It appears to me that the problem is in the current implementation of
> {{{}JAXRSCdiResourceExtension{}}}. This implementation has {{@Observes}}
> methods for both {{ProcessProducerMethod}} events and {{ProcessBean}} events
> - but {{ProcessProducerMethod}} extends {{ProcessBean}} so both of these
> handlers get called for each {{ProcessProducerMethod}} event fired by the CDI
> implementation. This means both handlers add the producer method to the list
> of {{providerBeans}} and the producer method is subsequently called twice
> when {{loadProviders()}} is called and two instances of the provider are
> passed to the {{{}JAXRSServerFactoryBean{}}}.
> I believe this behaviour was introduced by this commit:
> [https://github.com/apache/cxf/commit/4b96a222aea61f9fe80083c4c4bb1519955890ab]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)