Moving Camel Application Between OSGi and JavaEE Containers in Fuse

DZone 's Guide to

Moving Camel Application Between OSGi and JavaEE Containers in Fuse

Here's a method for moving applications from OSGi to JavaEE containers and vice versa.

· Integration Zone ·
Free Resource

Now that JBoss Fuse supports both OSGi Karaf and JavaEE JBoss EAP container. When should you use each? Is there any best practice for which container to use? It depends .... Situations vary between cases. Here are my point of view, you many like it or disagree, but I am happy to hear more of your thoughts.

I think it is BEST if you stick with Karaf containers if possible, for now. It is more lightweight, which means you can deploy applications much quicker and scale faster horizontally with applications distributed everywhere. OSGi manages the lifecycle of the services and allows you to dynamically deploy and undeploy services without affecting the others services in the same container. That is very important in for mission critical services. So if you can choose, go with Karaf.

I also think that an enterprise should not be restricted to using a single kind of container. Different container frameworks exist for a reason. Especially if you are providing a web application with EJB, JARs, and complex application glue to serve as the core business for the web application. Maybe it's a legacy application that has everything done in the Application server. Or it simply has too many non-OSGi compatible libraries to work with. Then I would go for the JBoss EAP scenario.

So how do you move from OSGi to JavaEE containers or vice versa? Moving a bundle from OSGi to JavaEE is dead simple. But please note, use the Spring framework instead of Blueprint if you are using OSGi, I would first convert it to Spring then work with it.

In this case, I will be using a WAR application, since most people use this format in JavaEE and it is supported in Karaf as well.

So there are few ground rules if you want to switch back and forth between the containers:

  • Use Spring Framework
  • Make sure your Camel route is placed under META-INF under webapp and named *-camel-context.xml

  • Set your plugins to generate the metadata needed for OSGi containers.
    • Add maven-bundle-plugin        

By sticking with these rules, it will allow you to create a project that can deploy on both containers.

In the JBoss Fuse Karaf Container,

  • Install with Profile or using an OSGi command
    • war:mvn:com.redhat/springtest/1.0.0-SNAPSHOT/war?Web-ContextPath=springtest
  • Make sure to have feature-fabric-web profile in your container

Running JBoss EAP Container with Fuse application.

  • Deploy and install by
    • Drag and dropping the WAR file under the deployment folder
    • Using Console/CLI deployment
  • Make sure the Fuse subsystem is installed and activated. 
  • Remember to disable ContextLoaderListener in web.xml

Here is a video showing how to move an application between containers.

containers, java ee, jboss, osgi, spring, war

Published at DZone with permission of Christina Lin , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}