GroovyWS

Module Overview

If you need to quickly consume and/or publish WS-I compliant web services, GroovyWS can help you.

Installation

If you are online and using the latest groovy version, here is the no-brainer way to use GroovyWS:

import groovyx.net.ws.WSClient

@Grab(group='org.codehaus.groovy.modules', module='groovyws', version='0.5.0-SNAPSHOT')
def getProxy(wsdl, classLoader) {
  new WSClient(wsdl, classLoader)
}
proxy = getProxy("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader)
proxy.initialize()

result = proxy.CelsiusToFahrenheit(0)
println "You are probably freezing at ${result} degrees Farhenheit"

Make sure to have the correct GroovyWS grape config file

If you need more control, see the GroovyWS installation notes.

Getting Started

GroovyWS comes with two sets of APIS that are briefly described below using a simple example.

When your service is using groovy beans on the server side, you may want to control the fields that are serialized. This is done using a small xml file located next to your script. A small example is demonstrating this:

When consuming a web service, you may also be using some complex types. Those types are automatically generated from the WSDL, compiled and made available via your classloader. The client API is providing you a method to easily instantiate such a complex object from its name. Obviously, knowing the class name can be difficult when using a complex web service and may require to study the contract (WSDL). In order to help the user, GroovyWS is logging the names of the classes generated on the fly.

The client side integrates seamlessly with Grails applications.

There exists a lot of public web services. We provide two examples that show how easy it is to use GroovyWS to tap on these resources.

More WSClient configuration is available if you need to use proxies, basic authentication and security related features.

The javadoc is probably the ultimate place to the missing bits. If you are missing a feature email us user@groovy.codehaus.org.

Articles

  1. A nice article from Geertjan's blog with several examples: http://blogs.sun.com/geertjan/entry/groovy_web_service
  2. An article explaining the difference between the different WSDL styles http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/

They use GroovyWS

If you use GroovyWS, please let'us now and feel free too add a quote in this section.

Community

  • The build process is using gradle.  In order to build the sources from svn, just run:
     ./gradlew

    in the directory containing the source tree.

  • Feel free to contribute by testing, giving your feedback, reporting bugs and sending patches.

Labels

supporting supporting Delete
tools tools Delete
groovyws groovyws Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 03, 2008

    Jason Dyer says:

    If anyone is getting the "<x> doesnt contain ObjectFactory.class or jaxb.i...

    If anyone is getting the "<x> doesnt contain ObjectFactory.class or jaxb.index" on Linux, make sure you don't have 'ecj' installed.  If you do, run 'apt-get remove ecj' (or your package manager remove command) and try again. 

    (I discovered this after a lot of frustration and trial-and-error, so I thought it might be worth documenting.

    Note that I have no idea what removing ecj (eclipse java compiler?) might break...

  2. Apr 21, 2008

    Roger Hosier says:

    I'm neither a Java developer nor a Groovy developer really, but I need some poin...

    I'm neither a Java developer nor a Groovy developer really, but I need some pointers to understand where to look or perhaps even to stop looking for some things that I'd like to do related to GroovyWS. Thanks in advance for any advice or links that you have for me!

    What I want to go is have the user be able to enter in the URL of the WSDL. The process will then create the proxy, which appears to create all of the classes necessary for the client. I want to be able to display a list of the operations to the user for selection of the action they are interested in. Once the operation is selected the user will be shown the appropriate request variable and they can select the ones that they need to fill in and designate where the data will come from or literals if appropriate. The mapping of the response will be done similiarly to the request. Once that is done whenever the action is to be taken the operation will be invoked and the data mapping will take place as necessary.

    Are there any methods that I can use to extract the list of operations from the proxy once it's created or do I need to inspect the WSDL itself in an XML parser like XMLSlurper and get this information myself? It seems like a waste for me to have to interrogate the WSDL when it's pretty obvious that CXF has already done that.

    One of the head scratchers that I have still is with the namespace handling. What I don't want to do is show com.terraserver_usa.terraserver.Place.city to the end user for the mapping, I think that Place.city would be perfect, but I don't see any way of being able to get the actual name of the class for the proxy.create call. I've seen a few posting where folks have complained about getting the generated package.class name from the WSDL, but I would expect that at least the CXF layer would allow me to get this information easily if I had the approriate CXF "client" object and knew the correct methods to call.

  3. May 13, 2008

    Dan OBrien says:

    The simple MathService works for me, but the complex BookService doesn't. The c...

    The simple MathService works for me, but the complex BookService doesn't. The client gets this error:

    groovy bookClient.groovy
    May 9, 2008 8:14:05 AM org.apache.cxf.endpoint.dynamic.DynamicClientFactory outputDebug
    INFO: Created classes: defaultnamespace.AddBook, defaultnamespace.AddBookResponse, defaultnamespace.ArrayOfBook, defaultnamespace.Book, defaultnamespace.FindBook, defaultnamespace.FindBookResponse, defaultnamespace.GetBooks, defaultnamespace.GetBooksResponse, defaultnamespace.ObjectFactory
    BindingInfo = org.apache.cxf.binding.soap.model.SoapBindingInfo@13829d5
    o = SOAPBinding ({http://schemas.xmlsoap.org/wsdl/soap/} binding):
    required=null
    transportURI=[http://schemas.xmlsoap.org/soap/http]
    style=document
    defaultnamespace.ArrayOfBook@baa31b
    Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Groovy in Action' with class 'java.lang.String' to class 'javax.xml.bind.JAXBElement'
    at bookClient.run(bookClient.groovy:11)
    at bookClient.main(bookClient.groovy)
  4. Jun 24, 2008

    Danilo Araya says:

    Hello World... When i set up a client to the following WSDL http://siagfqa.pap...

    Hello World...

    When i set up a client to the following WSDL

    http://siagfqa.paperless.cl:8083/axis2/services/ExtincionReconocimiento?wsdl

    using

    def extincion = new WSClient("http://siagfqa.paperless.cl:8083/axis2/services/ExtincionReconocimiento?wsdl", this.class.classLoader)

    i'm getting the following error

    Caused by: org.xml.sax.SAXParseException: A class/interface with the same name "
    cl.paperless.siagf.ws.Exception" is already in use. Use a class customization to
     resolve this conflict.

     Does anybody knows how to fix it?

  5. Jul 17, 2008

    Kirk Brocas says:

    This all looks great. One question though: will it support SMTP as a transport m...

    This all looks great. One question though: will it support SMTP as a transport mechanism like SOAP? CXF doesn't appear to support SMTP as transport.

  6. Oct 14, 2008

    Cazacu Mihai says:

    How about security support (like X509 certificates) ? Good job!  Keep...

    How about security support (like X509 certificates) ?

    Good job!  Keep moving!

  7. Nov 18, 2008

    wanggang says:

    hi! Why did the object of Book can be generated by the following code? ...

    hi! Why did the object of Book can be generated by the following code?

    Thread.currentThread().getContextClassLoader().loadClass(name).newInstance()

    thanks! 

  8. Nov 19, 2008

    wanggang says:

    Hi,galleon! the new version of groovyws is conflicted with Spring.If there i...

    Hi,galleon! the new version of groovyws is conflicted with Spring.If there is spring.jar,we will get the following error when running the tests:

    java.lang.NoClassDefFoundError: com/sun/xml/fastinfoset/stax/StAXDocumentParser
  9. Feb 03

    Sergey Bondarenko says:

    to David Sosby: I found some sources here:http://svn.codehaus.org/gmod/groovyws...

    to David Sosby:

    I found some sources here:http://svn.codehaus.org/gmod/groovyws/

  10. Feb 16

    olivier FRESSE says:

    I've updated the sources link My biggest issue with this module is to set the c...

    I've updated the sources link

    My biggest issue with this module is to set the client timeout...

    The web services I use takes a long time to perform a background operation. And no way to set the timeout value.

    (known issue : http://jira.codehaus.org/browse/GMOD-50?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel )

    I'm afraid I'll have to take a look in the code ...

     

  11. May 28

    Christian Posta says:

    Have others been able to get this to work recently? Seems like any of the wiki...

    Have others been able to get this to work recently?

    Seems like any of the wiki pages that I've seen that explain how to use Groovy and web services are outdated and the examples do not work. Furthermore, the documentation is very weak and offers no links for helping to debug any problems that may arise.

    Can anyone help? I am new to Groovy, and I like what I've seen so far, but I get so frustrated when the documentation is all outdated.

    The code on this page under the 'Installation' *does not work*. And by does not work, I mean I copied the code verbatim, I have the latest version of Groovy (1.6.3), and I copied the grape config file as instructed, and it returns 'dependency errors'. I have no idea how to resolve this, which is why I'm posting:

    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, General error during conversion: Error grabbing Grapes -- [unresolved dependency: org.apache.abdera#abdera-core;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-i18n;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-parser;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-json;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-main;0.4.0-incubating: not found, download failed: org.apache.santuario#xmlsec;1.4.2!xmlsec.jar, download failed: xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]

    java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.apache.abdera#abdera-core;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-i18n;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-parser;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-json;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-main;0.4.0-incubating: not found, download failed: org.apache.santuario#xmlsec;1.4.2!xmlsec.jar, download failed: xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
        at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
        at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:258)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:225)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
        at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:330)
        at groovy.grape.GrapeIvy$resolve.callCurrent(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:159)
        at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:213)
        at groovy.grape.Grape.grab(Grape.java:145)
        at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:180)
        at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:268)
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:798)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:278)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:249)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:189)
        at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
        at java.security.AccessController.doPrivileged(Native Method)
        at groovy.lang.GroovyShell.run(GroovyShell.java:202)
        at groovy.lang.GroovyShell.run(GroovyShell.java:147)
        at groovy.ui.GroovyMain.processOnce(GroovyMain.java:493)
        at groovy.ui.GroovyMain.run(GroovyMain.java:308)
        at groovy.ui.GroovyMain.process(GroovyMain.java:294)
        at groovy.ui.GroovyMain.processArgs(GroovyMain.java:111)
        at groovy.ui.GroovyMain.main(GroovyMain.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)

    1 error
     

  12. Jun 22

    Cazacu Mihai says:

    Thanks Jason for your advice. Removing the "ecj" package was the solution.

    Thanks Jason for your advice. Removing the "ecj" package was the solution.

  13. Jul 02

    John Langley says:

    Replying to Christian's post... no! It didn't work this morning when I tried...

    Replying to Christian's post... no! It didn't work this morning when I tried it following the directions here. I get a similar error:

    jlangley@prospero:$ groovyc temp.groovy
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, General error during conversion: Error grabbing Grapes -- [unresolved dependency: org.apache.abdera#abdera-core;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-i18n;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-parser;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-json;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-main;0.4.0-incubating: not found, download failed: org.apache.santuario#xmlsec;1.4.2!xmlsec.jar, download failed: xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]

    java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.apache.abdera#abdera-core;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-i18n;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-parser;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-json;0.4.0-incubating: not found, unresolved dependency: org.apache.abdera#abdera-extensions-main;0.4.0-incubating: not found, download failed: org.apache.santuario#xmlsec;1.4.2!xmlsec.jar, download failed: xalan#xalan;2.7.1!xalan.jar, download failed: xalan#serializer;2.7.1!serializer.jar]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
            at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
            at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:52)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:192)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:200)
            at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:258)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:225)
            at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
            at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:330)
            at groovy.grape.GrapeIvy$resolve.callCurrent(Unknown Source)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:159)
            at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:213)
            at groovy.grape.Grape.grab(Grape.java:145)
            at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:180)
            at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:268)
            at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:798)
            at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
            at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:443)
            at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:57)
            at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:173)
            at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:141)
            at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:155)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
            at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)

    1 error

    And that was after updating my ~/.groovy/grapeConfig.xml as per instructions (with a cut and paste)