1
votes

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:

  1. Deploy org.apache.felix.http.proxy jar file inside the web application (WEB-INF/lib); [DONE]
  2. in a startup listener (like ServletContextListener) set the BundleContext as a servlet context attribute [DONE]
  3. define org.apache.felix.http.proxy.ProxyServlet inside your web.xml and register it to serve on all requests [DONE]
  4. define org.apache.felix.http.proxy.ProxyListener as a in your web.xml to allow HTTP session related events to be forwarded [DONE]
  5. be sure to add javax.servlet;javax.servlet.http;version=2.6 to OSGi system packages [not obligatory]
  6. 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?

1
Hi. Have you tried the example at github.com/apache/felix/tree/trunk/http/samples/bridge to see if that works for you?Sten Roger Sandvik
Sure, this example is about how to create a bundle for the servlet bridge. But my problem is about how to use this bundle on the server sideVictor Bashurov
That example shows how to build a war file using the servlet bridge. It does not build a bundle. Just wondering if the example works as expected?Sten Roger Sandvik
In my case it doesn't work as expected. However I modified this sample. Instead of using war file I'd like to use a bundle (jar file) and install this bundle to OSGI embedded framework of the main servletVictor Bashurov

1 Answers

2
votes

Looks like I made a mistake configuring embedded OSGI. Now I got it worked, if anyone needs a sample of a felix servlet bridge take a look on this: http://vbashur.blogspot.kr/2014/07/osgi-servlet-bridge-sample.html