0

Working with JBoss Fuse, I have a Camel-FOP endpoint component that successfully generates PDFs as part of a route. A new requirement is to include dynamic barcode generation in the PDF output. This must run in the OSGi container. While both FOP and Barcode4J are bundles, the FOP Extension (barcode4j-fop-ext:21) is just a plain jar and no bundle version seems to be available.

I first tried to wrap the FOP extension via bnd and deployed it, however FOP does not find/see the extension. The way this works is that at runtime FOP looks for any text files named org.apache.fop.fo.ElementMapping supplied by optional extensions in the classpath. FOP then dynamically instantiates a class in the extension Jar using the class name provided within that text file - class.forName(...).

The FOP Extension Jar keeps the plain text files under META_INF/services which must be visible to the FOP bundle, as well as several Java packages in the Extension Jar. This text file contains the string "org.krysalis.barcode4j.fop.BarcodeElementMapping" that corresponds to the class within the FOP Extension that the FOP bundle must instantiate.

EDIT: I should add also that I've looked at the FOP bundle manifest, and there is no optional import or other reference to the FOP Extension Jar I'm using. The idea with the extensions I think is that they are runtime discoverable, and thus not implicitly referred to.

Is there any way to get this to work in OSGi, or should I be looking at other solutions?

Gerry Mantha
  • 1,068
  • 7
  • 14
  • I would not assume it would be easy to do if that FOP extension does not support OSGi in any good way. You can try turn on dynamic import on the camel-fop and fop bundles, in Karaf there is a command for that dev-dynamic-import or something like that. – Claus Ibsen May 05 '17 at 19:54
  • Couldn't you simply wrap the non-osgi jar and let Karaf create the bundle for you? http://stackoverflow.com/questions/32889600/install-depency-jar-file-in-apache-karaf-2-3-10 – Souciance Eqdam Rashti May 08 '17 at 06:36

1 Answers1

1

Sounds like your FOP is looking for service extensions. Make sure you also have the Aries SPI-Fly feature installed. This feature looks for those service extensions META-INF/services and makes those available to other bundles requiring those extensions. That should already do most of the work for you.

Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22