Bug 57857 - Provide an OSGi bundle
Summary: Provide an OSGi bundle
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.12-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 53866 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-25 01:52 UTC by Nick Burch
Modified: 2020-10-02 11:44 UTC (History)
3 users (show)



Attachments
PAX-EXAM Patch (15.22 KB, patch)
2015-05-14 22:10 UTC, Bob Paulin
Details | Diff
ServiceMix patch (21.58 KB, patch)
2016-10-08 17:20 UTC, Andreas Beeker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Burch 2015-04-25 01:52:18 UTC
There seems to be increasing demand for an official OSGi bundle version of Apache POI. Some other Apache projects (eg ServiceMix) will sometimes produce their own copy, but not that often, which leaves our OSGi users on older versions or struggling themselves

Through the use of Apache Felix and friends, it ought to be fairly straightforward to build a bundle. Based on the Apache Tika OSGi bundle work of late, we can also include a unit test which checks that the bundle comes up and main parts of the API work
Comment 1 Nick Burch 2015-04-25 02:18:09 UTC
To try the work so far, you can use the "osgi" ant target, or you can build + install the maven poms locally with the "mvn-install" ant target then in the osgi directory run "mvn -Dpoi.version=3.12-beta2 install". However, it isn't yet working...
Comment 2 Bob Paulin 2015-04-26 15:40:50 UTC
So just as a quick experiment I did get the service mix 3.11 bundle running but it did take some toying around:

In the config I had to add:
org.osgi.framework.system.packages.extra=org.w3c.dom,org.w3c.dom.html,org.w3c.dom.traversal,org.w3c.dom.ranges,org.w3c.dom.views

This exposes the JRE classes to the osgi container.


Also below is the log out of the bundles that I had in play to get it to spin up.  The bundles I added are 1, 7-12,16.  
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.6.1)
    1|Active     |    1|Apache Commons Codec (1.9.0)
    2|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    3|Active     |    1|Apache Felix Configuration Admin Service (1.8.2)
    4|Active     |    1|Apache Felix Gogo Command (0.14.0)
    5|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    6|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    7|Active     |    1|Apache ServiceMix :: Bundles :: bcel (5.2.0.4)
    8|Active     |    1|Apache ServiceMix :: Bundles :: poi (3.11.0)
    9|Active     |    1|Apache ServiceMix :: Bundles :: xalan (2.7.1.4)
   10|Active     |    1|Apache ServiceMix :: Bundles :: xercesImpl (2.9.1.4)
   11|Active     |    1|Apache ServiceMix :: Bundles :: xmlresolver (1.2.0.5)
   12|Active     |    1|Apache ServiceMix :: Bundles :: xmlsec (1.4.3.3)
   13|Active     |    1|Apache Sling OSGi LogService Implementation (1.0.4)
   14|Active     |    1|OPS4J Pax Logging - API (1.8.2)
   15|Active     |    1|OPS4J Pax Logging - Log4j v2 (1.8.2)
   16|Active     |    1|Apache XML Security for Java (2.0.1)
Comment 3 Bob Paulin 2015-04-26 15:41:19 UTC
So just as a quick experiment I did get the service mix 3.11 bundle running but it did take some toying around:

In the config I had to add:
org.osgi.framework.system.packages.extra=org.w3c.dom,org.w3c.dom.html,org.w3c.dom.traversal,org.w3c.dom.ranges,org.w3c.dom.views

This exposes the JRE classes to the osgi container.


Also below is the log out of the bundles that I had in play to get it to spin up.  The bundles I added are 1, 7-12,16.  
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    0|System Bundle (4.6.1)
    1|Active     |    1|Apache Commons Codec (1.9.0)
    2|Active     |    1|Apache Felix Bundle Repository (2.0.2)
    3|Active     |    1|Apache Felix Configuration Admin Service (1.8.2)
    4|Active     |    1|Apache Felix Gogo Command (0.14.0)
    5|Active     |    1|Apache Felix Gogo Runtime (0.12.1)
    6|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    7|Active     |    1|Apache ServiceMix :: Bundles :: bcel (5.2.0.4)
    8|Active     |    1|Apache ServiceMix :: Bundles :: poi (3.11.0)
    9|Active     |    1|Apache ServiceMix :: Bundles :: xalan (2.7.1.4)
   10|Active     |    1|Apache ServiceMix :: Bundles :: xercesImpl (2.9.1.4)
   11|Active     |    1|Apache ServiceMix :: Bundles :: xmlresolver (1.2.0.5)
   12|Active     |    1|Apache ServiceMix :: Bundles :: xmlsec (1.4.3.3)
   13|Active     |    1|Apache Sling OSGi LogService Implementation (1.0.4)
   14|Active     |    1|OPS4J Pax Logging - API (1.8.2)
   15|Active     |    1|OPS4J Pax Logging - Log4j v2 (1.8.2)
   16|Active     |    1|Apache XML Security for Java (2.0.1)
Comment 4 Bob Paulin 2015-05-14 22:10:06 UTC
Created attachment 32736 [details]
PAX-EXAM Patch
Comment 5 Bob Paulin 2015-05-14 22:17:26 UTC
Attached is a Patch that sets up a PAX-Exam test for the POI bundle project.  The setup is based on the servicemix project work to configure the optional imports but I tried to keep the exports as minimal as possible.  The tests pass for 3.11 but not 3.12-beta2 because it appears that the org.etsi.uri.x01903.v14 and org.etsi.uri.x01903.v14.impl packages have been removed from the poi-ooxml-schemas jar at 3.12-beta2.  Either these packages need to be removed from the poi jar or they need to be added back into the poi-ooxml-schemas jar.
Comment 6 Dominik Stadler 2015-08-20 19:27:54 UTC
*** Bug 53866 has been marked as a duplicate of this bug. ***
Comment 7 Andreas Beeker 2016-10-08 17:20:05 UTC
Created attachment 34336 [details]
ServiceMix patch

This is a preliminary patch for Apache ServiceMix (i.e not for POI itself), which still needs to be tweaked when POI 3.16 comes out, which contains the fix for #60226

The tweak might contain additions like ...
- org.apache.xml.security.signature;resolution:=optional,


fyi - this is related to the SO issue [1]

[1] http://stackoverflow.com/questions/38791416/apache-poi-felix-xslf-table-is-empty
Comment 8 Yegor Kozlov 2020-09-16 16:06:59 UTC
I updated the OSGi POM to work with 5.0.0-SNAPSHOT, see https://svn.apache.org/repos/asf/poi/trunk/osgi/

The POI bundle is self-contained and can be used out of the box in a bare OSGi container, i.e. no other bundles are required. The  bundle exports all the POI classes, XML Beans, OOXML Schemas and required  dependencies. The current size is around 21 MB. 

## Embedded Dependencies
The bundle embeds all the jars from lib/main:

- SparseBitSet
- curvesapi
- commons-math3
- commons-compress
- commons-collections4
- commons-codec

## Optional Dependencies

1. Apache Batik
Required to render WMF/EMF images. The OSGi bundle is provided by ServiceMix and available in Maven Central: https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.batik/1.13_1
2. Saxon
Required if using as the XSLT and XQuery Processor engine in XML Beans.
Available in Maven Central: https://mvnrepository.com/artifact/net.sf.saxon/saxon/8.9.0.4-osgi
3. Apache XML Security for Java, Bouncy Castle and XML Commons Resolver 
These are required to sign or validate signed Office documents. The OSGi bundles are available in Maven Central:

    - Apache XML Security for Java: https://mvnrepository.com/artifact/org.apache.santuario/xmlsec/2.2.0
    
    - XML Commons Resolver: https://mvnrepository.com/artifact/xml-resolver/xml-resolver/1.2-osgi
    
    - Bouncy Castle: https://mvnrepository.com/artifact/org.bouncycastle/bcprov-ext-jdk15on/1.66, https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on/1.66

## Blocked Imports

These are not used and can be suppressed : 

Transitive dependencies from XML Beans not required by POI:

    - !com.github.javaparser.*,
    - !org.apache.tools.ant.*

Optional codecs pulled by  Commons-Compress. Not used by POI

    - !com.github.luben.zstd.*,
    - !org.tukaani.xz.*,
    - !org.brotli.dec.*,
    
Internal APIs which are no more in JPMS

    - !sun.misc.*


I tested the bundle in Apache Felix, Apache Sling (web framework running on Felix), Adobe AEM (Commercial version of Apache Sling ) and it worked fine for me. 
There is also a Pax Exam integration test running with the Apache Felix driver.
Comment 9 PJ Fanning 2020-09-16 17:11:25 UTC
the xmlbeans 5.0.0-SNAPSHOT uses a version of saxon that is more like 10.x
Comment 10 Yegor Kozlov 2020-10-02 11:44:11 UTC
The osgi bundle is in a good shape and this ticket can be finally closed out.
It turned out to be a bit more than just wrapping the POI classes. The bundle includes an Activator (https://svn.apache.org/repos/asf/poi/trunk/osgi/src/main/java/org/apache/poi/osgi/Activator.java) which registers services exported from the JPMS modules which otherwise would not load via ServiceLoader@load mechanism in OSGi.

I'd like to recommend it as a reference implementation and projects that wish to wrap POI into their own bundles should follow the pattern. 

For now poi-osgi is a separate maven sub-project which does not fit in the main Ant-driven build .