Http Service

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

Installing the HTTP feature
root@karaf()> feature:install http

Test the HTTP service is up by pointing your browser to [http://localhost:8181/].

Configuring the HTTPService

By default the HTTPService listens on port 8181 you can change the port by creating a file etc/org.ops4j.pax.web.cfg with the following content:

org.osgi.service.http.port=8181

or by typing:

root@karaf> config:property-set -p org.ops4j.pax.web org.osgi.service.http.port 8181

If the http feature is already installed the change will take effect immediately.

Registering a servlet with the HttpService manually
Using the Pax Web whiteboard extender

The Pax Web whiteboard extender is an enhancement of the http feature. So use the following command to install:

root@karaf> feature:install http-whiteboard

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:8181/myServlet.

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

For commands take a look at the command section in the webcontainer chapter.