Grails Challenge: Pens Down

Boy that 20 hours certainly went more quickly than expected… Actually SlimTimer is telling me that I’m at 21.3 hours, so it’s definitely time for pens down! I’ll factor in the final cleanup and deploy time to get a more accurate final figure for the go-live.

Tons of new features made it into the final release, though. Lets start with the more boring webby stuff, since that’s all part of the development deal too, and quite a time burner.

As promised last time, I ended up getting in those tabs using A List Apart’s sliding doors technique. Actually was much quicker than I expected since that technique only needs four images.

Tabs in action

Then I set to work on some nice box layouts for various things that run down the margin. While I was at it I put in a simple login div as a trial run:

Login Window in a spunky div

Then came some features I’ve been wanting for a while. Thanks to the generous folk at Nabble, they have allowed me to integrate their Grails and Groovy RSS feeds into groovyblogs. So I’ve not got a “List Buzz” tab so you can get a quick glance at what’s being talked about on the lists:

Lists courtesy of Nabble

I already had all the infrastructure to parse and present feeds, so it seems a shame not to include the lists in their own tab. I didn’t want to persist them, though, so I decided to use an in memory cache. ehcache is bundled with Grails, so it seemed like a good candidate. Decided to make it generic with a little Grails CacheService. Then I got to thinking…

If you’ve got a generic CacheService, why not cache some other useful stuff? So I now wrap the Popular, Recent and Feed links in the CacheService which means my hits on the db should be through the floor. Must get around to doing some profiling on that one…

[Read More]

Grails Challenge: 15 hour update

Just back from a week at the beach on hols and feeling fantastic. I must say that progress has been a lot slower in the second set of 7 hours but I’m still pretty on track for my 20 hour deadline. SlimTimer is reporting 14.8 hours on the clock, so I figure it must be time for an update.

RSS and Atom generation of “Recent Entries” is in and happening. Here’s a grab from Newzcrawler showing what an Aggregator should see:

Feeds in Newzcrawler

Full Text Search of entries using my Groogle code is now in place. Indexer will get tripped as new entry is added to the db, and have put some code in to do a nightly optimize to keep is tight.

Searching Indexed Entries

The Ajax preview feature of “Add a Blog” is slowly getting there (but still having some grief with Scriptaculous getting my visual effects happening. I’m a bit of a Javascript bunny, so everything takes a lot longer here than it should. It’s kinda gratifying to be able to add your URL and see GroovyBlogs nicely rendered a parse of your URL, but I’m not sure it’s really that useful. Good sample code, though.)

Implementation of “Hot Entries” is now in (which I am planning on making that “last 7 days” rather than “last 24 hours” based on the size of the Groovy blogosphere.). I’ve also implemented that “suppress more than 3 entries from same author” thing that Javablogs does.

I’ve come up with a nice taglib for doing “3 hours 14 minutes ago” or “30 minutes from now” date transformations. Very useful for the “Just In” and “Hot Entries” pages.

Wasted a stack of time on more GUI work including a site logo, a favicon (can recommend DynamicDrive’s cool little online tool) and color scheme work. I’m really working on improving my GUI skills, but it’s a long walk to freedom.

Favicon in a browser

[Read More]

Grails Challenge: 7 hour update

Ok. Creeping up on 6.7 hours working on my Grails-based Groovy Blog Aggregator and it’s time for an update on what’s done so far.

Ok. Quite a lot is in:

But you probably want pictures…

Groovy Blogs home page after 7 hours

Where have I burnt most of the time? I know a bit has certainly gone to CSS and Photoshop (those damn gradient backdrops…). Also burnt a fair bit of it working out how Rome handles Atom and RSS irregularities (still some XML encoding bugs in there to iron out at my end).

Also came across some issues in the remoteFormLink tag when using Yahoo as the underlying Ajax library. Retreated to Prototype version and life was good (must remember to log an issue on that one).

So things are definitely on track for my 20 hour timeframe… but everyone says that early in a project :-)

[Read More]

The Grails 20 hour Challenge...

So how much of a Community-driven Website could you build in 20 hours, once you’ve got a good feel for the framework? That’s my February Grails challenge…

I reckon I can find about 5 hours of “project” time a week (think wife/kids/dog/dayjob/uni/health - so 5 hours might be optimistic). I’m really keen to see what I could build in that timeframe over the course of February that would be useful to the Groovy and Grails community (you’ll also be able to download the src to as a good little sample app for learning when I’m done).

I’m going to use Slimtimer to keep my hours honest and get some good non-fudged metrics on my own productivity. I’m also going to be reusing code from my other Grails apps (it’s not cheating - you would too :-).

The plan is to have a crack at building a blog aggregator - a simple automated aggregator of Groovy and Grails related blogs in the same style as javablogs.com.

Not sure there are quite Groovy and Grails bloggers yet for a “hot entries” page, but we’ll work that all out as we go. I’m planning to post up grabs of my progress here once a week, so people can see just how much you can build in your spare time. Here’s how far I’ve got so far :-)

Early sketches of GroovyBlogs ideas

[Read More]

Grails on Glassfish is Go!

That’s right. Grails apps now play nice on Glassfish v1. Graham has been very patient about my regular nagging over GRAILS-269 , and true to his word, the new Grails 0.4 will indeed be Glassfish friendly.

This is sensational news for me, since I have been busting to run a few of my apps publicly for a while and had to resort to all sorts of dodgy workarounds getting Grails running on Jetty while the rest of my apps run on Glassfish.

For a first taste, try out my little Groogle test harness to see how you can add full text search to your Grails app. You can read more about how Groogle is implemented here and download the source if you’re super keen.

I found I had issues with straight Glassfish V1 b48 on Ubuntu (CPU went to 100% whenever I deployed an app), but I’ve had great success on the latest update release (UR1 P1) on both Win32 and Linux. Took the opportunity to upgrade to JDK 1.6 at the same time and everything is playing very nicely!

Huge props to Graham and the team for making Glassfish a first class option for Grails apps!

[Read More]

Hudson is one cool build tool...

I’ve been a long term fan of Anthill. It was always so much easier to configure than Cruise Control and, even though the feature set was slimmer, it did everything I needed in an automated build/continuous integration tool.

Lately, however, I’ve been taking Hudson for a spin as an Anthill replacement, and it has totally blown me away. The cool Ajaxy console window that keeps in sync with your build’s stdout as it happens, the RSS feed for builds, ability to easily see CVS mods for a particular build, integrated test reporting, and very easy to use and slick UI all combine for a killer automated build tool.

The other big sell is that there is no Unix command prompt fiddling required. The whole app installs as a single WAR - and everything can be configured with from a browser.

Just one gotcha for new players, you’ll want to set your app server’s environment to include a HUDSON_HOME (on Glassfish, use /Configuration/System Properties from the console as shown below), so you don’t end up with build artifacts in the scratch area of your deployed Hudson war. Once that’s done, just replace with the latest Hudson war as it comes out and all your settings will just keep on trucking.

Configuring HUDSON_HOME on Glassfish

Big props to the Hudson guys for a fantastic build tool that’s a snap to configure and use. Awesome stuff - my new automated build tool of choice!

[Read More]

PasswordSafeSWT 0.6 hits the streets

After a year of stuffing around, I’ve finally released PasswordSafeSWT 0.6 - my little Java port of the popular PasswordSafe password manager.

New in this release is long-awaited support for the v3 PWS database format, along with Mac OSX Universal binary support, and an update to SWT 3.2 which should fix some Linux display manager issues some people were having.

PasswordSafeSWT Startup Dialog

This release took sooo much longer than I thought it would, mostly because I tried to reuse the existing v1/2 classes and extend them to support the (entirely different) v3.0 database format.

Along the way I’ve learned a ton about Chaining Block Ciphers, SHA-256, JCE, and why the Bouncy Castle lightweight API can be a better choice than the standard option (Anyone for an “Unsupported keysize or algorithm“ exception?)

Feel free to download it from SourceForge, or have a browse of some screenshots on the various platforms.

[Read More]

Groogle: Adding a Simple Search facility to Grails

There’s been a some talk on the Grails list from different folk that are having a go at implementing a fulltext Search for their Grails application. Maurice has done a sensational job with integrating Compass, and looks like a fantastic platform for a future integrated Grails search capability.

Recently I’ve been using raw Lucene, and I have my hit hitlighting happening (including … ellipses for joining multiple hits in a single document), along with some snazzy search paging, and general Google-like goodness. Think of it as a “Cheap and Cheerful” search capability you can implement in a hurry on your current Grails app.

Here’s a grab of the beast in action. I’ve slurped in the RSS feeds of recent groovy and grails posts from Nabble to have some reasonable test data, but the harness lets you add your own documents to search against.

groogle Search Screen

My approach, while nowhere near as feature-packed or snazzy, just uses standard Grails domain classes, on which you add an “indexedFields” method. You then need to call index(), reindex(), and unindex() in your Controller classes, but even with those changes, you should be able to add full text search to your app in about 15 minutes. I thought I’d post up my progress so far which I hope to turn into a simple grails plugin for indexing - Groogle.

Implementing the search consists of a number of components that will be familiar to Grails developers:

  • SearchTagLib to give you handy g:searchBox, g:searchResults, and g:searchCrumbs
  • SearchService which does the heavy lifting of indexing, reindex, unindexing and searching your Grails documents using Lucene indexes

So how can you implement it for your own application? Well it’d be best to use a Groogle plugin, but we’re not there yet, so you’ll have to download the demo app and pull it apart yourself for now. Or wait a couple of weeks for a real plugin :-).

In general terms, what you’ll need to do is:

  1. Put a copy of lucene-core-2.0.0.jar and lucerne-highlight-2.0.0.jar into your project’s lib directory

  2. Add a indexedFields() method to domain classes that you want to be searchable. This method should return a map of the field names and values that you want to index.

  3. Add the SearchService to your service classes

  4. Copy the supporting Groovy classes out of /src/groovy into your own project’s /src/groovy.

  5. Inject the SearchService into any controller that creates or updates your domain class

  6. When calling save() or updating your domain class, make a call to searchService.index(myObj) or searchService.reindex(myObj) or searchService.unindex(myObj) as appropriate.

  7. Copy the SearchController and search.gsp into appropriate places in your project. Edit the g:searchBox tag in search.jsp to include the fields you want to search on.

[Read More]

Generating RSS Feeds with Grails and Rome

I’m currently working on a little Grails bug tracking application which should see the light of day on Sourceforge sometime in the new year. One of the features I just love about Jira is the RSS support - I’m always watching the Grails recently closed issues to see what’s been fixed in the SVN.

So I decided to see what’s involved in generating a feed. I could use the standard Groovy MarkupBuilder for sure, but then I’d have to work out the details for each of the XML formats in the common RSS and Atom formats. There has to be an easier way.

Enter ROME, a fantastic little library for generating ALL the common RSS feed formats. My goal was to have a controller action that takes a parameter for feed type so I could set up a bunch of links for the common cases. Turns out there’s a great tutorial to get you started. Using it from Grails makes it even simpler…

Copy your rome.jar file to your project/lib directory, create a new FeedController, and you’re off and running. Here’s a sample controller I’ve whipped up that generates a ton of standard feeds:


import com.sun.syndication.feed.synd.*;
import com.sun.syndication.io.SyndFeedOutput;

class FeedController {

    def supportedFormats = [ "rss_0.90", "rss_0.91", "rss_0.92", "rss_0.93", "rss_0.94", "rss_1.0", "rss_2.0", "atom_0.3"]

    def rss = {

            render(text: getFeed("rss_1.0"), contentType:"text/xml", encoding:"UTF-8")

    }

    def atom = {

            render(text: getFeed("atom_1.0"), contentType:"text/xml", encoding:"UTF-8")

    }

    // or specify your own feed type
    def all = {
            def format = params.id
            if (supportedFormats.contains(format)) {
        		render(text: getFeed(format), contentType:"text/xml", encoding:"UTF-8")
            } else {
                response.sendError(response.SC_FORBIDDEN);
            }
    }

    def getFeed(feedType) {

        def issues = Bug.list(max: 5, sort: "created", order: "desc")

        def entries = []
        issues.each { issue ->
            def desc = new SyndContentImpl(type: "text/plain", value: issue.description);
            def entry = new SyndEntryImpl(title: issue.name + " - " + issue.summary,
            		link: 'http://bugga.sf.net/issues/show/' + issue.name,
            		publishedDate: issue.created, description: desc);
            entries.add(entry);

        }
        SyndFeed feed = new SyndFeedImpl(feedType: feedType, title: 'Recently Closed Bugga Issues',
                link: 'http://bugga.sf.net', description: 'Bugga issues closed in the last few days',
                entries: entries);

        StringWriter writer = new StringWriter();
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed,writer);
        writer.close();

        return writer.toString();

    }

}

Then you just need to point your aggregator to http://localhost/bugga/feed/atom and you’re in business. Or if you want to use any of the supported feeds, head on over to http://localhost:8080/bugga/feed/all/rss_2.0 or whatever you fancy.

Here’s a grab from NewzCrawler:

Bugga Feed running in NewzCrawler

Props to the ROME team for a first class little library that does one thing very well.

[Read More]

Splash Screens with exe4j

I’m a long-time fan of exe4j for creating nice .exe launcher for Windows users. It costs a few bucks, and there are some great open source alternatives,  but exe4j is just so feature packed, I’ve never had to look elsewhere. Every time I think "It’d be good if exe4j  supported.." I find that it does.

This week’s adventure centred around designing a splash screen for PasswordSafeSWT, my little open source password manager. I’ve been putting off adding a splash because I’ve never quite worked out how to get one to display quickly enough to be useful (ie. to give the user feedback that they have in fact launched the app). I’d seen exe4j had a splash tab, so I figure I’d explore more (to at least give the windows users some feedback).

One of the first things I noticed was that you could specify your image file, but also  overlay your version numbers onto the image at runtime. How cool is that! After picking a few colours and font sizes, I was happily tinkering:

exe4j Splash Designer

exe4j has fantastic Ant integration, so I was already passing my version info for embedding into the final .exe. After a quick rebuild, my splash screen is up and running… with that new version info right where I left it… which still needs some alignment work :-)

PasswordSafeSWT spash screen in action

If you’re in the market for a very sharp exe maker, I can give exe4j 5 stars. Great stuff ej-technologies folk!

[Read More]

Creating dmg files from Ant

For my little password manager, I’ve long wanted to be able to automate the task of creating a .dmg file for my osx users. In fact, about 18 months ago when I was linking to a page describing the manual process, I was saying this should be ant-able.

Well since I’ve been doing a bunch of betas of the new version, I’m finally sick of creating .dmg files by hand and did some research on what’s required to drive the process from Ant.

The guys at Eclipse have done a sensational job of documenting some interesting mac integration goodies, including the hdiutil app which drives the commandline creation of dmg files. Wrap that guy in a little exec task, and life is pretty darn fine.

In the end, you’ve got something like:

<exec executable="hdiutil">

<arg line="create -srcfolder ${folder.containing.your.app} ${dist.dmg.file}"/>

</exec>

Which creates your dmg file from the folder containing your binary. Does the appropriate compression to ensure the dmg file is only big enough to hold your app. Just the ticket.

Driving all this from Ant makes the osx distro process so much quicker… Big props to the Eclipse dudes for writing this up. Has saved me a ton of time.

[Read More]

Glassfish, AWStats and Access Log Formats

I’ve finally found some time to get awstats setup to crunch my Glassfish logs. This turned out to be a little trickier than I expected, so I though I’d write up some gotchas incase other are walking the same path.

First up, you need to get Glassfish to write log files in a suiteable format for awstats. Glassfish gives you a nice admin GUI in /Configuration/HTTP Service/Access Logs where you can change the format of what’s logged. If you access this page, then click the Help menu, you’ll get a list of available parameters that you can insert.

Awstats likes the NCSA combined/XLF/ELF format, which you can whip up in Glassfish using the following format:

%client.name% %datetime% %request% %status% %response.length% %header.referer% %header.user-agent%

This is pretty close. It’ll get you to something like:

"123.456.7.89" "13/Nov/2006:14:22:25 +1000" "GET /common/images/feed-icon-16x16.png HTTP/1.1" 200 764 "[http://www.bytecode.com.au/passwordsafeswt/](http://www.bytecode.com.au/passwordsafeswt/)" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3"

But we’re still not quite there. Those quotes around the first ipaddress and date fields will cause you grief. So you need to strip them off. I’m using sed with a command like:

LogFile="sed -e 's/"([0-9.]*)"/1/g' -e 's/"([^"]*+1000)"/[1]/g'/path/to/glassfish/domains/domain1/logs/access/www.bytecode.com.au_access_log.%YYYY-0-%MM-0-%DD-12.txt |"

That guy will strip the quotes from the ipaddress, then reformat the datestamp to have no quotes and replace with square brackets. You’ll need to change the +1000 to whatever your GMT offset is as it appears in your logs.

Once you’ve done all that, you’re good to go. Setup a cron job to run awstats_updateall.pl early in the morning, then follow it with a awstats_buildstaticpages.pl to dump your stats into some docroot location and you’re ready to crunch.

[Read More]

Grails 0.3 ships with Freight Train Momentum

I figured something must be up when I saw that 31 outstanding bugs were fixed in the last 24 hours, then Graeme&nbsp;made the&nbsp;annoucement that Grails 0.3 was released and available for download.

If you’ve been on the sidelines waiting to check out Grails, now is an excellent time. There have been enormous functionality enhancements in 0.3 (particularly in GORM - the ORM stuff - which is now so cool), the documentation is just fantastic, and the mailing list is&nbsp;extremely active with tons of input from the actual committers, and heaps of openness to offering your own ideas on how things could be made more groovy.

I gave a talk to the Canberra JUG in Australia last Wednesday night, and it was packed. There are a lot of people watching Grails right now. It’s awesome to see. Someone asked me "How can you feel comfortable building commercial apps on 0.3?" I said, "It’s not about the numbers, it’s about having an active community that are moving and shaking. You’re more likely to get fixes when people are excited…." . The next question was about a paginate tag…. fixed last night in GRAILS-337.

Props to Graeme and all the team. Awesome effort!

[Read More]

Grails presento in Canberra - Win an IntelliJ license!

I’ll be giving a presentation tomorrow night at our Canberra Java User Group titled "Impatient Web Development with Grails".&nbsp; If you’re nearby, it’s gonna be a great night.

Thanks to the generous guys at Jetbrains, we’re also giving away a copy of the IntelliJ IDEA 6.0 and TeamCity&nbsp;to one lucky attendee.&nbsp; And we’re also grateful&nbsp;that the dudes from Sun and Borland will be putting on Beer and Pizza. You guys rock!

Should be a sensational night. If you’re in the area, make sure you drop by.

&nbsp;

&nbsp;

[Read More]

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.

[Read More]

Doing bytecode Kungfu with Javassist

Came across a situation today where I need to mock out a static method on&nbsp;one of Websphere’s&nbsp;classes to simulate a certain test case. Normally this kind of bad boy is pretty tricky since you’ve either got to wrap the vendor’s class with your own injectable wrapper, or provide your own impl for their interface. The call in question was:

WSSubject.getCallerSubject();

with WSSubject being a static and final class for good measure. No mocking of the interface possible, no subclassing tricks available; I thought it might be time to check out what is achievable with the various bytecode manipulation libraries to see if I could just change the single method I was interested in. Had a look at ASM and BCEL, and found myself in way too deep in bytecode semantics. In the end I came across Javassist which was at just the right level. Worked my way through the tutorial and I was good to go.

&nbsp;As long as you get to the class before the classloader does, you can go crazy: add methods, substitute in your own methods, add before and after interceptors, change field visibility, the whole nine yards. So I put in a little block in my test case’s static initialiser to hook myself into the process:

&nbsp;

    static {

        try {            ClassPool cp = ClassPool.getDefault();            CtClass cc = cp.get("com.ibm.websphere.security.auth.WSSubject");             CtMethod subjMethod = cc.getDeclaredMethod("getCallerSubject");            subjMethod.setBody(cp.get(MyTest.class.getName()).getDeclaredMethod("getCallerSubject"), null);            cc.toClass();        } catch (Exception e) {            e.printStackTrace();        }

    }

Grab a handle to the WSSubject class, grab a handle to the getCallerSubject() method, then use that setBody() call to insert your own method body in the mix. In my case, I call the getCallerSubject() on my test class to manufacture my own subject to return. Two words: Sen Sational.

Would probably have been a lot easier wrap the getSubject() call in my own injectable class, but&nbsp;it’s handy to know that all sorts of bytecode kungfu is possible if your motivated.

Big props to Javassist dudes.

[Read More]

Twofish, Cipher Block Chaining, and Bouncy Castle...

I’ve been hard at work on the lastest release of PasswordSafeSWT, my Java port of the popular Win32 password manager PasswordSafe. The biggest change in the new version is a completely overhauled file crypto (which, in part, uses 256bit TwoFish in Chaining Block Cipher mode, along with some HMAC-SHA256, and some standard SHA256).

Now, I’ve never been exposed to CBC before, so it was quite an interesting bit of work. With a chaining block cipher, "each block of plaintext is XORed with the previous ciphertext block before being encrypted" … effectively chaining the whole decryption process. Sweet.

Turns out that BouncyCastle has fantastic support for all the ciphers needed in the PasswordSafe format, but getting there needs some divergency from the standard JCE mechanism I’ve been used to. Try using it with large keys outside the US, and you’ll be greeted with:

java.lang.SecurityException: Unsupported keysize or algorithm parameters		at javax.crypto.Cipher.init(DashoA6275)

I didn’t want end users to have to go through downloading unrestricted policy files for the JREs, so I figured I’d just use the lightweight crypto library that comes with Bouncy Castle and bypass the whole JCE thing entirely.

Using things outside the JCE is a liitle more work, but you can get there if you don’t mind digging through the extensive examples they ship with. My TwoFish CBC ended up like this:

TwofishEngine tfe = new TwofishEngine();cipher = new CBCBlockCipher(tfe); 	KeyParameter kp = new KeyParameter(key);ParametersWithIV piv = new ParametersWithIV(kp, IV);cipher.init(forEncryption, piv);

Then the actual crypto was a one liner…

int len1 = cipher.processBlock(input, 0, out, 0); 

All very doable. Go Bouncy Castle! You guys rock!

[Read More]

In-Browser functional testing with Selenium

I’ve been wanting to get into functional testing for a while, but have just never worked up the enthusiasm for the whole "writing clicks as code" deal that you get with the current crop of http-based junit-like test frameworks.

But the other day a workmate put me onto Selenium, and I’ve got to say that its just sensational. I can record my scripts straight in the browser (screencast), do the level of asserts I need (title, button labels, etc) using a familiar right-click metaphor, and save a tiny html file as my script for later use. Plus all the tricky Javascript stuff that fires behind the scenes in our apps "just works" because you’re running in a real browser.

They apparently also have stuff for automating the process in your nightly build. Can’t wait to look at what we might be able to achieve in nightly functional tests using this bad boy.

Props to the boys at openqa for a stunning bit of work.

[Read More]

Implementing SAML 2.0 on the cheap...

This last year I’ve done more SAML than any man should. I’ve had&nbsp;a&nbsp;couple of clients doing federated identity and single signon stuff, and SAML is all the rage (actually, I’ve found it pretty great to work with once I got my head around XML C14N).

SAML 2.0 is new and shiny and vendors are still scrabling to build libraries to handle it, so to test interop, I built a little test harness. Originally it just used strings for the messages, but some of the messages are so verbose (with just the odd timestamp or url&nbsp;insertion here or there), it was time to make the switch to a templating language before escaping quote characters inside strings drove me crazy.

I’ve been meaning to play with Freemarker for a while, but I finally had a good excuse. I’ve tinkered with Velocity before, so the paradigm was familiar, but one thing I really like about Freemarker is how it can handle its context being a plain vanilla java.util.Map. It also crashes and burns if you don’t provide a value for one of the merge strings in the template (which for me is a good thing, though in the web context it might not be so sweet).

For doing the actual message signing, you can’t go past Apache XML Security. I’ve raved about it before, but it is just sensational. Spec complete, and very easy to work with.

So my little test harness scoops up one of my canned templates, merges in some timestamps and urls, output&nbsp;it all as a&nbsp;string, sends it to XML Security for the signatures, then ships it off to the big hairy vendor for validation. It also slurps in responses from the other end, validates the signature, and gives you feelgood output.

In the end I’ve got a pretty cool little interop app that I can validate a good subset of SAML 2.0 against the big iron. On the very cheap…

Great work Freemarker and XML Security dudes. Your libraries are awesome!

&nbsp;

[Read More]

Grails: Sending a file to the browser

I recently wanted to add the ability to export CSV files from my little Grails app directly to the browser with one of those "Save As…" numbers. Makes it very easy for clients to save a copy of their addressbook directly to their local disk, and reimport it later on.

I’m using opencsv for the heavy lifting so the CSV bit was a snack. The tricky bit was getting the browser to popup as a "Save As".&nbsp; Messing with content/type didn’t help me, so it was time to do some researching…. and there’s just a little magic required which Grails controllers make very simple.

So here’s the magic strings you’re looking for.

response.setHeader("Content-disposition", "attachment; filename=" +
    session.userid + ".csv");
render(contentType: "text/csv", text: sw.toString());

And that will give you:

Dynamic File Creation Screenshot

Giddy up. Just what I was after…

[Read More]

Recoving your iPhoto collection from an Emptied Trash... (there is hope!)

So what do you do when your small child erases your iPhoto collection? I guess you undelete from the trash… But what happens if you didn’t know your photo collection was in the trash and you emptied it? You go to your most recent backup. But what happens when your most recent backup is&nbsp;6 weeks old (you know, just before your newborn arrived?). You panic.

I’ve had a Mac Mini for over a year, and never had a drama with it. So when all my photos disappeared I felt sick in my stomach. I am so not battletested in this space - I’ve never had to be.

Anyways after some frantic hunting on the web I bought a copy of FileSalvage for OSX. It’s $99USD which is quite a sum… but really a very smart pricing model since the only time you need this tool is when you really need this tool. RIght Now. Before your OS starts using all of that "empty" space you just created.

Anyways, I set it off and a few hours later I had 23000 undeleted images called File001. I only needed ones from the last six weeks, so I ran the sensational PhotoToolCM to rename and redate the files based on the EXIF data that the camera stored inside the image and I was in business.

This story has a happy ending (not many of these sorts of things do). The newborn shots are back. All of them. Phew!

Now I plan to backup weekly…

[Read More]

Feeling a little comma-separated? Try opencsv 1.6...

Thanks to user-supplied patches, I’ve just uploaded opencsv 1.6 to Sourceforge - my Apache licensed two-class library for reading and writing CSV files. If you’re in the market for a CSV library and can’t be bothered with dealing with unusual edge cases, this might be the library for you.

This new release adds custom line terminators (which is pretty useful if you’re exporting CSV from your linux web server to Win32 clients). Thanks to Klaus Stafto and Jerry Vos for good work here.

This release also fixes an unusual edge case where quote characters are used in an element, but not in the first position.

Someone send me a patch for this second issue, which I’ve integrated, but have since lost the original email. Let me know who you are, and I’ll add you to the credits.

[Read More]

Making the switch to Glassfish

I’m a longtime Jetty user and a huge fan (it’s always been my appserver of choice and the stuff coming in Jetty 6.0 looks just amazing), but for my own sites (including this one), I’ve made the switch to Glassfish. I’ve heard so much good stuff about it lately it was time to take it for a proper workout.

The install was painless, and I had my apps redeployed on the appropriate virtual servers inside 30 minutes - and without a single restart. That’s pretty sensational stuff - mainly due to an outstanding web admin UI and a very comprehensive set of documentation.

One of the real killer features that people rave about with Glassfish is the hot deploy stuff. I’m going to be giving it a bit of a workout in that department with an upcoming Grails app, and I’m keen to keep my outages to a bare minimum. For all of the setup, I could do it all from the web UI, and I was so impressed that I didn’t need to bounce the server - adding domains, deploying and redeploying apps, adding new port listeners, all good.

I’m really keen to see how it holds up as a main site. I always ran Jetty using Supervise to handle the restarts when it inevidably fell over. With Glassfish, I have no such safety net, but it has quite a reputation for being rock solid, so we’ll see how I fare.

But I’m sure loving every second of that sweet web-based administration…

[Read More]

Grails + Yahoo Autocomplete = Giddy Up

My little grails SMS gateway is powering along. I’ve now integrated Yahoo autocomplete into my "New SMS" page and it works just great. Now my users can begin typing entries from their addressbook, and get that snazzy dropdown happening as they type. Even works with multiple elements when you type in a comma. Sample below:

Autocomplete in CyaThen.com

I’ve been really impressed with how customisable Yahoo have made it. You can wire up the datasource to be Ajax (which is the way I went since Grails makes the xml generation so easy), or an in-page array. You can apply all kinda fades and delays and caching and… well, check out their example page to see all the customise options.

Thought it might be useful to other grails guys to jot down the steps I needed to go through to get it happening. This only applied to Grails 0.2, the file might be already included in a future version.

1.&nbsp;You need to download the Yahoo components from sourceforge since Grails 0.2 didn’t include the autocomplete_min.js file that you need. Track down that file and copy it into the /web-app/js/yahoo directory in your grails app.

2. Edit the JavaScript TagLib.groovy and make sure the yahoo map is edited to include ‘yahoo/autocomplete-min’&nbsp; (note their is no .js on the end of that one)

3. Inside the view that you want&nbsp;to have an autocomplete field, edit your html <head> element to include <g:javascript library="yahoo" /> which will pull in all the Javascript you need.

4. Add a script element that will tell wire up your input element to your backend XML datasource. Here’s what mine looks like:

<script>
    var myDataSource = new YAHOO.widget.DS_XHR("search", ["person", "name"]);
    myDataSource.responseType = myDataSource.TYPE_XML;
    var myAutoComp = new YAHOO.widget.AutoComplete('numbers','customcontainer', myDataSource);
    myAutoComp.delimChar = ","
</script>

This piece of magic tells the yahoo component to call my "search" action, and expect the returned XML to have an array of "person" elements, each with a "name" field to display. The autocomplete line wires up that datasource to my "numbers" input box using the empty "customcontainer" DIV to display the funky slidy autocomplete list.

[Read More]