3

I am using struts2 for my web application and i want to use osgi architecture for service and dao layer. Now I dont want to wrap my struts2 actions as osgi bundles but want service and dao layer to be packaged as bundles. Now can anybody tell me how my non osgi actions can consume osgi bundles(service and dao layer). And I want to deploy my struts2 web application in web container so how web container will interact with osgi container(where my service and dao is deployed) in this case . Please help .

2 Answers 2

5

You need a so called 'bridge' between your web container and your OSGi environment. Both Felix and Equinox have that capability, but for me the Felix implementation worked much better.

What you basically want to do is:

  • Add a context listener to your ServletContext
  • Starting OSGi when starting the ServletContext, stop it when the ServletContext gets destroyed.
  • Pass the ServletContext to the OSGi context by registering it as a service
  • Store the OSGi framework object in the ServletContext by registering it as an attribute.

So to access the web context from OSGi: Retrieve the ServletContext service, and go from there.

To access OSGi from the webcontext: Retrieve the OSGi framework from the ServletContext attribute and go from there.

Check the Felix Documentation, also I've made an example a while back on GitHub

4
  • could you please give me some link to the tutorial which i can follow ? It would be of great help Jul 24, 2012 at 10:46
  • Not really, the felix bridge documentation is all I could find. It isn't really a tutorial, but it does explain how it works. It is a pity it does not help you get a functional application, it only gets you to the point that you have a running OSGi framework, which can't do much. From there on, the only thing you can do is explicitly installing new bundles (using BundleContext.installBundle). This is only feasible for tiny projects.
    – Frank Lee
    Jul 24, 2012 at 16:19
  • What I did in my example was (in the FrameworkService2 class) was programatically loop through all the jar files in the WEB-INF/bundles dir, and installing them into the framework, so you have a sort-of easy way to add bundles.
    – Frank Lee
    Jul 24, 2012 at 16:21
  • It is not the best way to deploy bundles into OSGi (For example OBR is much nicer) but it should be enough to get you going.
    – Frank Lee
    Jul 24, 2012 at 16:23
-1

Most surely this will not work. Why do you think it should be a good idea to move half of your application to OSGi? Either you should move all of it or none.

You may be able to deploy the struts layer in a war file and a access the OSGi services from it. I think this is possible in Virgo and Apache Karaf. It means to enhance the war with OSGi structures. For example in Karaf you can use a wab file which is a war file with a Manifest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.