Running Atom Hopper with Apache Tomcat

Post to Twitter

In my last post I introduced you to Atom Hopper. Today I want to show you how to take the Atom Hopper WAR file and run it inside Apache Tomcat as well as change some of the default settings.


Please refer back to my original post on how to get Atom Hopper up and running in Netbeans 7.

Update: March 9, 2012 – All configuration files are now located in one central location when running Atom Hopper as a WAR in an application server like Apache Tomcat. Any references in this article to configuration files will refer to the location: /etc/atomhopper/ You should make sure to follow the WAR Installation Method (Recommended) in the Atom Hopper Wiki.

With the Atom Hopper project loaded and built we can go into the folder for the ATOM Hopper – WAR project. From the target folder we can grab the newly created WAR file (or just remember this location).

I am using OS X 10.7 (Lion) and I am assuming you are on either OS X or Linux. If you are using Windows you will need to make changes to the path for the database and the atom-server.cfg.xml file. You can make the first change in the application-context.xml file.

For OS X and Linux users make sure that the following paths exist (modify for Windows):

/opt/atomhopper
/etc/atomhopper

To put the database into your home folder you can change this:

<entry key="hibernate.connection.url" value="jdbc:h2:/opt/atomhopper/atom-hopper-db" />

To this:

<entry key="hibernate.connection.url" value="jdbc:h2:~/atom-hopper-db" />

- also make sure that you have access to the read and write to the mentioned folders (assuming the Tomcat process is started under your username).

Place the atom-server.cfg.xml file (which can be found in the folder in the screenshot below) into: /etc/atomhopper

Assuming you have Tomcat 6 or 7 running you can either drop the WAR file into the webapps folder or install it via the Tomcat manager tool. Once it has been deployed call it with Poster (a FireFox add-on).

Go to the following address (change as needed as the version number is incremented):
http://localhost:8080/ah-war-0.9.2-SNAPSHOT/namespace/feed/

Press the GET button in Poster to get the feed, yours will be empty for now but mine has some entries already:

Let’s add two new workspaces (or called namespaces).

Shutdown Tomcat. Go into the /etc/atomhopper folder and edit the file called: atom-server.cfg.xml

The contents of atom-server.cfg.xml look like this:

<?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="domain.com" />

    <workspace title="Testing Namespace" resource="/namespace/">
        <categories-descriptor reference="workspace-categories-descriptor" />
        
        <feed title="Testing Feed" resource="/feed">
            <feed-source reference="hibernate-feed-source" />            
            <publisher reference="hibernate-feed-publisher" />
        </feed>
    </workspace>  
</atom-hopper-config>

It is in this path we setup the workspace and feeds. Lets create two workspaces with unique feeds. Also, let’s get rid of the default domain.com and replace it with our IP address (I’ll just use localhost for now) so the links in the ATOM entries work.

<?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" />

    <workspace title="Namespace1" resource="/namespace1/">
        <categories-descriptor reference="workspace-categories-descriptor" />
        
        <feed title="Feed1" resource="/feed1">
            <feed-source reference="hibernate-feed-source" />            
            <publisher reference="hibernate-feed-publisher" />
        </feed>
    </workspace>
    
    <workspace title="Namespace2" resource="/namespace2/">
        <categories-descriptor reference="workspace-categories-descriptor" />
        
        <feed title="Feed2" resource="/feed2">
            <feed-source reference="hibernate-feed-source" />            
            <publisher reference="hibernate-feed-publisher" />
        </feed>
    </workspace>      
</atom-hopper-config>

Save the file and re-start Tomcat. Now you will have two valid paths:
http://localhost:8080/ah-war-0.9.2-SNAPSHOT/namespace1/feed1/
http://localhost:8080/ah-war-0.9.2-SNAPSHOT/namespace2/feed2/

Lets add an entry to each feed, for details how to do this with Poster see my original article.

Here is the XML for feed1:

<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">This is going to namespace1 and feed1</title>
  <updated>2011-10-06T21:39:49.904Z</updated>
  <author>
    <name>Chad</name>
  </author>
  <content type="text">Hello Feed 1</content>
</entry>

POST to this address (don’t forget to set the content type in Poster to: application/atom+xml ):

http://localhost:8080/ah-war-0.9.2-SNAPSHOT/namespace1/feed1/

Here is the XML for feed2:

<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">This is going to namespace2 and feed2</title>
  <author>
    <name>Chad</name>
  </author>
  <content type="text">Hello Feed 2</content>
</entry>

POST to this address (don’t forget to set the content type in Poster to: application/atom+xml ):

http://localhost:8080/ah-war-0.9.2-SNAPSHOT/namespace2/feed2/

Try each path (use Poster with GET) and notice how you can get your ATOM entries back from each feed.

If you find this project useful please add a comment or send me an email and let me know how your using Atom Hopper. Also, if you think you have something cool to contribute back to the project then please fork it and submit a pull request back. Please keep in mind this is a pre-1.0 release (as of this blog article) and bugs are still out there.

Post to Twitter

This entry was posted in Apache Abdera, Apache Tomcat, Atom Hopper, Java, Open Source. Bookmark the permalink.

One Response to Running Atom Hopper with Apache Tomcat

  1. Pingback: Using Atom Hopper | Giant Flying Saucer