| h1. Pax Web (OSGi HttpService) |
| |
| The Karaf http feature enables the Pax Web implementation of the OSGi HTTP service. |
| |
| h2. Installing the HTTP feature |
| |
| {code} |
| root@karaf> features:install http |
| {code} |
| |
| Create a file {{etc/org.ops4j.pax.web.cfg}} with the following content: |
| |
| {code} |
| org.osgi.service.http.port=8080 |
| {code} |
| |
| 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: |
| |
| {code} |
| http://localhost:8080/ |
| {code} |
| |
| h2. Registering a servlet with the HttpService manually |
| |
| See [Apache Felix HTTP Service|http://felix.apache.org/site/apache-felix-http-service.html]. |
| |
| h2. Using the Pax Web whiteboard extender |
| |
| The Pax Web whiteboard extender is part of the war feature. So use the following command to install: |
| |
| {code} |
| root@karaf> features:install war |
| {code} |
| |
| The [Pax Web whiteboard|http://wiki.ops4j.org/display/ops4j/Pax+Web+Extender+-+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. |
| |
| {code} |
| <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> |
| {code} |
| |
| 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. |
| |