OSGi blog sample application

The blog sample application is a traditional blogging application, used for publishing essay-length articles and allowing readers to comment on them. This sample application shows how to write and package bundles into an enterprise bundle archive (EBA) file. The sample includes example code for Blueprint management, bean injection, using and publishing services from and to the OSGi service registry, and the use of Java™ persistence.

Before you begin

The blog sample application consists of five bundles, but can be run with four bundles because the fifth bundle is an upgrade to the persistence bundle.

The sample application requires that the supplied com.ibm.samples.websphere.osgi.logging.api.jar and com.ibm.samples.websphere.osgi.logging.impl.jar bundles are installed into the internal bundle repository. The following procedure describes how to do this. These two JAR files, and the blog sample EBA file, are provided in the installableApps directory of the OSGi_blogSample.zip compressed archive file.

About this task

The bundles are divided into the following functional areas:
  • com.ibm.samples.websphere.osgi.blog.persistence, which contains code relating to the Java Persistence API (JPA) layer, and also contains interfaces that are used by the main application code to update and query blog entries.
  • com.ibm.samples.websphere.osgi.blog_1.0.0, which contains the main application logic code, and interacts between the web front end and the back end persistence code layer.
  • com.ibm.samples.websphere.osgi.blog.web, which contains the static web content and backing Java code for the web front end for the application.
  • com.ibm.samples.websphere.osgi.blog.api, which contains the API for the whole sample.
  • com.ibm.samples.websphere.osgi.blog.persistence_1.1.0, which contains an upgraded persistence bundle that also supplies a comment service.

You can use scripts to completely install the sample application, or you can use scripts to complete the initial configuration of the application then use the administrative console to install the application into the application server. You can also use, modify and remove the sample, and upgrade the persistence service that is provided by the sample.

Procedure

Configure and install the blog sample.

You can either configure and install the sample using scripts (the first optional step in the instructions that follow), or you can configure the sample using scripts then install the sample using the administrative console (the second optional step in the instructions that follow).

The scripts that you use to do this are provided in the scripts directory of the OSGi_blogSample.zip compressed archive file. The createBlogDb.sql script contains the necessary configuration commands to create the required Derby database and associated tables. The blogSampleInstall.py script contains the required jython to create data sources, and to install the blog sample with default configuration. You should fully qualify the path to the script if you do not run it from the directory that contains the script.

Note: If you have data sources already defined in your environment, and these data sources have the same name as the data sources that are specified in the blogSampleInstall.py script, then the sample might not install and run successfully.

In the following steps you must substitute your own values for the variables app_server_root, profileName, serverName, nodeName, blogSample.eba_Location, com.ibm.samples.websphere.osgi.logging.api.jar_Location, com.ibm.samples.websphere.osgi.logging.impl.jar_Location, uncompressed_sample_directory, and path_to_ant.

Use the blog sample.

Upgrade the persistence service.

To add the new persistence bundle to the blog application, use the administrative console to load the com.ibm.samples.websphere.osgi.blog.persistence_1.1.0.jar file into the internal bundle repository, then modify the asset to expect a new bundle version. Complete the following steps:

Modify the blog sample

All the source code for this application is provided in sub-directories below the uncompressed_sample_dir directory. Each part of the project has its own ant build.xml script. To build the whole application into a newly-available EBA file, you use the ant build.xml file located in the uncompressed_sample_dir directory. WebSphere® Application Server ships a version of ant in its bin directory called ws_ant. To build the sample, you also need a JAR file on the ant classpath. To simplify matters, you can edit the was.root property in the supplied build.properties file to point to this JAR file.

Remove the blog sample.

To remove the blog sample, you complete the following 3 steps:
  1. Remove the application configuration and the data sources, either by using a script (the first optional step in the instructions that follow), or by using the administrative console (the second optional step in the instructions that follow).
  2. Remove the shared logging bundles from the internal bundle repository.
  3. Remove the database.
Note: Only remove the bundles if you have no other applications installed that use them. Both the blog and blabber sample applications use the shared logging bundles, so if both applications are installed these bundles should not be removed.

The uninstall script is provided in the scripts directory of the OSGi_blogSample.zip compressed archive file. The blogSampleUninstall.py script contains the required jython to remove data sources and to remove the installation of the blog sample with default configuration. You should fully qualify the path to the script if you do not run it from the directory that contains the script.

In the following steps you must substitute your own values for the variables app_server_root, and profileName.

Results

The following illustration shows the correctly running sample:

A screen capture of the Blog application Home page. There is a banner labeled "Blog Home", and a blank page below the banner. At the top of the blank page are two options: "CREATE NEW POST" and "CREATE AUTHOR".


Icon that indicates the type of topic Task topic

Terms and conditions for information centers | Feedback


Timestamp icon Last updated: Monday, 21 April 2014
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-express-iseries&topic=sample_osgi_blog_readme
File name: sample_osgi_blog_readme.html