Groovy Advice Needed for Shakespeare Web Service Client

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)
        proxy.initialize()
        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");
        System.out.println(client.getPlay());
        System.out.println(client.getSpeaker());
        System.out.println(client.getWords());
    }

}

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
MACBETH
ALL
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.

Comments:

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?

Cheers,
Marcus

Posted by marcus on December 12, 2011 at 11:10 PM PST #

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

http://stackoverflow.com/questions/3193228/problems-consuming-web-service-from-groovy-script

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

Marcus

Posted by Marcus on December 12, 2011 at 11:14 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
23
24
25
26
27
28
29
30
   
       
Today