views:

513

answers:

2

What bundles do I need to install? At least, this would have to be a servlet container / web server such as Jetty, but will the basic org.apache.felix.http.jetty bundle do, or is there anything else needed to discover the web.xml in other bundles?

Do I put the webapp in a standard WAR, add OSGi headers and am done? Or are there any webapp specific headers required for the OSGi environment?

What other configuration has to be done?

What are options to automate these steps using Maven?

I have tried deploying the org.apache.felix.http.jetty bundle, and I get a Jetty answering with 404 on localhost:8080. Next, I tried a simple webapp with nothing but a static HTML file configured as a welcome-file. As far as I can tell, Jetty doesn't even notice the deployment descriptor, at least deploying the test webapp into Felix doesn't change anything at all.

+1  A: 

Jetty and the webapp alone are not enough, there has to be some glue that actually registers the webapp at the web server under a specific context.

One example that works:

  • use the Pax web service in the org.ops4j.pax.web.pax-web-service bundle as the HTTP Service, it runs Jetty, too
  • add a Webapp-Context header to your bundle manifest
  • use the Pax web extender to look for that header when your bundle registers, it will then hook it up to the http service.

For some reason, it has to be the Pax webservice, if I replace it with the basic jetty bundle from org.apache.felix, it won't resolve the URL properly.

I'm still a long way from actually understanding what's going on here, but at least I got it working. I suspect you could do without the Pax bundles and the bundle header if you let your webapp bundle do something in its bundle activator to perform the hookup.

Hanno Fietz
Maybe the registration is possible through injection via Declarative Services (if it isn't, it surely should be).
pmf
+1  A: 

You don't have to use Pax Web but it does make things a lot easier. Without Pax Web, you'll need a bundle that implements the OSGi HTTP Service (there's a Jetty bundle for this) then get a service reference to HttpService. You can register your webapp with this but it is tedious. Take a look at the Pax Web code if you want to see the gory details. Pax Web doesn't add anything to HttpService but just handles all the registration pains.

Carl