Pax Web (OSGi HttpService)

The Karaf http feature enables the Pax Web implementation of the OSGi HTTP service.

Installing the HTTP feature

root@karaf> features:install http

Create a file etc/org.ops4j.pax.web.cfg with the following content:

org.osgi.service.http.port=8080

This tells Pax Web to listen to the port 8080. As soon as the http feature is installed and the config
file is present, the following URL will be reachable:

http://localhost:8080/

Registering a servlet with the HttpService manually

See Apache Felix HTTP Service.

Using the Pax Web whiteboard extender

The Pax Web whiteboard extender is part of the war feature. So use the following command to install:

root@karaf> features:install war

The Pax Web whiteboard extender listens to services
of interface type HttpServlet and Filter.
It will register each of these interfaces with the HttpService and remove them as soon as the service goes down.
So it is much more convenient than registering with the HttpService directly.

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <service interface="javax.servlet.http.HttpServlet">
        <service-properties>
            <entry key="alias" value="/myservlet"/>
        </service-properties>
        <bean id="myServlet" class="com.example.MyServlet"/>
    </service>
</blueprint>

The above snippet publishes the Servlet MyServlet on http://localhost:8080/myServlet.

Please keep in mind that the Whiteboard pattern for Servlets is not standardized and only works with Pax Web.