Question

We have a problem with conflicting HttpServices in our OSGi system based on Apache Karaf embedded in a web application running in Tomcat.

Some parts of our application are non-OSGi based and respond to requests directly through code in our WAR, and some parts respond to requests by using the Felix Servlet Bridge to call servlets in the Felix OSGi container. We are also using Felix's whiteboard bundle to achieve automatic registration of servlets.

We are also using the ActiveMQ feature in Karaf, and it includes Pax Web for its console. The result is that we end up with one HttpService from the Felix Servlet Bridge, that integrates with the embedding application server, and one HttpService from Pax Web, that runs its own Jetty server on a different port.

So, the problem is that the whiteboard bundle on some startups connect to the Pax Web HttpService and thus exposes our servlets in the wrong place. We haven't found a way to configure the whiteboard bundle to somehow ask for the desired HttpService from Servlet Bridge, and as all involved bundles are third-party stuff, we'd like to avoid changing their Java code as well...

What's the best way to solve this?

(We'd prefer configuration over code for maintainability and we want to keep the ActiveMQ console on its own port)

Was it helpful?

Solution

It sounds like a curious (and rather wasteful) setup to run in an app server and then run another web server inside ... Guess you have your reasons for this self inflicted complexity :-)

The first and easiest solution is probably to not use the whiteboard and use Declarative Services references and then just register with the given http service. Then you can use Config Admin to set the target filter for the Http Service reference. Alternatively, you can just register at all Http Services.

Second solution is to fix the Apache Felix Whiteboard service, allow it to be configured to all Http Services or a specific one through Config Admin. You can also make your own whiteboard bundle, it is a very small bundle and quite trivial, especially with DS. Please donate it (back) to Apache Felix if you do.

Third solution is to use Service Hooks and ensure that the Whiteboard bundle only sees the correct Http Service. Again use Config Admin for configuring such a bundle. A bit hackish though.

Fourth solution, let ActiveMQ run in a separate framework and export its service(s) to the client framework. Not sure if this is feasible, works in general very well with service oriented bundles. This could use OSGi subsystems but not sure how far along the implementations are for this is.

Last solution, would be my preference, get rid of the problem and let the ActiveMQ run on the bridge web server under a properly protected path or alternatively use Jetty as your web server and skip Tomcat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top