>>>>> Steinar Bang <s...@dod.no>:

> Aries Spifly was logging very little, so it was hard to debug.
> Figuring out where the log level should be upped, turned out to be
> surprisingly easy, however...
>  
> https://github.com/apache/karaf/blob/main/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.logging.cfg#L51

I now have some success: I created a DS component that listens for the
OSGi services created by Aries spyfly, from the Twelvemonkeys SPI
services, and registers the injected services with the imageio
ServiceRegistry. 

The full strory follows:

Logging told me that the SPI services were found by spifly:
 
https://gist.github.com/steinarb/6dd2b87cca74f483c560abd3f05868e2#file-karaf-log-L408

However imageio still picked the built-in 
com.sun.imageio.plugins.jpeg.JPEGImageReader
to read a JPEG (JFIF) file:
 
https://gist.github.com/steinarb/6dd2b87cca74f483c560abd3f05868e2#file-karaf-log-L478

It turns out there is no magic in Aries Spifly that makes it find the
SPI registry that listens for SPI services and register the service
there.

I tried using the Spifly-specific MANIFEST.MF header SPI-Consumer to
specify a class and method to consume the SPI services.
 https://aries.apache.org/documentation/modules/spi-fly.html#specificconf

But I would need to go via two method calls to get to the one I need, ie.
 IIORegistry.getDefaultInstance().registerServiceProvider(service);

I tried doing it like this, but that didn't work
 SPI-Consumer: 
javax.imageio.spi.IIORegistry#getDefaultInstance#registerServiceProvider
and, not surprising, because I think the Spifly SPI-Consumer code only
provides for calling a method on a class.

If there had been a static method that could be called to register an
imageio service I think maybe the SPI-Consumer MANIFEST.MF header would
have worked...?

But since the spifly docs say: "Additionally services found in 
META-INF/services are registered in the OSGi Service Registry."
I decided to try a DS component that injects all Twelvemonkeys SPI
services as OSGi services and use them to register the service in the
imageio service registry:
 
https://github.com/steinarb/twelvemonkeys-karaf-demo/blob/master/src/main/java/no/priv/bang/demos/frontendkarafdemo/ImageioSpiRegistration.java#L12

And that worked. 
https://gist.github.com/steinarb/abb91df9447d00f73963f366fcc01771#file-karaf-log-L491

I don't know if this is the correct way to do imageio SPI service
registration, but it worked, so this is what I'm rolling with for now.

Reply via email to