September 13, 2006

Implementing the Atom Publishing Protocol

Writing about web page http://www.ietf.org/html.charters/atompub-charter.html

Yesterday I did a deploy of BlogBuilder that includes support for the Atom Publishing Protocol (APP). What this essentially means is that you can use a desktop client, a web service or your own programming to create, edit and delete entries from a Warwick Blog.

We chose the APP because the other blogging APIs out there are all a bit horrible really and the APP is new and shiny and relatively easy to understand and program for.

The implementation was not without its difficulties. For a start reference clients and servers are very thin on the ground at the moment as the spec is not actually 100% complete (although almost there). This meant a fair bit of time just getting my head around how it worked and sniffing traffic to spot what a working client and server actually did when they talked to each other.

In the end, with the help of the Atomic Client, Tim Bray’s Atom Protocol Exerciser and Elias Torres’s public server implementation I was able to get it all working…and here’s how I did it :)

We already used Rome in places for our Atom/RSS feed creation and parsing. It’s slightly tricky to get it to do everything you need to create an Atom Protocol server as you don’t always need to send and receive whole feeds. Sometimes you’ll just want to parse/create a single entry. This leads to code which manually creates or strips the feed around the single entry so that Rome can then parse it properly… blah.

As we’re a Spring shop here, I used a single MultiActionController to do all of the GET/POST/PUT/DELETE functionality that the Atom Protocol needs. You can easily map incoming requests to the right method with something like this MethodNameResolver:

public class HttpMethodTypeMethodResolver implements MethodNameResolver {

    private Map<String, String> methodMappings;

    public final String getHandlerMethodName(final HttpServletRequest request) throws NoSuchRequestHandlingMethodException {

        String method = request.getMethod().toUpperCase();

        if (methodMappings.containsKey(method)) {
            return methodMappings.get(method);
        }

        throw new NoSuchRequestHandlingMethodException(request);

    }

    public final String[] getSupportedMethods() {
        return methodMappings.keySet().toArray(new String[] {});
    }

    public final Map<String, String> getMethodMappings() {
        return methodMappings;
    }

    public final void setMethodMappings(final Map<String, String> methods) {
        this.methodMappings = methods;
    }

}

Then you just set this up to map your DELETE -> deleteEntry() method and PUT -> updateEntry() method and so on…

Another little thing with Rome is that you have to use the Atom specific parts of the API, you can’t just use the generic SyndFeed/SyndEntry classes as they do not convert to/from the exact Atom markup you need. So instead you need to use the Feed and Entry classes in the com.sun.syndication.feed.atom package.

So far I’ve only tested our implementation against Tim Bray’s APE and the Atomic client (which doesn’t send authentication headers when doing POST/PUT/DELETE operations so we could only really try it out with the GET stuff.

We’ll be trying it out against the new Office 2007 Atom client code later on today so it’ll be interesting to see if we need to tweak it a bit more (as I think everyone interprets the as to be completed standard a little differently).


- 6 comments by 4 or more people Not publicly viewable

[Skip to the latest comment]
  1. Steve Rumsby

    If I wanted to try posting from Office 2007, what would I use as the “Blog Post URL”?

    13 Sep 2006, 10:41

  2. Update: Unfortunately it doesn’t work.

    1) It will only occasionally actually go and try the service rather than whenever you make a change so it’s hard to tell when it is or isn’t even trying to do stuff
    2) If it gets back a response it doesn’t like it will sometimes just keep prompting for a password and you can never get rid of the popup so you have to kill Word to get out of it
    3) It looks like it uses the old protocol before the latest IETF draft so it doesn’t like the standard introspection XML that it gets back once it does work

    On the plus side, it does look quite easy to setup and manages the HTTPS Basic Auth ok…it’s just that is as far as it gets :(

    13 Sep 2006, 12:16

  3. Robert O'Toole

    Sounds useful. Are there any Pocket PC clients that will post to blogs using Atom?

    18 Sep 2006, 14:04

  4. Not that I know of…but I’ve not looked.

    18 Sep 2006, 15:09

  5. David Davies

    This is really cool. The latest generation of Nokia phones, I have an N73, uses Atom to post pictures from the built-in camera. I’ll try it and report back. I use WordPress for my main blog and am still waiting for Atom posting support so kudos to Warwick blogs.

    19 Sep 2006, 21:49

  6. Phil Wilson

    Could you not have used Abdera or contributed to it rather than writing your own from scratch? Or indeed Dave Johnson’s Blogapps stuff? I’m sure you’ve seen them already, but http://incubator.apache.org/abdera/ and https://blogapps.dev.java.net/ respectively.

    02 Nov 2006, 10:25


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

September 2006

Mo Tu We Th Fr Sa Su
Aug |  Today  | Oct
            1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30   

Tags

Search this blog

Most recent comments

  • One thing that was glossed over is that if you use Spring, there is a filter you can put in your XML… by Mathew Mannion on this entry
  • You are my hero. by Mathew Mannion on this entry
  • And may all your chickens come home to roost – in a nice fluffy organic, non–supermarket farmed kind… by Julie Moreton on this entry
  • Good luck I hope that you enjoy the new job! by on this entry
  • Good luck Kieran. :) by on this entry

Galleries

Not signed in
Sign in

Powered by BlogBuilder
© MMXXIII