OSGi Fragment connection to a bundle - internationalization

I want to create a Fragment which will connect to a bundle living in an OSGi container.
I cannot find any documentation about the content of each Manifest.MF files for both sides (Fragment and Bundle).
Can anyone give me a good example in order to fully understand it.
A source code example it will be the best.
Thanks

If the host bundle has the following in its manifest:
Bundle-SymbolicName: org.example.myhostbundle
Bundle-Version: 1.0.0
then the fragment should have:
Bundle-SymbolicName: org.example.myfragment
Fragment-Host: org.example.myhostbundle; bundle-version="[1.0,1.1)"
Please see the OSGi wiki page for more detailed information.

Related

How to use a third-party component in a modular way in Liferay?

I wrote a Liferay 7 module that uses org.apache.http.client.methods.HttpPost.
So I downloaded the httpclient-osgi JAR and put it in deploy/, but when I try to start it I get:
org.osgi.framework.BundleException: Could not resolve module: org.apache.httpcomponents.httpclient [1088]
Unresolved requirement: Import-Package: org.apache.http; version="[4.4.0,4.5.0)"
So I searched mvnrepository.com for org.apache.http.
PROBLEM: No such component seems to exist.
Do I have no other option than including the classes inside my Liferay module?
Doing so sounds contrary to the OSGi principles: if my 100 Liferay modules use httpclient then including httpclient in each of them does not sound very modular.
Am I thinking the wrong way?
How to use a third-party component in a modular way in Liferay?
What you are searching for is a package name not a jar name.
Apache httpclient needs httpcore.
These bundles are known to work well together:
mvn:org.apache.httpcomponents/httpclient-osgi/4.5.3
mvn:org.apache.httpcomponents/httpcore-osgi/4.4.6
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient-osgi/4.5.3
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore-osgi/4.4.6

How can I run OSGi blueprint in Felix in Scala?

I am able to get OSGi blueprint to work in Karaf, but I don't understand how to do it in Apache Felix, or my question can be also defined as how can I use OSGi blueprint in plain OSGi?
I made an example here https://github.com/PhilAndrew/sbt-osgi-felix-akka-blueprint-camel using https://github.com/doolse/sbt-osgi-felix in which Akka is working but Blueprint and Camel not yet working.
This question may help Is Apache Aries running in Felix?
It's not starting Blueprint because your bundle's code doesn't actually rely on any of the classes in blueprint, so you either need to add "Require-Bundle" header to your manifest:
requireBundle := Seq("org.apache.aries.blueprint")
or add the bundles that needed to be started to the osgiDependencies of run:
osgiDependencies in run := bundleReqs("org.apache.aries.blueprint.core",
"org.apache.aries.proxy")
Apache Karaf also runs on felix. So for the most part you just need to install the correct bundles and maybe do the necessary system package exports if you hit package use constraint violations.
Check what karaf installs and try to do the same.

Do I need to create seperate OSGi bundles for each jar

I want to create an OSGi bundle for log4j2. I need to use some additional jars along with log4j2 such as log4j2-jcl, log4j2-jul, log4j2-web etc. I want to clarify some confusions listed below about this.
However this is not specific to log4j2 I'm asking this as a general procedure.
Do I need to create separate OSGi bundles for each jar or can I use one bundle for all the jars? (What is the best practice)
How can I know whether OSGi bundles are already available for these jars ? (So that I don't need to re create bundles, can use existing ones)
I'm quite new to OSGi so can anyone please clarify these things no need to specific for log4j2.
Thanks!
Do I need to create separate OSGi bundles for each jar or can I use one bundle for all the jars? (What is the best practice)
I recommend to create one bundle per JAR, if possible. This gives you the greatest flexibility and makes sure that each JAR is properly designed.
How can I know whether OSGi bundles are already available for these jars ? (So that I don't need to re create bundles, can use
existing ones)
Just have a look at the Manifest file.
If it contains the OSGi Metadata -> it's a OSGi bundle.
If it doesn't contain the OSGi Metadata -> it's not a OSGi bundle.
I think the Log4J JARs already provide the OSGi Metadata (-> they are already bundles), but I haven't double-checked.
just a recommendation.
before you do any bundle, check if it exists.
https://jpm4j.org/#!/search?q=log4j2
also, I recommend slf4j

How to get extra attributes in "resource" element of an OBR repository?

We try to get Apache Felix Web Console OBR plugin working with OBR repos produced by the current BND Tools/Bindex.
The problem is that the generated repositories (for example, produced with "Release Bundles" from Eclipse) cannot be read by the Felix Web plugin.
To the contrary, the Felix' own OBR repository is properly understood by the plug-in, since it seems to have additional attributes within the "resource" element, which are missing in our repository:
...
<resource
id="org.apache.felix.bundlerepository/1.4.1"
symbolicname="org.apache.felix.bundlerepository"
presentationname="Apache Felix Bundle Repository"
uri="http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.bundlerepository/1.4.1/org.apache.felix.bundlerepository-1.4.1.jar"
version="1.4.1">
...
The schema specification in http://www.osgi.org/download/rfc-0112_BundleRepository.pdf leaves the room for the attributes within the "resource" XML element, however they are defined as a part of Java API.
This gitHub fork seems to do the job https://github.com/rkrzewski/bindex but does anybody know what is the status of this? Will this be integrated to Bindex some day? UPDATE: here is the answer from RafaƂ, this forks' owner https://github.com/rkrzewski/bindex/issues/3#issuecomment-27784279
So, I have reasked on bndtools-users Google group: https://groups.google.com/forum/#!topic/bndtools-users/ZdY0ASnLNmc
Or are there any other ways to get the OBR repos be generated with the missing resource attributes? Thanks.
The development of Bindex moved to https://github.com/bndtools/bindex.
(source: https://groups.google.com/d/msg/bndtools-users/R3U2SDazTjY/OyOVTK8DZHUJ)
Does this version create the proper format for you?

What is strict class loading?

I am learning osgi framework. It says osgi works on strict class loading environment. I am unable to get what is Strict ClassLoading. Please help i am unable to get the concept
Thanks
Strict classloading means that a module (bundle) has to explicitly specify what it needs. In OSGi this is done using Manifest headers. Import-Package lists the packages and their version ranges the bundle needs and Export-Package lists the packages and their versions the bundle offers. In the OSGi runtime you then have a classloader per bundle that wires the bundles according to the exports and imports.
You should not define these headers by hand though. There is a nice tool named bnd or in maven the maven bundle plugin from felix which does most of the work for you. In this tutorial you find how this works in practice:
http://www.liquid-reality.de/x/DIBZ
You will see that I actually do not define to much by hand there. So build the code and into the meta-inf/Manifest to see what it does.
strict class loading environment means that the appropriate headers of the class need to be specified. for example the class path and the import-package

Resources