Romain,

Depends on how you're trying to instantiate it.  There is a CdiBusBean
provided by CXF which does what you're trying to do -
https://github.com/apache/cxf/blob/3.1.x-fixes/integration/cdi/src/main/java/org/apache/cxf/cdi/CdiBusBean.java#L40
,
take a look at the create method.

I was actually contemplating removing the @Inject from the CXFCdiServlet's
set method, it seems to work inconsistently.  However, i suspect that your
issue is that you're getting a Bus registered as a valid CDI bean
(bean-discovery-mode=all?).

John

On Tue, Oct 18, 2016 at 5:58 AM Romain Manni-Bucau <rmannibu...@gmail.com>
wrote:

> Hi guys,
>
> in cdi-integration I don't get how the deployment can work cause the thread
> local bus is not set
>
> Here what i did to ensure i use a single bus (and prevented the cxf one to
> run):
>
> public class JAXRSCdiResourceExtensionWorkaround extends
> JAXRSCdiResourceExtension {
>     @Override
>     public void load(@Observes final AfterDeploymentValidation event,
> final BeanManager beanManager) {
>         final Bus bus =
>
> Bus.class.cast(beanManager.getReference(beanManager.resolve(beanManager.getBeans(Bus.class)),
> Bus.class, null));
>         BusFactory.setThreadDefaultBus(bus); // cause app class will
> rely on that and would create multiple bus and then deployment would
> be broken
>         try {
>             super.load(event, beanManager);
>         } finally {
>             BusFactory.clearDefaultBusForAnyThread(bus);
>         }
>     }
> }
>
>
> Issue was caused by JAXRSCdiResourceExtension#createFactoryInstance which
> calls ResourceUtils.createApplication which uses the thread bus which is
> not set by the extension leading to 2 buses.
>
> Did I miss something?
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>

Reply via email to