While testing out my little browser thumbnail service, I thought I’d throw together a little thumbnail Swing client to tinker with (I was super inspired by Geertjan’s work on Soap clients). You can type in a URL, invoke the Thumbnail service over XMLRPC, then have a look at the image returned:

Thumbnail client in action

If you’re keen for a play, download the latest XML RPC jar (I’m using v0.3), and copy it to your ~/.groovy/lib directory (or %USERPROFILE%.groovylib on Windows). Then fire up groovyConsole and cut and paste….

import groovy.net.xmlrpc.*

def server = new XMLRPCServerProxy("http://www.groovyblogs.org:7999")

def swing=new groovy.swing.SwingBuilder()

def frame=swing.frame(title: 'Thumbnail Service',
    preferredSize: [700, 500],
    background: java.awt.Color.lightGray) {
  vbox {
    panel {
    label 'Enter URL:'
        textField(id: 'url', columns: 40, "http://www.google.com.au/")
    button(text: "Get Thumb", actionPerformed: { event ->
        println "Retrieving URL: $swing.url.text"
        def thumbs = server.getThumbnail(swing.url.text)
        def large = new javax.swing.ImageIcon(thumbs[0])
        def small = new javax.swing.ImageIcon(thumbs[1])
        swing.smallicon.icon = small
        swing.bigicon.icon = large
    })
    }
    panel {
    label(id: 'smallicon')
    label(id:'bigicon')
    }
  }
}
frame.pack()
frame.show()

The service only exposes one method, getThumbnail(url) which returns an array of byte[]. The first element is the large thumbnail bytes, the second is the small one. The format returned is jpeg. Be patient, it can take a few seconds to return…

Once I have a public download of the thumbnail service code, I’ll cut the public API, but it’s a fun experiment of what you can do with a few lines of groovy plus some XMLRPC goodness!