How to specify system package exports in pax exam - osgi

Pax exam is used to test Apache CXF Distributed OSGi. I recently updated to apache felix 4.2.1. In the newer version of felix I get problems with packages exported by cxf spec bundles and the system bundle. No idea why this did not occur with the older felix 3.x.
For the distribution we control this in the felix config (see the config template we use)
There we use the "org.osgi.framework.system.packages" property to define the system package exports.
How can I do the same using pax exam. I know how to do this using karaf exam but it can not be used as we want to explicitly test against pure felix.
I already tested CoreOptions.systemPackage but it only allows to add exports not to redefine them.

Pax Exam 3
Option[] conf = options(
systemProperty("org.osgi.framework.startlevel.beginning").value("4"),
systemPackages(
"com.ibm.uvm.tools",
"com.sun.jdmk.comm",
"sun.misc",
"javax.jmdns",
"javax.microedition.io",
"javax.servlet.http",
"javax.persistence",
"javax.servlet",
"javax.net.ssl",
"javax.jms",
"javax.mail",
"javax.mail.internet",
"javax.mail.util"),
...);
Regards
Roland

Got an answer from the ops4j list:
CoreOptions.frameworkProperty("org.osgi.framework.system.packages").value(sysPackages)
The option works on Eclipse Equinox but not on Apache Felix.

Related

Apache felix cannot load dbcp2 as bundle

I have created an OSGi bundle, that is using apache commons dbcp2 to create a database connection pool. I am using apache felix gogo as runtime to start my bundles. I have loaded multiple other external libraries without any problems into the apache felix:
Image here (cant post no rep):
https://i.gyazo.com/c779ccaba20e3fa327d61a621748d8dc.png
However every time I try to start dbcp2 bundle which is requiered in my bundle I get the following error:
Image here (cant post no rep):
https://i.gyazo.com/ac7b673e63b9e6ad764af2e6adddb19a.png
I have found that there is some Apache mixservice bundle available, but it contains dbcp 1.4 and I need dbcp 2.5.0 or higher.
What needs to be done so apache felix is able to load the dbcp2 as a library requiered by other projects ?
What you see in the error is that the dbcp bundle requires the javax.transaction package in version >= 1.1.0. This is not an error in the bundle. It just means that you need to provide this package in the OSGi container.
Normally you would install a bundle that provides the package. In this case the package comes from the jre and the system bundle should export it.
Depending on how you start felix the way to export a system package is different.
For example if you use bndtools you do this in a bndrun file. See the Enroute microsevice example.
For plain felix see the parameter "org.osgi.framework.system.packages.extra".
In this example the javax.transaction package is exported (among some others).

Equivalent of feature:repo-add and feature:install in Apache Felix

I am familiar of feature:repo-add and feature:install in Karaf. I am looking for similar thing in Apache Felix or any alternate way to do the same.
If you want to deploy on plain felix without karaf then I recommend using the bnd packaging.
It is used in the enroute tutorials (you need to switch to felix as they use equinox by default). You give it a repository of the bundles to draw from (pom file) and a bndrun file. The output is a runnable jar with all bundles and felix included. When looking at the bndrun ignore the runbundles .. you do not have to write them. Threy are automatically generated.
When deciding between karaf and bnd packaging keep in mind that you do not have the pre defined features of karaf. So finding the set of bundles for the repo is a bit more work. You can use the list of bundles from the karaf features you use as a good starting point.
See https://github.com/osgi/osgi.enroute/tree/master/examples/quickstart/app

CXF - ClassCastException (SEIStub/ClientProxy) in Equinox

I am getting following exception inside Equinox OSGI :
Getting java.lang.ClassCastException: com.sun.xml.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy
Please advise.
It looks like you accidently use the jax-ws stack that is part of the jdk instead of CXF. I guess the reason is an incorrect deployment of CXF in your OSGi runtime.
You will need to not export the jax-ws API packages from the framework and instead install the jax-ws API from servicemix bundles. You can try to install Apache CXF in Apache Karaf to see how the correct deployment should look like.
To set the packages to be exported by the framework use the framework property org.osgi.framework.system.packages. See also Apache Felix configuration. Unfortunately there is no option to remove a package from the exported packages. If you use this option then you need to specify all packages that the framework exports. The default can be found in the felix jar in a property file default.properties.

how to make camel-example-cxf-proxy work in serviceMix 4.3.0

I downloaded camel 2.6.0 and used example camel-example-cxf-proxy (under example folder) to deploy into serviceMix.
what i would like to do is packaging it to become a jar file and then goto serviceMix karaf console to install this jar.
(install -s wrap:file:/c:/...jar)
But this example doesn't work in serviceMix 4.3.0.
Do you know what thing i have to modify to make it work within serviceMix 4.3.0
Do i have to install any other bundle into serviceMix?
The first thing is that you should make sure your maven project builds a bundle. I recently did a tutorial that shows how to run camel routes in OSGi:
http://www.liquid-reality.de/display/liquid/2012/01/03/Karaf+Tutorial+Part+5+-+Running+Apache+Camel+integrations+in+OSGi
So basically you have to make sure that the camel features you need are installed. In your case this is probably camel-cxf and camel-http.
Then you need to change the pom to create a bundle. See the pom of the example:
https://github.com/cschneider/Karaf-Tutorial/blob/master/camel/jms2rest/pom.xml
You need to change the packaging to bundle and add the maven bundle plugin. For camel projects the default typically work very well.
Btw. you can also run camel on pure karaf when you follow the instructions in my tutorial. This has the advantage that you can almost always use the newest camel version while servicemix often comes with an older version.

Karaf development

Im currently develop bundles for karaf and have some questions...
I wrote a bundle/webservice based on cxf, I try to deploy it in karaf but it could not start that bundle because it could not resolve some packages e.g.
org.osgi.framework.BundleException: Unresolved constraint in bundle org.springframework.aop [56]: Unable to resolve 56.0: missing
requirement [56.0] package; (&(package=org.aopalliance.aop)(version>=1.0.0)(!(version>=2.0.0)))
so here is a question, this package dependency comes from spring-aop (3.1.0.RELEASE), so where is the problem? what dependency is missing? how can I solve such problems?
In that case i did not clearly understand the development process. should i deploy all missing bundles in deploy? because i would like to keep thirdparty libs spereated from my developed bundles. And what bundles i have to deploy? Is it a trial and error process? Is there a common way to let maven do the dependency stuff?
I discovered a folder "system" and read on the docu that it is a repository like maven, is it for the features?
I had for test cases a karaf with some pre deployed bundles and put my webservice bundle into it, but again execeptions...
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
What dependency is missing?
I already read the tutorial about camel and karaf, but it did not explain the deployment stuff, so could anyone suggest me a good tutorial?
Thanks!
Chris
Short answer
Scroll down to the bit referring to "camel-cxf" and run the two commands features:addurl and features:install. I have a feeling this will resolve all your problems.
spring-aop
On Karaf console type:
exports | grep org.aopalliance.aop
I think you'll see lines like:
XX org.aopalliance.aop; version=3.1.0.RELEASE
So while the spring-aop bundle has the right packages they're the wrong version, the range being requested is >=1.0.0 and <2.0.0, so 3.1.0 doesn't satisfy that.
Deploying/Installing
You can drop bundles into ${karaf.home}/deploy or use the console.
You can install maven bundles from the Karaf console with:
install -s mvn:groupId/artifactId/version/packaging/classifier
Where -s starts the bundle and packaging/classifier are optional.
You can find a lot of OSGi ready maven dependencies here http://ebr.springsource.com/repository/app/ - I had a quick look but your spring aop dependency is very old, what version of CXF are you using?
Read up about Karaf features - they're basically XML files that list suites of bundles that can be installed. Very useful for deploying large numbers of bundles and they can be installed into a maven repository.
There are some standard features available in Karaf, try:
features:install war
This will give you a jetty webcontainer and may resolve your ClassNotFoundException: javax.servlet.http.HttpServlet as long as it's the right version
Camel also has a features file which probably sort all your issues, try this:
features:addurl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install camel-cxf
Tutorials
There's quite a bit available, some on http://karaf.apache.org and http://fusesource.com but also take a look at the PDF manual that comes in the Karaf distribution.
Always beware that info may be out-of-date
Please post your MANIFEST.MF file. I think you didn't not mention the tag in maven-bundle-plugin dependency.

Resources