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

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.

Related

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

Hawtio as an OSGI bundle

We have our own karaf based application and recently we decided to migrate our web console on hawtio as a plugin. Is there any possibility to append hawtio to our project as an OSGI bundle? i've downloaded hawtio project, but there is no maven module with packaging mode "bundle" or something like that. As an option of course we can get kar archive file, extract it and use its bundles. But that's not a native way at all. Thank you!
Hello have you try to use the latest Hawtio for karaf (hawtio-karaf) available on maven repository?
http://search.maven.org/#artifactdetails|io.hawt|hawtio-karaf|1.4.26|jar
It provide a features.xml that can be install on Karaf.
First: install everything on your local maven repo.
Second: launch your karaf.
Third: run the command: feature:repo-add mvn:io.hawt/hawtio-karaf/1.4.26/xml/features
Fourth: run the command: feature:install hawtio
According to the official website, the default URL is: http://localhost:8181/hawtio/
Let me know if it is working as you were expecting.
There is no clean solution for standalone unit testing, but apache karaf provides exam environment for such situations - http://karaf.apache.org/manual/latest/developers-guide/writing-tests.html
So we can run tests with our application and hawtio in dev mode.
On production this leak of functionality is absent.

How to work with frequent local snapshot bundle deployments on Karaf?

I decided to build an application on top of OSGI and Karaf - I really like this stuff. However, I'm struggling a bit with a daily deployment on my local, development machine. I mean.. I make a change and then I would like to test it on my local Karaf instance. And it can happen like couple times per hour.
The way I'm doing it now is a maven build that creates a JAR bundle and then it's copied into the Karaf's deploy directory. I think that it isn't elegant at all.
I was trying to find a way around (google). I read about Karaf's features but it seems that despite the fact that it is a nice mechanism for deploying whole app, it doesn't solve my problem. As I understand it right, it does not check whether new version of my SNAPSHOT jar appeared in my local maven repo, right?
The key to make the update mechanism of karaf work is to deploy from maven instead of using the deploy folder.
Install you bundle like this:
install -s mvn:groupid/artifactID/version
or
install -s mvn:groupid/artifactID/version/typeOfMavenArtifact
Second one is useful for installing for example war/wab artifacts. Full maven protocol specification can be found here.
Then Karaf knows where the bundle came from. You can also check this using la -u. This makes karaf show the update location which now should be a maven uri. You will not that all karaf bundles have an update location like this.
When you now create a new build of your project using maven it will end up in you local maven repository.
Then simply run
update <bundleid>
This makes karaf check the update location (in your case you local maven repo) and reload the bundle from there.
You can even further automate this by using
dev:watch
or for karaf 3+
bundle:watch
This will make karaf check you maven repo for changes in SNAPSHOT bundles it has deployed and automatically redeploy these.
This also works very well together with the remote debugging. Use
export KARAF_DEBUG=true
before starting karaf. It then will listen for a debugger on port 5005.
You can then start a remote debug eclipse session on the same port and nicely debug your application in karaf. This works very well even if you change your bundle using one of the approaches above. So you can debug, find your problem, change the code, build and continue debugging with the changed version.
I also use this frequently when I work at the karaf code base itself as this also works for most of karaf's own bundles.

How to deploy easily to Karaf Osgi container with maven project

I'm developing an OSGI bundle for parsing a PDF file using PDFBox library. I use maven to build the project and Karaf as the OSGI container. The PDFBox library is OSGI compatible so I thought this would be easy. But I just can't get the deployment model right.
In a traditional web app I would build a single WAR-file containing all the dependencies and put it in a Servlet container and it would get deployed. On the other hand the only way I've figured how to install an osgi bundle is by doing it by hand. I have to create an installation instruction file that lists all the dependencies that have to be manually downloaded and copied to the Karaf deploy folder, and be sure to do it in the right order. I feel like I'm back in the stone ages.
There has got to be an easier way, right? I still use maven to declare dependencies but I just have to use the provided scope. It would be great if those dependencies could be automatically installed.
I'm using the maven-bundle-plugin to generate a bundle from my application. It does generate an OBR repository(repository.xml) and I tried installing my bundle using obr karaf plugin but it still doesn't help with dependencies.
There are different possibilities for provisioning bundles. I prefer to install a bundle using Maven via the Karaf console such as:
install mvn:org.apache.pdfbox/pdfbox/1.8.4
If you don't want to install every bundle one by one, you could use so called features as described here. A feature lists all needed bundles:
<feature name='my-project' version='1.0.0'>
<feature version='2.4.0'>camel-spring</feature>
<bundle start-level='80' start='false'>mvn:com.mycompany.myproject/myproject-dao</bundle>
<bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-service</bundle>
<bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-camel-routing</bundle>
</feature>
You add a feature via Karaf console:
features:addUrl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.0.0-m2/xml/features
features:install nmr
Instead of the mvn handler, you could also use the file handler:
features:addUrl file:base/features/features.xml

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