Oct
28
2006

A very Groovy Morning Tea with Confluence, Groovy-XMLRPC and AntBuilder

When I found out that Confluence has an XMLRPC interface, and the Groovy had an XMLRPC module, I started to think of a very simple way to make sure people remember when they’re rostered on Morning Tea.

My criteria for the app was "What’s the simplest thing that could possible work?" I figured a morning tea page on the Wiki, with a table of dates and names. My script is cronned to run once a week, scrape the page, parse the table, convert names to email addresses, and send em a reminder.

I told a mate that I reckoned I could put something together inside a lunch hour. 20 minutes later I was good to go.

Confluence needs a username and password to logon, so just using a scraper was no good. Fortunately the XMLRPC interface is a snack. To slurp down a secure confluence page, you just grab a token, the make the appropriate getPage call:

import groovy.net.xmlrpc.*; def c = new XMLRPCServerProxy("http://yourhostname/confluence/rpc/xmlrpc") def token = c.confluence1.login("user","password")  def page = c.confluence1.getPage(token, "YourSpaceId" , "Morning Tea Roster") def content = page["content"]  

Once you’ve got a handle to the content, it’s just a matter of some regular expressions to parse out the names, and you’re ready to email.

Groovy’s AntBuilder makes email integration equally straightforward:

new AntBuilder().mail(    mailhost: 'yourmailhost',     subject: 'Morning Tea') {      from(address: 'glen.smith@yourdomain.com.au')      to (address: 'the.person@yourdomain.com.au')     message( 'morning tea is on you today' ) )

And you’re off and emailing. You’ve just gotta love scripting languages…

Props to Tug for the XMLRCP module, and to the Confluence boys for providing the interface. Top Stuff. If you guys are ever in Canberra, Australia, the next donut’s on me.

About the Author: Glen Smith

1 Comment + Add Comment

  • Tug mailed me the following super useful info:

    Hi Glen!

    Glad you found Groovy useful:)

    You can use a couple of Groovy features to make the code slightly less noisy:

    def c = new XMLRPCServerProxy('http://yourhostname/confluence/rpc/xmlrpc')
    
    c.confluence1.login('user','password')  {token -> 	def page = confluence1.getPage(token, 'YourSpaceId' , 'Morning Tea Roster') 	def content = page.content	..... }

    1/ if you pass a closure as the last parameter to an XML-RPC call then that closure is called with the result of the XML-RPC call as a parameter. In addition any calls inside the closure which cannot be resolved in the program scope are made against the XML-RPC server (so we can write ‘confluence1.getPage’ rather than ‘c.confluence1.getPage’).

    2/ page['content'] can be rewritten as page.content

     

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action