Hi Rémy, I put a few comments inline hoping it helps
Le mar. 22 nov. 2022 à 16:11, Rémy Maucherat <r...@apache.org> a écrit : > Hi, > > Following a post on the user list, I have looked into CDI and > injection processing in Tomcat standalone (or standalone extended by > CDI) and found the following issues: > > a) metadata-complete is done wrong. The spec got retconned some time > ago and metadata-complete only means Servlet spec defining metadata, > such as @WebServlet (= the ones that require scanning all classes just > in case). So in practice inside DefaultInstanceManager the > ignoreAnnotations flag shouldn't be used at all and it should simply > be removed. I am ok on only doing this in 11 ;) > > b) CDI is not intertwined with the DefaultInstanceManager. Basically > as the user said, injections should be done *before* @PostConstruct, > and it . There's a (minor) problem with the DefaultInstanceManager > API, a method needs to be protected and then integrations will then be > able to hack inside the DefaultInstanceManager. You can see this here > in the OWB integration: > > https://github.com/apache/tomcat/blob/main/modules/owb/src/main/java/org/apache/webbeans/web/tomcat/OpenWebBeansInstanceManager.java#L102 > (basically, first call newInstance, because there's no other way, then > inject, but newInstance will have already invoked @PostConstruct). To > fix this, I plan to add an Injector interface to > DefaultInstanceManager since this is pretty much the only way to do > this cleanly in Tomcat standalone (taking over the whole > DefaultInstanceManager is clearly not the best idea). > Yeah, TomEE ([1]) had some hard time with JSP due to that and its re-implementation of the instantiation. Basically the idea was to implement it aside Tomcat default impl but for some classes it was not convenient enough. That said I have to admit I'm not sure it needs a new concept (injector) because basically it will copy the instance manager API (inject, release or something like that since it is not only about the inject phase so either you define the lifecycle or you store a Runnable you call at release time too - isnt the abstraction too complex then?). Another issue there is that newInstance assumes a "new" which means you can not use a CDI instance generally speaking, only a banalised instance which gets injections so it means you can just impl yourself a newInstance+whatever you want+postconstruct call (this is light actually). This is where setting ignoreAnnotations would be quite fancy in your own instance manager and wouldnt need any new API. That said, enabling to use a CDI instance would be way more powerful and is not against the spec - it is actually not specified AFAIK. Indeed it would need a toggle on the OWBIM of Tomcat integration but it would also open way more doors in terms of usage because your servlet (filter, ...) is now a CDI beans with a connection to its bus and interceptors. I know it can already be done by using a container initializer which gets beans injected and the instances directly passed to the addServlet() (instead of the class) but it would also be a very valuable addition to the module if the instantiation is reworked so I'm just mentionning it as an opportunity. [1] https://github.com/apache/tomee/blob/main/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/JavaeeInstanceManager.java > > The impact of fixing these for users should be non-existent: it is > really a Tomcat standalone only thing impacting users with some very > precise EE needs. A full EE integration will simply take over the > whole annotation processing and instance manager from Tomcat, and > hopefully do The Right Thing already. > > Although this is not super critical, I plan to address these issues in > the OWB integration (after adding the needed API change in Tomcat's > DefaultInstanceManager). > > Comments ? > > Rémy > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org > >