How to deploy a Apache Camel Spring boot project in servicemix? - spring

I have a Spring Boot Apache Camel project. And now I wanted to deploy the same in servicemix. Can some one help me with the steps in deployment of the package which is generated as part of mvn goal.
From Camel examples I was able to get the answer. And the following is the example which helped me:
https://github.com/apache/camel/tree/master/examples/camel-example-osgi
But, the problem with this approach would be I will be need to publish my code to maven repository and installation will be happening from there. And the machine in which I run service mix does not have maven(we are not supposed to install maven)

You can deploy features or bundles from the file system using the file:// protocol as shown in this documentation: Servicemix provisioning
"Deploy bundles from file system without using Maven:
As we can use file:// as protocol handler to deploy bundles, you can use the following syntax to deploy bundles when they are
located in a directory which is not available using Maven"
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<feature name="spring-web" version="2.5.6.SEC01">
<bundle>file:base/bundles/spring-web-2.5.6.SEC01.jar</bundle>
</feature>
</features>

Related

Package and deploy OSGi bundles and Karaf features in Karaf Container

Recently, I have been working on Apache Karaf project.
The first one is a CXF REST service example and the second one is an Apache Karaf Maven example to run and deploy a Karaf container.
What I would like to do is to combine these two. The idea is to download a couple of JAR files from a repository and then package them into a Karaf.
Building Karaf Assembly manually then deploying the created JAR files in my deploy folder under Karaf is not a good idea if the task is reccurent each day. I would very much like to automate this if possible?
To achieve automatic deploy of Java project in Karaf, follow these steps:
Create a feature project: It is a Maven project and its goal is to create a descriptor of JAR (bundles) to be deployed under Karaf. The packaging of this Maven project is feature.
For your project of Karaf Assembly, add your feature as dependency and add it as boot feature so it can be installed when Karaf is up.
Look at this project https://github.com/benson-basis/karaf-feature-version-tc.
It has all the necessary configuration to automate Karaf building and deploy.

Spring Maven rest web service - What is the URL when deploying on real web server?

I followed this tutorial https://spring.io/guides/gs/rest-service/ by creating maven project in intellij, addind pom.xml etc. Then I run on localhost exactly as written in the tutorial and all works:
http://localhost:8080/greeting
When greeting came from the annotation of method in the controller #RequestMapping("/greeting").
Then I made JAR artifact & deployed it to Tomact on 'real server' (Elastic beanstalk environment running EC2 instance on AWS).
I got from AWS the base URL of my webserver running Tomact. What is now the suffix to my service? This is NOT working:
http://someEnvironmentName.elasticbeanstalk.com/greeting
EDIT: How I made the artifact JAR
In intellij I can compile & run maven project and then test it in localhost. So what I did:
Right click on the project name->Open Module Settings->Artifacts->Add->Jar
Build->Build Artifacts->Selecting the Jar from above
Maybe I need to build WAR? And how to deal with the POM.xml? Now my pom is exactly as in the linked tutorial.
Thanks,
If you use spring-boot, you donĀ“t need a tomcat because spring include an embedded tomcat. Only you run the application with Maven. So, the advantage of spring-boot is not dependent on an application server and using other containers such as Docker.
Do you put the port in the call to your webserver?
On the other hand, check your server logs to see if there are any problem.
Solution (Thanks to #JBNizet suggestion):
Follow this link http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
Modify the Application.java file
Modify the pom.xml (By adding one more dependency)
Then if you are using Intellij IDE under Build->Build Artifacts will be automatically option for WAR file.
Just deploy to AWS elasticbeanstalk instance running EC2 in the usual way. The URL is:
http://someEnvironmentName.elasticbeanstalk.com/greeting

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 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

How to install a bundle on boot in Karaf

I came across this post but it doesn't quite answer my question. I am using blueprint to set up a H2 database in Karaf and it requires that I first install H2 driver and OSGi enterprise package because it contains JDBC library.
install -s mvn:org.osgi/org.osgi.enterprise/4.2.0
install -s mvn:com.h2database/h2/1.3.174
I added the blueprint XML file to Karaf's deploy folder and it keeps giving error messages until I install H2 and enterprise package. Ideally, I would like to install both enterprise and H2 before the blueprint script kicks in, so I am thinking somehow add it to karaf's boot process but I am not sure how.
Any insights will be much appreciated.
One option would be to hot deploy a features XML before deploying your bundle.
See the Karaf deployer guide for more details. Here is an XML example:
<features>
<feature name="features_test">
<bundle>mvn:org.osgi/org.osgi.enterprise/4.2.0</bundle>
<bundle>mvn:com.h2database/h2/1.3.174</bundle>
</feature>
</features>
One way to achieve this is to publish the blueprint file to the maven repo. This way you can reference it in feature files. See the maven build helper plugin with goal attach artifacts. Many feature files are deployed tnis way.
You can also put your blueprint file into an ordinary bundle. Then it will also work in other containers than karaf.

Resources