Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CB109200BA5 for ; Wed, 19 Oct 2016 15:25:01 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C9A33160ADE; Wed, 19 Oct 2016 13:25:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9B2C2160AFE for ; Wed, 19 Oct 2016 15:25:00 +0200 (CEST) Received: (qmail 33309 invoked by uid 500); 19 Oct 2016 13:24:59 -0000 Mailing-List: contact dev-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list dev@cxf.apache.org Received: (qmail 32700 invoked by uid 99); 19 Oct 2016 13:24:58 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 13:24:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 56DEA180664 for ; Wed, 19 Oct 2016 13:24:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.68 X-Spam-Level: ** X-Spam-Status: No, score=2.68 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, HTML_OBFUSCATE_05_10=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id sFhzmFeJEiTt for ; Wed, 19 Oct 2016 13:24:53 +0000 (UTC) Received: from mail-qt0-f175.google.com (mail-qt0-f175.google.com [209.85.216.175]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 07A3B5F24F for ; Wed, 19 Oct 2016 13:24:53 +0000 (UTC) Received: by mail-qt0-f175.google.com with SMTP id q7so19128963qtq.1 for ; Wed, 19 Oct 2016 06:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jeqLTZOqSDqvCXVKwjugkS7V0qLfTk5Oo3SdTWpF7Rc=; b=WWEGoWgz9XfDW0/nHW5t+11Z7SgGrSaP3caThOydScd1/FJVP47PuDfXNjIJMJO0KF LoMpHtvzkDopm9hCakkBATQTPWfFzS8bMPsbpl9a8bFfFaVqiocnlDyYG6ma9wZ+lhVW BqPihVXZZ4nxomIM9KbCOI0L0ObkNAFIKYHPvrALeOpIlMdCSO6bjKkvavqdiNJPCwEa GKcAQQAiq6Mm2Kn4OHPd8g+1hsUW4tX81phDuc05uIE9GzlzIhnQPUbawZ1Qx701+hag yCp8vqnaZ0B9I+PGP2B4ttD459TbC2k/TrufzVzpDj0SvhOSziDH9C6kJ4eBzJvEv6i3 tl0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jeqLTZOqSDqvCXVKwjugkS7V0qLfTk5Oo3SdTWpF7Rc=; b=ZT2x3PQjSiLbsdIqD27974t3IR+N+hd2zDuidFDv3DwUH99tITp1UIz9jyXY1gep34 3+7bkA6zH8moj/WSPPN8P7yeq5oZebgdDOXk+AGORtsS9M8Msf854TH8u6pErEfo1t1y Siv5ae/PgTPVpYll61v7wYkUApetN49/HB+IhWZ4rO2gm+HI/3AMqPetq4jowJVxKn31 XkPtylP+d9oFeCFRKZOeFLLJvKRSU3TsVu7cNI9IaMzQeCMJ2n7Mgr/cRU0Y4GSVsTMi FYD3rTZVydyMuhzeVcJGIKFkKJWbfBVFX8cDoGQq5vNz1+C+UrAz4VORMSsMqD1X5Lyz mPaw== X-Gm-Message-State: AA6/9RnCwYUCNGgYPbEB1Q8/+cWFoG4URJnfm04eVmbU7ug1bgRma9tT59ZjiRi59bEuRclmnu+n+VPkJS/Caw== X-Received: by 10.28.88.78 with SMTP id m75mr5407356wmb.26.1476883490612; Wed, 19 Oct 2016 06:24:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.110.73 with HTTP; Wed, 19 Oct 2016 06:24:29 -0700 (PDT) In-Reply-To: References: <30e2470a-2f14-8d56-8902-a7f4b7b3f18a@gmail.com> <1666042994.20161018221403@gmail.com> From: Romain Manni-Bucau Date: Wed, 19 Oct 2016 15:24:29 +0200 Message-ID: Subject: Re: cxi integration: multiple buses during deployment? To: Andrey Redko Cc: Daniel Kulp , "John D. Ament" Content-Type: multipart/alternative; boundary=001a11442806d52b5f053f37bb09 archived-at: Wed, 19 Oct 2016 13:25:02 -0000 --001a11442806d52b5f053f37bb09 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable doesn't work but for a weirder reason. CdiBean is added programmatically - all fine Then it is directly used to get the bus (in "use the default bus" mode). This is not really fine since the CDI impl is free to wrap this so you should retrieve the actual instance of the bus and get it with this Bean instance and not supposing the CDI container will return you the instance you added. Concretely here are the few fixes (on 3.1.x-fixes branch): https://gist.github.com/rmannibucau/0bb8abf2e164d953be17b24b4a08e685 In CDI you can't assume equals/hashcode of Bean so you need to lookup the bus instance and not use the internal one. This patch solves the issue. Romain Manni-Bucau @rmannibucau | Blog | Old Wordpress Blog | Github | LinkedIn | Tomitriber | JavaEE Factory 2016-10-19 13:35 GMT+02:00 Andrey Redko : > Hi Roman, > > Thanks a lot for clarifying on things. Could you please try latest > 3.1.9-SNAPSHOT / 3.2.0-SNAPSHOT against this issue? > The fix should be there. Thanks! > > Best Regards, > Andriy Redko > > On Wed, Oct 19, 2016 at 2:28 AM, Romain Manni-Bucau > wrote: > >> Le 19 oct. 2016 04:14, "Andriy Redko" a =C3=A9crit : >> > >> > I think this is what is happening: >> > - Roman defines own CXF bus bean, named "cxf" >> >> This is a workaround to be able to lookup the bus in my workaround >> extension. Not doing it without my extension leads to the issue. >> >> > - our JAX-RS CDI extension finds it and makes it a "default" bus to b= e >> used >> > for JAXRSServerFactoryBean instances >> > - however, JAXRSServerFactoryBean::setApplication() would create a >> new bus >> > nonetheless, because the actual call to >> JAXRSServerFactoryBean::setBus would >> > be done later >> > >> >> This is the issue, custom bus or not. >> >> > The issue in this case is that application was created using one bus >> instance, >> > but JAXRSServerFactoryBean would be initialized using another bus >> instance. This >> > is my understading of the problem. Hopefully it makes sense. >> > >> >> The factory uses the cdi bus but the application used a "prototype" bus. >> >> Side note: i deploy with tomcat embedded a single app so I am not in >> "multiple" deployments case. >> >> > Best Regards, >> > Andriy Redko >> > >> > JDA> So still something isn't clicking as I don't have Romain's issue. >> Is it >> > JDA> specific to when you have multiple deployments in your JVM? >> > >> > JDA> On Oct 18, 2016 09:02, "Romain Manni-Bucau" >> wrote: >> > >> > >> 2016-10-18 14:43 GMT+02:00 Andrey Redko : >> > >> > >> > Hi Romain Manni-Bucau, >> > >> > >> > >> > Yes, technically we do have this option, but I would suggest to u= se >> > >> > explicit wirings instead of thread local context. It >> > >> > could have quite a number of side effects. I hope you would agree >> with >> > >> > that. >> > >> > >> > >> > >> > >> I agree it is better but side effect should be null since the value >> is >> > >> cleaned up after. If not then runtime can have side effects which >> would be >> > >> a bigger issue ;) >> > >> > >> > >> > Thanks! >> > >> > >> > >> > Best Regards, >> > >> > Andriy Redko >> > >> > >> > >> > >> > >> > On Tue, Oct 18, 2016 at 7:49 AM, Romain Manni-Bucau < >> > >> rmannibucau@gmail.com >> > >> > > >> > >> > wrote: >> > >> > >> > >> > > We also have option 3: set the thread bus as in the workaround = I >> used. >> > >> > > >> > >> > > >> > >> > > Romain Manni-Bucau >> > >> > > @rmannibucau | Blog >> > >> > > | Old Wordpress Blog >> > >> > > | Github > > >> > > rmannibucau> | >> > >> > > LinkedIn | Tomitriber >> > >> > > | JavaEE Factory >> > >> > > >> > >> > > >> > >> > > 2016-10-18 13:47 GMT+02:00 Sergey Beryozkin < >> sberyozkin@gmail.com>: >> > >> > > >> > >> > > > Hi Andriy >> > >> > > > yes, option 1 is probably the simplest for the CDI integratio= n >> path, >> > >> > > > >> > >> > > > Thanks, Sergey >> > >> > > > >> > >> > > > On 18/10/16 12:43, Andrey Redko wrote: >> > >> > > > >> > >> > > >> Hey guys, >> > >> > > >> >> > >> > > >> Indeed, there is an issue with CDI and usage of custom bus. = I >> think >> > >> > > there >> > >> > > >> are couple of the options >> > >> > > >> we have here: >> > >> > > >> - pass the bus instance to ResourceUtils::createApplication= , >> in >> > >> this >> > >> > > >> case >> > >> > > >> if bus is not set, the behaviour would be exactly the same >> > >> > > >> - change the way JAXRSServerFactoryBean is being created so >> we >> > >> could >> > >> > > set >> > >> > > >> the bus before setting the application >> > >> > > >> >> > >> > > >> Romain Manni-Bucau, do we have a ticket for it? If not, coul= d >> you >> > >> > please >> > >> > > >> create one, we'll work on a fix for it. >> > >> > > >> Thanks. >> > >> > > >> >> > >> > > >> >> > >> > > >> On Tue, Oct 18, 2016 at 7:08 AM, Romain Manni-Bucau < >> > >> > > >> rmannibucau@gmail.com> >> > >> > > >> wrote: >> > >> > > >> >> > >> > > >> Not yet something failling i can share but globally I ended >> up doing >> > >> > > that: >> > >> > > >>> >> > >> > > >>> @Named("cxf") >> > >> > > >>> @ApplicationScoped >> > >> > > >>> public class BusInstance implements Bus { >> > >> > > >>> @Delegate >> > >> > > >>> private Bus delegate =3D new ExtensionManagerBus(); >> > >> > > >>> } >> > >> > > >>> public class OWBAutoSetup implements >> ServletContainerInitializer { >> > >> > > >>> @Override >> > >> > > >>> public void onStartup(final Set> c, final >> ServletContext >> > >> > ctx) >> > >> > > >>> throws ServletException { >> > >> > > >>> >> > >> > > >>> ctx.addListener(WebBeansConfigurationListener.class); >> > >> > > >>> ctx.addListener(WebBeansConfigurationHttpSessionListener. >> class); >> > >> > > >>> } >> > >> > > >>> } >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> public class CxfCdiAutoSetup implements >> > >> ServletContainerInitializer { >> > >> > > >>> @Override >> > >> > > >>> public void onStartup(final Set> c, final >> ServletContext >> > >> > ctx) >> > >> > > >>> throws ServletException { >> > >> > > >>> final ServletRegistration.Dynamic jaxrs =3D >> ctx.addServlet("cxf-cdi", >> > >> > > >>> CXFCdiServlet.class); >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> jaxrs.setLoadOnStartup(1); >> > >> > > >>> jaxrs.setAsyncSupported(true); >> > >> > > >>> jaxrs.addMapping("/*"); // TODO: config >> > >> > > >>> } >> > >> > > >>> } >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> With my workaround extension it works fine, without there i= s >> this >> > >> > > >>> mismatch >> > >> > > >>> of bus. >> > >> > > >>> >> > >> > > >>> Have to admit I have no idea how >> > >> > > >>> org.apache.cxf.jaxrs.utils.ResourceUtils#createApplication( >> > >> > javax.ws.rs >> > >> > > . >> > >> > > >>> core.Application, >> > >> > > >>> boolean, boolean) could reuse the right bus in current stat= e >> of the >> > >> > cdi >> > >> > > >>> module. If you check >> > >> > > >>> org.apache.cxf.cdi.JAXRSCdiResourceExtension#createFactoryI= n >> > >> > > >>> stance(javax. >> > >> > > >>> ws.rs.core.Application, >> > >> > > >>> java.util.List, java.util.List, java.util.List> extends >> > >> > > >>> org.apache.cxf.feature.Feature>) the bus is set but too lat= e >> > >> (after >> > >> > > bean >> > >> > > >>> .setApplication(app);). >> > >> > > >>> >> > >> > > >>> Romain Manni-Bucau >> > >> > > >>> @rmannibucau | Blog >> > >> > > >>> | Old Wordpress Blog >> > >> > > >>> | Github < >> https://github.com/ >> > >> > > >>> rmannibucau> | >> > >> > > >>> LinkedIn | >> Tomitriber >> > >> > > >>> | JavaEE Factory >> > >> > > >>> >> > >> > > >>> >> > >> > > >>> 2016-10-18 12:50 GMT+02:00 John D. Ament < >> johndament@apache.org>: >> > >> > > >>> >> > >> > > >>> Do you have a sample project that demonstrates the issue? >> > >> > > >>>> >> > >> > > >>>> Also, do you see setBus method being called on >> CXFCdiServlet? How >> > >> > > many >> > >> > > >>>> times do you see it invoked? Maybe step through loadBus t= o >> see >> > >> > which >> > >> > > >>>> >> > >> > > >>> path >> > >> > > >>> >> > >> > > >>>> it follows. >> > >> > > >>>> >> > >> > > >>>> On Tue, Oct 18, 2016 at 6:24 AM Romain Manni-Bucau < >> > >> > > >>>> >> > >> > > >>> rmannibucau@gmail.com> >> > >> > > >>> >> > >> > > >>>> wrote: >> > >> > > >>>> >> > >> > > >>>> Not really, >> > >> > > >>>>> >> > >> > > >>>>> I don't have any bus bean, just using the default one of >> the >> > >> > > extenson - >> > >> > > >>>>> behavior is the same however if I impl my own bus bean. >> > >> > > >>>>> >> > >> > > >>>>> Issue is in the load() method of the extension. It gets >> the bus >> > >> and >> > >> > > >>>>> >> > >> > > >>>> then >> > >> > > >>> >> > >> > > >>>> calls ResourceUtils.createApplication(application, false, >> false) >> > >> > > which >> > >> > > >>>>> >> > >> > > >>>> will >> > >> > > >>>> >> > >> > > >>>>> call org.apache.cxf.jaxrs.JAXRSServ >> erFactoryBean#setApplication >> > >> > > which >> > >> > > >>>>> >> > >> > > >>>> will >> > >> > > >>>> >> > >> > > >>>>> do getBus() wich uses BusFactory.getThreadDefaultBus() >> which is >> > >> > > >>>>> >> > >> > > >>>> obviously >> > >> > > >>>> >> > >> > > >>>>> not set so you end up in org.apache.cxf.BusFactory# >> > >> createThreadBus >> > >> > > >>>>> >> > >> > > >>>> which >> > >> > > >>> >> > >> > > >>>> does a newInstance().createBus() and here you are, you hav= e >> 2 >> > >> > > instances >> > >> > > >>>>> >> > >> > > >>>> of >> > >> > > >>>> >> > >> > > >>>>> a bus. >> > >> > > >>>>> >> > >> > > >>>>> Romain >> > >> > > >>>>> >> > >> > > >>>>> 2016-10-18 12:10 GMT+02:00 John D. Ament < >> john.d.ament@gmail.com >> > >> >: >> > >> > > >>>>> >> > >> > > >>>>> Romain, >> > >> > > >>>>>> >> > >> > > >>>>>> Depends on how you're trying to instantiate it. There i= s >> 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 t= he >> > >> > > >>>>>> >> > >> > > >>>>> 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=3Dall?). >> > >> > > >>>>>> >> > >> > > >>>>>> John >> > >> > > >>>>>> >> > >> > > >>>>>> On Tue, Oct 18, 2016 at 5:58 AM Romain Manni-Bucau < >> > >> > > >>>>>> >> > >> > > >>>>> rmannibucau@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 extend= s >> > >> > > >>>>>>> JAXRSCdiResourceExtension { >> > >> > > >>>>>>> @Override >> > >> > > >>>>>>> public void load(@Observes final >> AfterDeploymentValidation >> > >> > > >>>>>>> >> > >> > > >>>>>> event, >> > >> > > >>> >> > >> > > >>>> final BeanManager beanManager) { >> > >> > > >>>>>>> final Bus bus =3D >> > >> > > >>>>>>> >> > >> > > >>>>>>> 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 | Blog >> > >> > > >>>>>>> | Old Wordpress >> Blog >> > >> > > >>>>>>> | Github < >> > >> > > >>>>>>> https://github.com/rmannibucau> | >> > >> > > >>>>>>> LinkedIn | >> > >> Tomitriber >> > >> > > >>>>>>> | JavaEE Factory >> > >> > > >>>>>>> >> > >> > > >>>>>>> >> > >> > > >>>>>>> >> > >> > > >>>>>> >> > >> > > >>>>> >> > >> > > >>>> >> > >> > > >>> >> > >> > > >> >> > >> > > > >> > >> > > > -- >> > >> > > > Sergey Beryozkin >> > >> > > > >> > >> > > > Talend Community Coders >> > >> > > > http://coders.talend.com/ >> > >> > > > >> > >> > > >> > >> > >> > >> > >> > > --001a11442806d52b5f053f37bb09--