tree: f2dbbf9c79b4bd68b3ab30c5878adcf18b60c0a7 [path history] [tgz]
  1. karaf-servlet-example-annotation/
  2. karaf-servlet-example-blueprint/
  3. karaf-servlet-example-features/
  4. karaf-servlet-example-registration/
  5. karaf-servlet-example-scr/
  6. pom.xml
  7. README.md
examples/karaf-servlet-example/README.md

Apache Karaf Servlet examples

Abstract

This example show how to register a servlet in the Karaf HTTP Service.

It uses different approaches:

  1. Using @WebServlet annotation using the Karaf annotation scanner
  2. Registering a servlet directly into the Karaf HTTP service
  3. Using Karaf Servlet whiteboard pattern with blueprint
  4. Using Karaf Servlet whiteboard pattern with SCR

Artifacts

  • karaf-servlet-example-annotation is a bundle using @WebServlet Servlet 3.0 annotation to register.
  • karaf-servlet-example-registration is a bundle that register a servlet directly into the Karaf HTTP service.
  • karaf-servlet-example-blueprint is a Blueprint bundle registering a Servlet service used by the Karaf Servlet whiteboard pattern.
  • karaf-servlet-example-scr is a SCR bundle registering a Servlet service used by the Karaf Servlet whiteboard pattern.
  • karaf-servlet-example-features provides a Karaf features repository used for the deployment.

Build

The build uses Apache Maven. Simply use:

mvn clean install

Features and Deployment

On a running Karaf instance, you register the example features repository with:

karaf@root()> feature:repo-add mvn:org.apache.karaf.examples/karaf-servlet-example-features/LATEST/xml

The karaf-servlet-example-annotation feature installs the required features (HTTP service) and register the servlet using Servlet 3.0 annotation:

karaf@root()> feature:install karaf-servlet-example-annotation

The karaf-servlet-example-registration feature installs the required features (HTTP service) and register the servlet by hand in the Karaf HTTP service:

karaf@root()> feature:install karaf-servlet-example-registration

The karaf-servlet-example-blueprint feature installs the required features (HTTP service & blueprint) and register the servlet using a Servlet service:

karaf@root()> feature:install karaf-servlet-example-blueprint

The karaf-servlet-example-scr feature installs the required features (HTTP service & SCR) and register the servlet using a Servlet service:

karaf@root()> feature:install karaf-servlet-example-scr

Usage

Whatever feature you use, you can access the servlet on the following URL:

[http://localhost:8181/servlet-example]