Using OSGi HTTP Whiteboard in Liberty
You can use the httpWhiteboard-1.0 feature to enable the development and deployment of modular Web applications written using servlet technologies.
Before you begin
- Install the latest version of Liberty with the OSGi application programming model capabilities. You can install Liberty either by using one of the zip install packages (ZIP file) or by extracting the Java archive (JAR) package. For more information about installing Liberty, see Installing Liberty.
- Install the httpWhiteboard-1.0 feature. If the feature is not
available as part of the downloaded ZIP archive files, then install the feature
from the Liberty repository by using the following
command:
bin\installUtility install httpWhiteboard-1.0
Step 1 of 3: Downloading httpWhiteboard-1.0...
Step 2 of 3: Installing httpWhiteboard-1.0...
Step 3 of 3: Cleaning up temporary files...
After the feature is installed successfully, you can use the feature.
Procedure
What to do next
The Http Whiteboard implementation looks for a particular type of OSGi services that are registered, for example javax.servlet.Servlet. So to use the Http Whiteboard feature, you can use any supported OSGi component model, such as Blueprint, to register the service and the service is automatically picked up.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="MyWhiteboardServletBean"
class="com.my.MyWhiteboardServlet" />
<service id="MyWhiteboardServletBeanService"
ref="MyWhiteboardServletBean"
interface="javax.servlet.Servlet" />
<service-properties>
<entry key="osgi.http.whiteboard.servlet.pattern"
value="/mywhiteboardservlet" />
</service-properties>
</service>
</blueprint>
[AUDIT ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT ] CWWKN2000A: HTTP Whiteboard context root added: /osgi/http
[AUDIT ] CWWKN2000A: HTTP Whiteboard context root added: /osgi/http/shared
[AUDIT ] CWWKT0016I: Web application available (default_host): http://localhost:9080/osgi/http/
[AUDIT ] CWWKN2000A: HTTP Whiteboard context root added: /osgi/http/MyHttpWhiteboardApp
[AUDIT ] CWWKZ0001I: Application MyHttpWhiteboardApp started in 0.424 seconds.
http://localhost:9080/osgi/http/MyHttpWhiteboardApp
Adding the value of
osgi.http.whiteboard.servlet.pattern will result in the following
URL:http://localhost:9080/osgi/http/MyHttpWhiteboardApp/mywhiteboardservlet
The Http Whiteboard specification is based around the OSGi services. This means the feature integrates with other native OSGi services and component models. For example, Blueprint can be used to dynamically inject other services. Blueprint name space handlers and configuration admin can be used to dynamically inject configuration values into the servlet allowing the application configuration to be changed if required.