Hello.
I'm tracing this through to try and understand why Jersey Servlet Initializer is not invoked for a pure Jaxrs applications running in Karaf 4.3.0.
It appears the way that the ServletContainerInitializerScanner in the pax-web-api has a fundamental design flaw when it searches bundles for instances of the /META-INF/services/ ServletContainerInitializerScanner file. Namely that it only searches dependent bundles of the one that is being initialised. As the implementation of any service is meant to be hidden by the API, it means that you will never be able to initialise any web servlet. As such the pax-jetty-web adds the bodge of wiring-in itself to all web-context so its contextInitializer code can be discovered, but no other implementations.
Rather than performing a bundle scan each time, surely jetty should be implementing the bundle listener pattern and have the set of servlet initializers that are available in the platform? Or am I missing something?
Cheers,
Paul
A WAB can optionally contain a web.xml resource to specify additional configuration. This web.xml must be found with the Bundle findEntries method at the path WEB-INF/web.xml. The findEntries method includes fragments, allowing the web.xml to be provided by a fragment.
Unlike a WAR, a WAB is not constrained to package classes and code resources in the WEB-INF/classes directory or dependent JARs in WEB-INF/lib/ only. These entries can be packaged in any way that's valid for an OSGi bundle as long as such directories and JARs are part of bundle class path as set with the Bundle-ClassPath header and any attached fragments. JARs that are specified in the Bundle-ClassPath header are treated like JARs in the WEB-INF/lib/ directory of the Servlet specification. Similarly, any directory that is part of the Bundle-ClassPath header is treated like WEB-INF/classes directory of the Servlet specification.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/e9d0b4ab-33d7-4895-8a0f-e6d55e3e3b43n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhqcqH3h1bhJhYLb1%2B08u3dcSzFE%2BEYpe%2B62O7CbmMZHGQ%40mail.gmail.com.
Thanks Grzegorz. I know what you mean about doing my "normal job", I also have be careful as to what can be shared to the community.I realise that the ServiceLoader is a bit of a problem and I've already had to alter other standard services to be bundle-aware. Which is why I think implementing a Bundle Listener could be a better approach for the SCI's.I'm out of the office for a couple of weeks so I'm going to look prototyping a solution when I get back.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/720b9929-0a4d-4ab6-aaca-52e4bc55bc7b%40googlemail.com.
You received this message because you are subscribed to a topic in the Google Groups "OPS4J" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ops4j/hmpbC3-vM6I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/a2363134-86ad-40e9-869b-36885ac68083n%40googlegroups.com.
Paul--You might checkout a BundleTracker. A BundleTracker is ensured to get a callback for every bundle, regardless as to when your bundle started. With a BundleListener, there is a race condition that you may not be activated before some bundles that you care about.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/a2363134-86ad-40e9-869b-36885ac68083n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhpRfntRwzx2oykWjf56AJtWPH2nFD59dfLBFWLO5NpCJA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/0ba73d25-16c8-4ac6-8bfd-ad9404c56664%40googlemail.com.
Hi Grzegorz,Sorry about the delay in getting back to you.I realise your concerns about sci's from different webapps interfering with each other. However the SCI mechanism appears to be the way that the other web technologies, such as JAXRS and SpringMVC have a chance to detect and influence the creation of the servlet.
Given that ServiceLoader architecture is being used, is it unreasonable that all possible instances for the SCI get asked to look at the bundle and initialize the context is appropriate?
If not, then we need another way to extend the WebExtender with other web frameworks, allowing them to get involved with servlet creation. Which does not include altering the webapp in some OSGI specific way.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/0ba73d25-16c8-4ac6-8bfd-ad9404c56664%40googlemail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhpYfC1xBd2%3DXEGjHjut8wAb1rCc6GYmP%2B2PqTk6rLy%3DKQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAB8EV3RwOvyXww2f_FaMwrjiAg%2BDKTvcAEdWeOV%2BJC2rCF0F_Q%40mail.gmail.com.
Thanks Grzegorz,I'll have a more detailed look at this when I get back next week.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/38587571-05a7-4043-a381-f0a7ac6d50fb%40googlemail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/CAAdXmhoVf7%3DeU_8E-AazwxR9UvT1b01BameHfx3d2wKJD6GGKw%40mail.gmail.com.
Hello,
My initial issue was that pure JAXRS WABs fail to bootstrap karaf, where as they work as documented when deployed into the OSGi side of Glassfish. Glassfish may be a JakartaEE platform, but essentiality it is an OSGI framework running on Felix. Therefore, felix should also support the concept of dropping annotated applications into the framework that will be picked up and initialised by the relevant extender.
This process is complicated by the fact that JAXRS services are web applications that are bootstrapped by a method described in the Servlet 3 specification. This is achieved by the appropriate technology (i.e. CXF or Jersey) providing a ServletContainerInitializer that allows the service to examine application and decided if further action is required.
As discussed previously the ServletContainerInitializer's are discovered through the use of the Java Util ServiceLoader service. This means that the META-INF/services file needs to be visible and creatable by the application's class loader. Or via some other means, e.g. servlet, jsp and jsf implementations are supported by the pax-web-extender specifically wiring in the appropriate class loaders during the web context initialisation process.
As such I've been trying to understand how Glassfish achieved something similar in a felix container, without the need for the application to specify either the Jersey implementation or the auxiliary library that contained the SCI.
It turns out that GF is using a couple of tricks to construct a common classloader at runtime which contains dependencies on all bundles that offer services through the ServiceLoader framework. This is then used as the parent classloader when bootstrapping web and other types of services, thus decoupling the web framework implementation from the applications that use it.
Personally I like this approach as it allows our framework engineer to maintain the platforms separately from application developers who only need be concerned with the business logic. Thus if we want to upgrade or change the implementation of a particular technology (e.g. JAXRS, Spring, JPA, XML/JSON Binding, etc…) then we can without the need to rebuild all of the applications that use it.
As a demo I have extended the ServletContainerInitializerScanner in the pax-web-api to track bundles that provide the SCI via the service loader file. These are then returned to the JettyServerWrapper when it is creating the HttpServiceContext. The result is that JAXRS, WebSocket and Spring MVC applications are all correctly initialised without the need to hard code a specific implementation into the business logic bundles.
I realise that bootstrapping services like this does not conform to the class loading concepts of the OSGI specification, however it does make Karaf more flexible when used as a service platform. As such, I believe that we should consider adding the option of a SCI Bundle Extender to the pax web offering.
Regards
Paul
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/629e8714-e364-4893-8e63-5b4291abca0an%40googlegroups.com.
Not sure if it already was mentioned, but OSGi provides already a way to
interact with Java-SPI through the Service Loader Mediator Specification
[1].
[1] https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/bec95850-92c9-6bb9-3e16-bf419cbdd7c6%40googlemail.com.
Thanks Christoph, I did something similar in my demo, where I used a bundle tracker in the api-web-api to return a list of SCIs. This worked for my scenario in that it located and invoked the Jersey SCI that was deployed in a support bundle. However as discussed in this thread, it isn’t really how services should be discovered in an OSGI environment.
We do have the option to use the “OSGi ServiceLoader Mediator”(aka SPI-FLY) as pointed out above. But I'm not a fan of needing to repackage bundles, to inject the capability headers to both the implementation and the client when you already have this information inside the bundle. So I guess we’re back to using bespoke extenders.
Also described in this thread, is the current work that Grzegorz is doing on pax-web version 8. I’ve had a brief look at the code and he has reworked the SCI discovery mechanism. I’ve yet to fully understand what he has done, but I believe that it keeps to the principle of only instancing SCI’s that are visible to the bundle. e.g. the dependencies of the WAB and pax-web bundles. As such any bespoke solution may need to be reworked for the next revision of pax-web.
Thanks for your input.
Paul
OPS4J - http://www.ops4j.org - op...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/b11af7e2-acf0-1fad-75c1-086dd1095af2%40googlemail.com.