Thursday, April 16, 2009

Configuring Jetty in the pax-web OSGi bundle

It took awhile for me to figure out how to configure Jetty as deployed in the pax-web web service bundle. It took even longer to figure out how to enable AJP in Jetty using the bundle fragment. Unfortunately, the steps on the pax-web site are incorrect (now fixed: 2009-04-17) for the current version of pax-web (0.6.0). Hopefully this will save someone else from having to go through this "fun".

Note that this will only work in pax-web version 0.5.2 or higher and requires an OSGi container that supports OSGi bundle fragments. I was doing this in Felix 1.6.0 (inside Sling).
  1. Checkout my bundle fragment source code
    https://source.caret.cam.ac.uk/camtools/trunk/sling/sling-jetty-config
  2. Edit the jetty.xml file to suit your taste
    (the one in there enables AJP)
  3. Build using Maven 2
    mvn clean install -Pajp
    (Leave off the -Pajp if you are not enabling/using ajp)
  4. Install the bundle fragment into your OSGi container using whatever mechanism you are used to. It tends to work best to install it with the same level as the bundle it is being used with.
  5. Restart the OSGi container
    (this is not always required but I find it tends to work a lot better if you do)
Unfortunately, I could not find a very good way to verify that this works other than putting a breakpoint at line 66 of /pax-web/bundle/src/main/java/org/ops4j/pax/web/service/internal/JettyServerImpl.java. You should see the jetty.xml file get loaded (resource will be non-null). You could also just check to see if Jetty is behaving as you would expect with the changes.

If there are problems (the fragment seems to have no effect) then here are a few debugging steps that may work:
  1. If you are using felix then you can run the resolve command from the felix command shell for your fragment. If you get nothing then you are probably good to go, if you get a failure then the Fragment-Host: org.ops4j.pax.web.pax-web-service value probably does not match the one in your container. Make sure the value is the same as the symbolic name of your installed pax-web-service-*.jar.
  2. Try making sure your jetty.xml actually works with Jetty. There are instructions on the Jetty website.

2 comments:

Olga Kudryavtseva said...

Do you have some problems with logging when configuring your jetty server? I have a problem with creating directory for logs, but when I create it by myself log-files will be created there without any problems.

Unknown said...

Thanks for this great information - you saved my day. It works like a charme!