Geertjan's Blog

  • December 12, 2009

Groovy Advice Needed for Shakespeare Web Service Client

Geertjan Wielenga
Product Manager
What is the most efficient way to do this? Right now, I've pared my Groovy code down to this:
import groovyx.net.ws.WSClient
class ShakesWsClient {
String play, speaker, words
void findQuote(searchString){
def proxy = new WSClient("http://www.xmlme.com/WSShakespeare.asmx?WSDL", ShakesWsClient.class.classLoader)
def speech = new XmlParser().parseText(proxy.GetSpeech(searchString))
play = speech.PLAY.text()
speaker = speech.SPEAKER.text()
words = speech.text()

That allows me to get at the play, speaker, and text from my Java code as follows:

public class Demo {
public static void main(String[] args) {
ShakesWsClient client = new ShakesWsClient();
client.findQuote("fair is foul");

Ant output:

12 Dec 2009 4:04:10 PM org.apache.cxf.endpoint.dynamic.DynamicClientFactory outputDebug
INFO: Created classes: com.xmlme.webservices.GetSpeech, com.xmlme.webservices.GetSpeechResponse, com.xmlme.webservices.ObjectFactory
12 Dec 2009 4:04:11 PM groovyx.net.ws.AbstractCXFWSClient getBindingOperationInfo
WARNING: Using SOAP version: 1.1
Fair is foul, and foul is fair: Hover through the fog and filthy air.
BUILD SUCCESSFUL (total time: 6 seconds)

Anyone out there with suggestions for how to improve my Groovy code (even further)?

By the way, I believe that Groovy's web service support is the best thing about Groovy, especially if you mainly want to continue working in Java.

Join the discussion

Comments ( 2 )
  • marcus Tuesday, December 13, 2011

    Hi Geertjan.

    I'd love to see out of the box support for SOAP web services in Groovy, but as usual the appealing look example like your's doesn't even compile with Groovy 1.8.3: The import groovyx.net.ws.WSClient cannot be resolved.

    What am I missing here? Do I need a magic @Grab annotation?



  • Marcus Tuesday, December 13, 2011

    This reflects my experiences with magic Groovy libs promising 'easy SOAP service consumption':


    Don't use it. Just have a look at the development status of GroovyWS: dormant.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.