I'm trying to make my servlet extendable with OSGI bundles: newly added bundles must be a servlets as well. There is a Servlet Bridge feature provided by Felix http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html, looks very nice for me but I got some problems during its setup. As Felix web page says, in order to to setup servlet bridge we need to do:
- Deploy org.apache.felix.http.proxy jar file inside the web application (WEB-INF/lib); [DONE]
- in a startup listener (like ServletContextListener) set the BundleContext as a servlet context attribute [DONE]
- define org.apache.felix.http.proxy.ProxyServlet inside your web.xml and register it to serve on all requests [DONE]
- define org.apache.felix.http.proxy.ProxyListener as a in your web.xml to allow HTTP session related events to be forwarded [DONE]
- be sure to add javax.servlet;javax.servlet.http;version=2.6 to OSGi system packages [not obligatory]
- deploy org.apache.felix.http.bridge (or org.apache.felix.http.bundle) inside the OSGi framework [????]
Step No 6 seems to be not enough to make servlet bridge workning in my case. I made all steps 1-5 for my bundle servlet. My main servlet has OSGI embedded mechanism, so I deploy my bundles from the java code. This is a piece of code of OSGI launcher:
Map m = new HashMap();
m.putAll(System.getProperties());
m.put(Constants.FRAMEWORK_STORAGE_CLEAN, "onFirstInit");
m.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.service.http");
fwk = getFrameworkFactory().newFramework(m);
fwk.start();
// Install bundle JAR files and remember the bundle objects.
BundleContext ctxt = fwk.getBundleContext();
for (int i = 0; i < jars.size(); i++) {
Bundle b = ctxt.installBundle(((File) jars.get(i)).toURI().toString());
bundleList.add(b);
}
// Start all installed non-fragment bundles.
for (int i = 0; i < bundleList.size(); i++) {
if (!isFragment((Bundle) bundleList.get(i))) {
((Bundle) bundleList.get(i)).start();
}
}
From the main servlet code I install required org.apache.felix.http.bridge
bundle, some dependencies for my servlet bundle (slf4j, javax.servlet...) and my servlet bundle that I've made following steps 1-5.
Deployment result: no HttpService available for Servlet Bundle - it means that I can't use it in my application cause no way to register any Servlet instances in my servlet bundle.
Looking at MANIFEST.MF of org.apache.felix.http.bridge
I didn't find any mention like Export-Service: org.osgi.service.http.HttpService
How do I need to use this bundle? How do I need to setup servlet bridge?