Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

This post will walk you through porting the Liberty MongoDB Sample application over to run on WebSphere Application Server Full Profile 8.5.5.1.

Before you start

Install a local version of WebSphere Application Server 8.5.5.1 (the full profile) and a MongoDB server to run against.

Instructions

  1. Download and unjar the Liberty MongoDB sample application.
  2. Copy the MongoDB configuration from mongoDBSample.jar\wlp\usr\servers\mongoDBSample\server.xml into a new file named ibm-mongodb.xml with a root element of <ibm-mongodb>. You will end up with something like this (you can modify the configuration settings as necessary):
    <ibm-mongodb>
      <mongo id="mongo" libraryRef="mongo-lib" hostNames="localhost" ports="27017"/>
      <mongoDB jndiName="mongo/sampledb" mongoRef="mongo" databaseName="sampleDb"/>
    </ibm-mongodb>
    
  3. Install the newly created configuration file into the application server’s configuration repository. If in the future you need to make configuration changes, you’ll need to manually edit this file in place and restart the server; the file is only processed at server start. To install this file:
    1. Start wsadmin (make sure your app server is running):
      C:\<was_home>\bin\wsadmin.bat -lang jython
    2. Run the following commands (replace <...> with the values for your system):
      AdminConfig.createDocument("cells/<cell_name>/nodes/[node_name]/servers/<server_name>/ibm-mongodb.xml", "<path_to>/ibm-mongodb.xml")
      
      AdminConfig.save()

    If the commands were successful, the MongoDB configuration in now installed into the WebSphere Application Server configuration tree.

    The MongoDB configuration must be scoped to an individual application server and it can’t be installed at any other levels. Also, there is no console support. If for some reason you don’t want to use the MongoDB support any longer, you can use AdminConfig to remove this document.

  4. Install the application that is packaged inside of the Liberty MongoDB sample (mongoDBApp.war):
    1. Log into the administrative console.
    2. Install the application to the server on which you installed the MongoDB configuration.
    3. Whilst going through the wizard, accept the default values and keep clicking Next.
    4. On Step 3, you’ll need to specify the target JNDI name for the resource reference mongodb/sample. In the Target Resource JNDI Name field, type mongodb/sampledb.

      mongodb 3 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

    5. In Step 5 of the wizard, set the context root to mongodb:

      mongodb 5 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

    6. Save the changes to the master configuration.

      At this point we have added the MongoDB configuration to the WebSphere configuration and installed the application.

  5. Configure a shared library so that the MongoDB Java driver classes are available to the server and the application:
    1. Download Version 2.10.0 or later of the MongoDB Java driver to the same file system as WebSphere Application Server.
    2. In the administrative console, navigate to Environment > Shared Libraries > New….
    3. Choose a name for this shared library (ie: mongodb), and configure the classpath to reference the newly downloaded driver.
    4. Select the Use an isolated class loader for this shared library check box.

      mongodb sl 1 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

  6. Navigate back to the application (Applications > WebSphere Enterprise Applications > mongoDBApp_war) configuration that was installed in Step 4 and click the Shared library references link.

    mongodb sl 2 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

  7. On the next page, click the first box and then click the Reference shared libraries button.

    mongodb sl 3 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

  8. Select the shared library that was created in Step 5 and click the arrow pointing to the right to add the reference. Then click OK and save the changes to the master configuration.

    mongodb sl 4 Porting a Liberty MongoDB application to run on WebSphere Application Server Full Profile

  9. At this point everything is fully configured. Restart the application server and if all works as expected, you should see a CWKKD0112 message indicating that the MongoDB service started successfully. Point your web browser to http://localhost:9080/mongodb (you might have to change the port depending on your installation). If you don’t see ‘HelloMongo!’ review the server logs for any error messages that might indicate what the problem is.