The WSO2 Carbon platform supports OSGi JRE SPI mechanisms by integrating ‘Apache Aries SPI Fly’, which provides OSGi support for JRE SPI mechanisms, including the usage of java.util.ServiceLoader, META-INF/services and similar methods. Developers can integrate Apache Aries SPI-Fly support by adding the relevant bundles to the
<AS_HOME>/repository/components/dropins/ directory as explained below. Since the Carbon Runtime is higher than the OSGi 4.3 compliant framework that supports WeavingHooks, we can use either Dynamic or Static weaving in the Application Server.
The following steps explain how SPI Fly support can be enabled for AS:
- Copy the relevant bundles from Apache Aries to the
<AS_HOME>/repository/components/dropinsdirectory. The bundles you should copy depend on whether Dynamic weaving or Static weaving should be enabled as explained below.
For Dynamic weaving, copy the following bundles:
SPI Fly Dynamic Weaving Bundle
For Static weaving, copy the following bundles:
SPI Fly Static Weaving Bundle
- Aries Util
These bundles will provide the necessary support for SPI Fly. Along with them, you can apply your SPI providers and consumers to the
If Static weaving is used, it is necessary to process the consumer bundles before the provider bundles. You can do this by executing the following command on a command line:
This command will change the bytecode of the bundle so that static weaving can be used at runtime. Note that the following tool is used in the above command:
Start the server.
Check the console logs and you will observe the logs from the consumer bundle that invoked the SPI.
See the Apache Aries documentation for samples and more information.