Groovy SOAP clients with ws-lite

21 Aug 2014, 4 minute read

When we needed to quickly build a proof-of-concept to test a set of SOAP services I thought: “this is perfect for Groovy, and it’s DSL support will mean talking to SOAP won’t require stub generation or any of that pain”. I was almost right.

SOAP is almost legacy, but it’s still the only way to interface with large enterprise systems, at least in healthcare. Just as I’ve come to accept that CSV is the way everyone sends lab and patient records (when they’re not exporting to Excel sheets), I wasn’t surprised when our project with MirthResults and MirthConnect only had SOAP calls to add patients to a component. No problem, I thought, just Google “Groovy SOAP” and I’ll be done in 10 minutes.

So, the top result is the Groovy SOAP documentation, which does say (although not very obviously) that it’s deprecated. That’s fine, it suggests its replacement, GroovyWS. But that page tells you to ‘be careful’ because the project is dormant. Not to worry, because it suggests looking at groovy-wslite. I’m already feeling like I’m entering the rabbit hole.

Fortunately groovy-wslite is an active project and has commits (at the time of writing) from just over a month ago. The DSL is pretty straightforward so I set about connecting to the target WSDL and then added basic authentication. The documentation for the project is quite sparse, so this post is an attempt to bring together the bits that I needed.

If you need anything other than ‘Basic’ HTTP autentication, stop right there. The project doesn’t seem to support ‘Digest’ or ‘NTLM’ authentication, so you might be better going for plain Java SOAP.

In a simple script, you can just grab the wslite dependency and connect in a couple of lines:

In the following gist I’ve abstracted the SOAP call away into its own method and then created a method for each SOAP call to give me a quick and easy interface to demo the SOAP calls from the console. Feel free to fork, copy, adapt to your own needs.