Run a MongoDB data adapter for Atom Hopper with Netbeans

Akademily
4 min readOct 1, 2020

Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to use the new MongoDB data adapter.

After testing, refactoring etc. is complete. E. For the MongoDB data adapter, it is likely to be enabled by default, not in the current Hibernate data adapter.
Important note: Be sure to put Index in DateLastUpdated — this will significantly improve HTTP GET requests.

As stated in our wiki, there are several ways to run Atom Hopper. To test a MongoDB adapter with Atom Hopper, let’s consider how to run it from Netbeans 7.1. You will also need a MongoDB running locally on your computer.

STEP 1: GET THE SOURCE CODE

The source code is open source under an Apache 2 license. You can use Git to easily get the source code. I am on OS X and I tend to use GitHub’s Mac client, but you can also use Git functionality in Netbeans.

STEP 2: COMPILING THE SOURCE CODE

Once you have downloaded the main repository for Atom Hopper, you can use Netbeans 7.1 to download the project. Run Netbeans, if it is not already running, and select: “File” -> “Open Project”, find the Atom-Hopper folder, click “Open required projects” and click “Open”.

After loading a project, right-click the ATOM Hopper — ATOMpub Server Collection project and select “Clean up and build”.

STEP 3: LAUNCHING THE STANDALONE VERSION OF JETTY (FOR TESTING PURPOSES ONLY)

At this stage, the project should have been successfully built — and it may take some time as all dependencies should be loaded first. Usually, when you run Atom Hopper, you use the resulting WAR file and embed it into something like Apache Tomcat. For simplicity and because it’s only for testing the new MongoDB adapter for Atom Hopper, I’ll just show you how to run the standalone version of Jetty used to debug Atom Hopper.

Right-click the default ATOM Hopper project — Jetty Server and select Properties.

In the opened dialog box “Project Properties” click “Run” in the left part of the categories, and then add the word “start” to the text field “Arguments” on the right.

Click the Ok button and return to the project. Go to the ATOM Hopper — Default Jetty Server project files and find the file atom-server.cfg.xml and application-context.xml.

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

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
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>

<bean name="mongodb-feed-publisher" class="org.atomhopper.mongodb.adapter.MongodbFeedPublisher">
<property name="mongoTemplate" ref="mongoTemplate" />
</bean>

<bean name="mongodb-feed-source" class="org.atomhopper.mongodb.adapter.MongodbFeedSource">
<property name="mongoTemplate" ref="mongoTemplate" />
</bean>
</beans>

Now we just need to install the atom-server.cfg.xml file so that it points to the publisher and MongoDB news 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">
<defaults>
<author name="Atom Hopper" />
</defaults>

<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" />
</feed>
</workspace>
</atom-hopper-config>

Continue and recompile the default ATOM Hopper — Jetty Server project, then right-click it and select “Run”.

The startup command we installed earlier allows the Jetty server to start at the following default values:
http:// localhost: 8080 / namespace / feed /

Use the above URL to check everything. You can execute HTTP POST or GET for the channel. Here is an example of ATOM XML code that you can use for testing:

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

Note. You can use a plugin such as XHR Poster for Chrome to easily place it in the Atom Hopper, or a plugin such as Poster for Firefox.

Before running HTTP POST, make sure that the content type is set to application/atom+xml. You can get more information on how to use the plugin to test Atom Hopper, from here.

To terminate a standalone Jetty Server, simply return to the ATOM Hopper — Jetty Server default project, then right-click it and select “Properties”. In the Project Properties dialog box that opens, click “Run” in the left part of the categories and then add the word “stop” to the text field “Arguments” on the right. Then run the ATOM Hopper — Jetty Server project by default, which will send the command to finish the work to the running instance.

--

--

Akademily

We conduct reviews, guides and comparative tests of gaming laptops, monitors, graphics cards, keyboards, mouses, headsets and chairs to help you buy the best ga