Skip to content
Sample Liberty User Feature showing how to provide an OSGi Service (the httpservice) to an OSGi application.
Java
Latest commit b4fe77b Sep 12, 2014 @lauracowen lauracowen Create CONTRIBUTING.md

README.md

sample.osgi.httpservice

This sample project combines the Equinox httpService with OSGi Applications on the WebSphere Liberty profile.

This readme file focusses on how to install and test the sample. Please see https://www.ibmdw.net/wasdev/docs/sample-osgi-httpservice for a broader overview of the sample and its purpose.

The project comprises a user feature and two OSGi applications. The user feature provides the HttpService. Of the two OSGi Applications, one registers itself with the HttpService; the other is detected and registered by the user feature.

Installation This section covers:

  • Getting the projects into Eclipse
  • Getting them to compile cleanly by downloading some missing bundles
  • Testing the application on a WebSphere Liberty profile.

Getting the projects into Eclipse. You will need:

  1. Create a WebSphere Liberty Profile runtime.
  2. Install the WebSphere Application Server Developer Tools ("WDT") into Eclipse: https://www.ibmdw.net/wasdev/downloads/
  3. Window > Preferences > Server > Runtime Environments > Add > WebSphere Application Server V8.5 Liberty Profile. Download a new runtime or reuse an existing one. Mine is called the default 'WebSphere Application Server V8.5 Liberty Profile'.

  4. Add a new server

  5. Create a new server: New > Server > WebSphere Application Server V8.5 Liberty Profile

  6. Download the following bundles:

  7. Load them into Eclipse: File > Import > OSGi Bundle or Fragment. Take the defaults, including the use of Liberty as the target runtime.

  8. git clone https://github.com/WASdev/sample.osgi.httpservice File > Import > Existing projects into workspace. Pull in:

    • httpService-1.0 - user feature
    • httpServiceWab - bundle contained by the user feature. http requests go through here.
    • redWeb - application bundle
    • redWeb.app - OSGi Applcation
    • greenWeb - second application bundle
    • greenWeb.app - second OSGi Application
  9. Set up your Target Platform: Windows > Preferences > Plug-in Development > Target Platform, and select WebSphere Application Server V8.5 Liberty Profile with SPI.

  10. Set up your server. I've not worked out how to check a server.xml into GitHub in a way that makes it easy to pull out. So, edit your server.xml and add the following features: wab-1.0 usr:httpService-1.0

    Also add this stanza:

       <webContainer deferServletLoad="false"/>
    
  11. Install the user feature: Right click on httpService-1.0 in Enterprise Explorer and then click "Install Feature".

  12. Install the first application: right click redWeb.app > Run as > run on server

  13. Start the server

  14. Test the application! Visit http://localhost:9080/httpService/red

    Web browser displays, 'Hello World from RedServlet'

  15. Test the second application! Vitit http://localhost:9080/httpService/greenWeb

    Web browser displays, 'Hello World from GreenServlet'

Something went wrong with that request. Please try again.