Over a million developers have joined DZone.

Run the MongoDB Data Adapter for Atom Hopper with Netbeans

DZone's Guide to

Run the MongoDB Data Adapter for Atom Hopper with Netbeans

· Database Zone ·
Free Resource

Download "Why Your MySQL Needs Redis" and discover how to extend your current MySQL or relational database to a Redis database.

I’ve mentioned Atom Hopper several times in this blog. Atom Hopper (based on Apache Abdera) for those whom might not know is a Rackspace sponsored open source project. Today I’ll show you how to use the new MongoDB data adapter. Although the MongoDB data adapter has not been fully tested and therefor shouldn’t be used in production yet, as a developer you can kick the tires and send us feedback or pull requests with improvements.

Once testing and refactoring, etc. has been completed for the MongoDB data adapter it will most likely be turned on by default rather than the current Hibernate data adapter. For now I’m going to assume it (MongoDB data adapter) needs to be manually turned on.

Important: Make sure to put an Index on DateLastUpdated – this will greatly improve HTTP GET requests.

As our wiki states there are several ways to run Atom Hopper. To test out the MongoDB adapter with Atom Hopper I’m going to show you how to run it from Netbeans 7.1. You will also need MongoDB running locally on your computer.

Step 1: Get the Source Code
The source code is open sourced under the Apache 2 license. You can use Git to grab the source code easily. I’m on OS X and I tend to use GitHub’s Mac client but you can use the Git functionality in Netbeans as well.

Step 2: Compile the Source Code
Once you have the master repository for Atom Hopper downloaded you can use Netbeans 7.1 to load the project. Start Netbeans if it isn’t running already and choose: File -> Open Project and locate the atom-hopper folder and click on the Open Required Projects option and then click open.

Once you have the project loaded right-click on the ATOM Hopper – ATOMpub Server Collection project and select Clean and Build.

Step 3: Running the stand alone Jetty version (only for testing)

At this point the project should’ve built successfully – and it may take a while since all the dependencies need to be downloaded first. Normally when you run Atom Hopper you use the resulting WAR file and deploy that to something like Apache Tomcat. For simplicity and because this is only to test the new MongoDB adapter for Atom Hopper I’ll simply show you how to run the standalone Jetty version which is what is used to debug Atom Hopper.

Right click on the ATOM Hopper – Default Jetty Server project and select Properties.

In the Project Properties dialog that opens up click on Run in the left hand side categories and then on the right add the word start to the Arguments textbox.

Press the Ok button and return to the project. Go into the ATOM Hopper – Default Jetty Server project files and locate the atom-server.cfg.xml and the application-context.xml files.

Let’s add MongoDB as the default adapter in the application-context.xml file. This is done by commenting out the Hibernate adapter and uncommenting in the MongoDB adapter. The file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!-- MongoDB -->
    <mongo:mongo host="localhost" port="27017"/>
    <bean name="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="mongo"/>
        <constructor-arg name="databaseName" value="atomhopper"/>
    <bean name="mongodb-feed-publisher" class="org.atomhopper.mongodb.adapter.MongodbFeedPublisher">
        <property name="mongoTemplate" ref="mongoTemplate" />
    <bean name="mongodb-feed-source" class="org.atomhopper.mongodb.adapter.MongodbFeedSource">
        <property name="mongoTemplate" ref="mongoTemplate" />

Now we just need to set the atom-server.cfg.xml file to point to the MongoDB feed publisher and source:

<?xml version="1.0" encoding="UTF-8"?>
<atom-hopper-config xmlns="http://atomhopper.org/atom/hopper-config/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://atomhopper.org/atom/hopper-config/v1.0 ./../../config/atom-hopper-config.xsd">
        <author name="Atom Hopper" />
    <host domain="localhost:8080" />
    <workspace title="Testing Namespace" resource="/namespace/">
        <categories-descriptor reference="workspace-categories-descriptor" />
        <feed title="Testing Feed" resource="/feed">
            <publisher reference="mongodb-feed-publisher" />
            <feed-source reference="mongodb-feed-source" />

Go ahead and re-compile the ATOM Hopper – Default Jetty Server project, then right-click on it and select Run.


The start command we set earlier allows the Jetty server to startup under the following defaults:

Use the above URL to test everything out. You can perform an HTTP POST or GET to the feed. Here is a sample ATOM XML you can use to test with:

<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">This is the title</title>
    <name>John Doe</name>
  <content type="text">Hello World</content>
  <category term="MyCategory 1" />
  <category term="MyCategory 2" />
  <category term="MyCategory 3" />

Note: You can use a plugin like XHR Poster for Chrome to easily POST this to Atom Hopper or a plugin like Poster for Firefox.

Before doing an HTTP POST make sure to set the content-type as application/atom+xml. You can get more details on how to use a plugin to test Atom Hopper from here.

To shutdown the Jetty standalone server simply go back into the ATOM Hopper – Default Jetty Server project and then right-click on it and select Properties. In the Project Properties dialog that opens up click on Run in the left hand side categories and then on the right add the word stop to the Arguments textbox. Then run the ATOM Hopper – Default Jetty Server project which will send a shutdown command to the running instance.

A final reminder… The MongoDB data adapter is still going through refactoring and testing so it is not ready for production usage at this time. Follow Atom Hopper on Twitter and you will be the first to know when it has stabilized enough for production usage. See the Atom Hopper wiki for the latest documentation.


Read "Developing Apps Using Active-Active Redis Enterprise" and discover the advantages over other active-actve databases.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}