Http Service

Apache Karaf supports several Http Services:

  • http feature installs Http Service powered by Pax Web

  • felix-http feature installs Http Service powered by Apache Felix HTTP

Installing the Http Service

If you want to use Pax Web Http Service, you have to install the http feature:

root@karaf()> feature:install http

NB: the HTTP service will be actually bound only when at least one web application will use it.

If you want to use Apache Felix Http Service, you have to install felix-http feature:

root@karaf()> feature:install felix-http

If you want to test the HTTP service, you can install the webconsole feature:

root@karaf()> feature:install webconsole

Then, you can test the HTTP service by accessing the Apache Karaf WebConsole pointing your browser to [http://localhost:8181/system/console].

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 (if you use the Pax Web Http Service) 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.

If you use Apache Felix Http Service, it’s basically the same but the configuration is etc/org.apache.felix.http.cfg.

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

NB: felix-http feature installs whiteboard by default in the feature.

You can take a look on a full example using whiteboard here: https://github.com/apache/karaf/tree/master/examples/karaf-servlet-example

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