Groovy Web Service

Long cherished dream of mine, reverberating through the darker corners of my innermost thoughts... figuring out how to consume a web service in Groovy. "A web service? In Groovy? That must mean you use the same standard Java libraries for JAX-WS, or JAX-RPC, generate client stubs and then use them to connect to the web service, right?" Wrong. Forget stubs. Groovy provides its own library for web services. Just to simplify the life of developers, since it is incredibly lightweight and gets the job done painlessly. And there are no stubs.

Everything, though slightly out of date, is described here:

Groovy Web Services

I tried the final example, with success. Here's my Groovy script:

import groovyx.net.ws.WSClient

class TryIt {
    
    groovy.swing.SwingBuilder swing = new groovy.swing.SwingBuilder()
    
    def proxy = new WSClient("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL", TryIt.class.classLoader)
    def currency = ['USD', 'EUR', 'CAD', 'GBP', 'AUD', 'SGD']
    def rate = 0.0

    void main() {

        def refresh = swing.action(
          name:'Refresh',
          closure:this.&refreshText,
          mnemonic:'R'
        )

        def frame = swing.frame(title:'Currency Demo') {
          panel {
            label 'Currency rate from '
            comboBox(id:'from', items:currency)
            label ' to '
            comboBox(id:'to', items:currency)
            label ' is '
            textField(id:'currency', columns:10, rate.toString())
            button(text:'Go !', action:refresh)
          }
        }
        frame.pack()
        frame.show()
        
    }
    
    def refreshText(event) {
          rate = proxy.ConversionRate(swing.from.getSelectedItem(), swing.to.getSelectedItem())
          swing.currency.text = rate
    }
    
}

It's incredible that this is literally all the code that you need. Nothing more in any shape or form. No configuration files, no stubs, no XML, no anything else. The above is almost the same as in the original document referred to above, but slightly tweaked (e.g., the 'def' keyword had been omitted in a few places). When I call the above class from a Java class (since NetBeans IDE doesn't support the running of Groovy classes, just Groovy scripts), the following Swing form appears, created from the SwingBuilder code above:

Then I enter a number (in the above case, I typed '500.00') and press Refresh. A number that doesn't make much sense to me returns, but that's how things go with web services over which you have no control. They're just black boxes, spewing something back to you upon request:

To set this up in NetBeans IDE, apart from creating the Groovy class in a Groovy file and calling it from a Java class, you need to be aware of the following:

  • Make sure to include the groovyws JAR when you compile, otherwise compilation will fail, since you're using Groovy's WSClient class:

    <target name="groovyc" description="groovyc">
        <taskdef name="groovyc" 
                 classpath="lib/groovy-all-1.1-rc-2-SNAPSHOT.jar" 
                 classname="org.codehaus.groovy.ant.Groovyc"/>
        <groovyc srcdir="${src.dir}" destdir="groovy">
            <classpath path="lib/groovy-all-1.1-rc-2-SNAPSHOT.jar"/>
            <classpath path="lib/groovyws-all-0.1.jar"/>
        </groovyc>
    </target>

    I can't remember where I got that JAR from. I googled a lot and found it referred to somewhere, after groovyws-standalone.jar turned out to not include everything I needed. (But maybe I'm wrong, I'll check this.) Now that you know it is called groovyws-all-0.1.jar, you should be able to find it. (Would be cool if it were bundled with the standard Groovy distribution.)

  • If you're using JDK 6, you need to set the endorsed dir, in the Run panel, in the Project Properties dialog box:

    -Djava.endorsed.dirs=copy the value of jaxws.endorsed.dir from nbproject/private.properties

  • You need ant-1.7.0.jar and the Groovy 1.1 JAR (or some other version of the Groovy 1.1 JAR) in your application's Libraries node.

And, I think, that's it. One thing thing I'm going to try is to get the Daily Dilbert web service to return comics via Groovy, as above, although I suspect I may end up in trouble with the images. But, before beginning that, I did a bit of tweaking, and not much later I now have the world's simplest web service client:

import groovyx.net.ws.WSClient

class TryIt {
    
    groovy.swing.SwingBuilder swing = new groovy.swing.SwingBuilder()
    
    def proxy = new WSClient("http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL", TryIt.class.classLoader)
        
    void main() {

        def frame = swing.frame(title:'Thought for the Day') {
          panel {
            label(proxy.ForToday())
          }
        }
        
        frame.pack()
        frame.show()
        
    }
        
}

The above (which is NOT a snippet, it is the entire web service client), results in this when I run it:

And here's one that's a bit more interactive, similar to the first one, but this time sending snippets of Shakespeare to a web service in order to retrieve full speeches, which has been referred to several times before in this blog:

import groovyx.net.ws.WSClient
import java.awt.BorderLayout

class TryIt {
    
    groovy.swing.SwingBuilder swing = new groovy.swing.SwingBuilder()
    
    def proxy = new WSClient("http://www.xmlme.com/WSShakespeare.asmx?WSDL", TryIt.class.classLoader)
        
    void main() {

        def frame = swing.frame(title:'Shakespeare',size:[300,300]) {
          panel(layout: new BorderLayout()) {
            textField(id:'quote',constraints: BorderLayout.CENTER, "fair is foul")
            textArea (id:'area',constraints: BorderLayout.NORTH, proxy.GetSpeech(swing.quote.text).replaceAll("><",">\\n   <"))
            button(constraints: BorderLayout.SOUTH,"Search",action:refresh)
          }
        }
        
        frame.pack()
        frame.show()
        
    }
    
    def refresh = swing.action(
          name:'Refresh',
          closure:this.&refreshText,
          mnemonic:'R'
    )
    
    def refreshText(event) {
          def newQuote = proxy.GetSpeech(swing.quote.text)
          swing.area.text = newQuote.replaceAll("><",">\\n   <")
    }
        
}

Clearly, it's all really cool and lightweight. I can imagine it can be very useful for doing quick tests as part of a larger process. But the above would make sense in a production environment too, I reckon. Why consume web services the hard way if you can do it the easy way? For all details on this, see the aforementioned page, which seems to be the only one that describes this cool Groovy feature.

In other news. Put 13949712720901ForOSX in your blog to let Apple know that you want Java 6 support in Mac OS, as described here! And then go here to see all the other people who have already done so...

Comments:

Nice post. Remember to register your RSS Feed on Groovy Blogs (http://www.groovyblogs.org), this way it will be available for the Groovy community.

Posted by Antonio Goncalves on November 03, 2007 at 10:14 PM PDT #

Done!

Posted by Geertjan on November 03, 2007 at 10:19 PM PDT #

Have you tried this with the terra service?
http://terraservice.net/TerraService.asmx?WSDL

I get an error as soon as I define the proxy with that WSDL;

INFO: Created classes: com.terraserver_usa.terraserver.AreaBoundingBox, com.terraserver_usa.terraserver.AreaCoordinate,
...
com.terraserver_usa.terraserver.UtmPt

org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.endpoint.dynamic.TypeClassInitializer.begin(TypeClassInitializer.java:94)
at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:74)
at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:95)
at org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:48)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:250)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:138)
at groovyx.net.ws.WSClient.<init>(WSClient.java:96)
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:494)
at org.codehaus.groovy.runtime.MetaClassHelper.doConstructorInvoke(MetaClassHelper.java:562)
at groovy.lang.MetaClassImpl.doConstructorInvoke(MetaClassImpl.java:1756)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:758)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:688)
at org.codehaus.groovy.runtime.Invoker.invokeConstructorOf(Invoker.java:163)
at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:140)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeNewN(ScriptBytecodeAdapter.java:243)
at wsterra.main(wsterra.groovy:7)
Caused by: java.lang.ClassNotFoundException: byte[]
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

Posted by sean d on November 07, 2007 at 01:46 AM PST #

I tried to connect to local Jira, but no luck... I got exception with creating proxy:
java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:98)
at java.util.XMLUtils.getLoadingDoc(XMLUtils.java:75)
at java.util.XMLUtils.load(XMLUtils.java:57)
at java.util.Properties.loadFromXML(Properties.java:701)
at org.apache.cxf.common.util.PropertiesLoaderUtils.loadAllProperties(PropertiesLoaderUtils.java:71)
at org.apache.cxf.wsdl11.WSDLManagerImpl.registerInitialExtensions(WSDLManagerImpl.java:209)
at org.apache.cxf.wsdl11.WSDLManagerImpl.<init>(WSDLManagerImpl.java:97)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

Posted by mare on November 12, 2007 at 05:05 AM PST #

I found out I'm not the only one:

http://www.nabble.com/groovy-grails%2C-CXF-and-generated-classes-tf4700854.html#a13523267

Posted by mare on November 12, 2007 at 05:16 AM PST #

I put some examples of using GroovyWS with Terra on GrrovyWS web sites

Posted by tog on November 25, 2007 at 01:15 AM PST #

I am very interested in GroovyWS and your blog is very helpful to me, but I can't find groovyws-all-0.1 jar in the web.
Could you help me to locate it?

Best regards,
Gacgde

Posted by gacgde on November 29, 2007 at 10:25 PM PST #

Just go here and download it there, it has a different name now, but does the same:
http://groovy.codehaus.org/GroovyWS

Posted by Geertjan on November 29, 2007 at 10:28 PM PST #

Thank you for the link.
But I get this error message when connecting to a service somebody has designed in my company:
Unable to create JAXBContext for generated packages: "generated" doesn’t contain ObjectFactory.class or jaxb.index.
Before this error message, in the list of generated classes, the right name DataModel.ObjectFactory appears. Then why does JAXB 2.1 looks for a "generated" class? Any idea?
I have tested with Java 1.5 or 1.6, Groovy 1.1.rc2 or rc3.
Thanks,
Gacgde

Posted by JAXB 2.1 issue? on November 30, 2007 at 04:34 AM PST #

Geertjan,
I'm getting the same problem :

AXBContext for generated packages: "generated" doesn’t contain ObjectFactory.class or jaxb.index.

Did you find a solution ?
thanks,
Tom

Posted by Tom Duerr on January 28, 2008 at 11:38 PM PST #

I tried using GroovyWS in linux and it works
perfect, but when i try to use it with Windows,
I get the following error:

[ERROR] IOException during exec() of compiler "javac". Check your path environment variable.

My JAVA_HOME and GROOVY_HOME are both set and
JAVA_HOME\\bin is in my path.

Any suggestions?

Posted by Schwame on March 28, 2008 at 02:20 AM PDT #

Suggestion: stop using Windows. :-)

Posted by Geertjan on March 28, 2008 at 02:26 AM PDT #

I tried to get the BookService (from the Groovy site) to work. I'm getting the following exception in client code:
Exception thrown: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Groovy in Action' with class 'java.lang.String' to class 'javax.xml.bind.JAXBElement'

Using Groovy 1.5.5 and groovyws-standalone-0.3.1.jar

I can get simple WS to work fine.

This is occuring when the code is trying to set the title of the book.

This seems to be a problem with using the Book class. I removed the "defaultnamespace" and got a Book object that worked until the addBook method was called. It would fail silently and never call the service.

All of the code is in the same dir on the same machine.

Posted by Dale Frye on April 25, 2008 at 07:01 AM PDT #

Hi Geertjan,

do you have any experience with webservice authentication? I try to get a webservice running with authentication but I get alway this error:

No such property: user for class: groovyx.net.ws.WSClient

WSClient client = new WSClient("http://localhost:8080/imap/services/ReportService?wsdl", this.class.classLoader)
client.user="user"
client.password="password"

I don´t find a running example for this on the web

Thx

Alwin

Posted by Alwin on May 06, 2008 at 06:31 PM PDT #

Hi Tom,

i had the same problem trying the example using windows. The solution can be found reading the error message: "Check your path environment variable."

After adding the jdk/bin directory to the system path - all works great. Could it be that your JAVA_HOME points to a JRE instead of a JDK?

Posted by dirksan on June 05, 2008 at 05:30 AM PDT #

Hi Geertjan,
Im trying to use ur code in a Desktop application ..u r using def is this a class or interface ,and reply with breif about its imports. and little information about proxy.ConversionRate() method

Thanks in advance
with regards
vivek.k

Posted by vivek on August 06, 2008 at 09:19 PM PDT #

I am having an error when I try to use a local WSDL and a local schema with local paths, all in the same directory ... Any idea?

The code ...

def proxy = new WSClient("SLCATALOG.wsdl", this.class.classLoader)

def cats = proxy.QuerySLCATALOG()

for (cat in cats) println cat

The WSDL ...

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mx="http://www.ibm.com/maximo" xmlns:mxws="http://www.ibm.com/maximo/wsdl/SLCATALOG" targetNamespace="http://www.ibm.com/maximo/wsdl/SLCATALOG" name="SLCATALOG">
<types>
<xsd:schema>
<xsd:import namespace="http://www.ibm.com/maximo" schemaLocation="SLCATALOGService.xsd" />
</xsd:schema>
< ....>

The error ...

java.lang.RuntimeException: Error compiling schema from WSDL at {SLCATALOG.wsdl}: Unable to resolve relative URI SLCATALOGService.xsd because base URI is not absolute: SLCATALOG.wsdl#types1
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.error(DynamicClientFactory.java:418)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.error(SchemaCompilerImpl.java:280)
at com.sun.tools.xjc.util.ErrorReceiverFilter.error(ErrorReceiverFilter.java:77)
at com.sun.xml.xsom.impl.parser.ParserContext$2.error(ParserContext.java:166)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.resolveRelativeURL(NGCCRuntimeEx.java:179)
at com.su .....

Posted by Heiko Ludwig on September 22, 2008 at 05:24 PM PDT #

I wanted to test the groovy-code of the 'TerraServer-USA by Microsoft'
example.

But invoking the proxy gives the folloing error:

30.09.2008 20:56:34 org.apache.cxf.endpoint.dynamic.DynamicClientFactory
outputDebug
INFO: Created classes: com.terraserver_usa.terraserver.AreaBoundingBox,
com.terraserver_usa.terraserver.AreaCoordinate,
com.terraserver_usa.terraserver.ArrayOfOverlappingThemeInfo,
com.terraserver_usa.terraserver.ArrayOfPlaceFacts,
com.terraserver_usa.terraserver.ArrayOfThemeBoundingBox,
com.terraserver_usa.terraserver.ConvertLonLatPtToNearestPlace,
com.terraserver_usa.terraserver.ConvertLonLatPtToNearestPlaceResponse,
com.terraserver_usa.terraserver.ConvertLonLatPtToUtmPt,
com.terraserver_usa.terraserver.ConvertLonLatPtToUtmPtResponse,
com.terraserver_usa.terraserver.ConvertPlaceToLonLatPt,
com.terraserver_usa.terraserver.ConvertPlaceToLonLatPtResponse,
com.terraserver_usa.terraserver.ConvertUtmPtToLonLatPt,
com.terraserver_usa.terraserver.ConvertUtmPtToLonLatPtResponse,
com.terraserver_usa.terraserver.CountPlacesInRect,
com.terraserver_usa.terraserver.CountPlacesInRectResponse,
com.terraserver_usa.terraserver.GetAreaFromPt,
com.terraserver_usa.terraserver.GetAreaFromPtResponse,
com.terraserver_usa.terraserver.GetAreaFromRect,
com.terraserver_usa.terraserver.GetAreaFromRectResponse,
com.terraserver_usa.terraserver.GetAreaFromTileId,
com.terraserver_usa.terraserver.GetAreaFromTileIdResponse,
com.terraserver_usa.terraserver.GetLatLonMetrics,
com.terraserver_usa.terraserver.GetLatLonMetricsResponse,
com.terraserver_usa.terraserver.GetPlaceFacts,
com.terraserver_usa.terraserver.GetPlaceFactsResponse,
com.terraserver_usa.terraserver.GetPlaceList,
com.terraserver_usa.terraserver.GetPlaceListInRect,
com.terraserver_usa.terraserver.GetPlaceListInRectResponse,
com.terraserver_usa.terraserver.GetPlaceListResponse,
com.terraserver_usa.terraserver.GetTheme,
com.terraserver_usa.terraserver.GetThemeResponse,
com.terraserver_usa.terraserver.GetTile,
com.terraserver_usa.terraserver.GetTileMetaFromLonLatPt,
com.terraserver_usa.terraserver.GetTileMetaFromLonLatPtResponse,
com.terraserver_usa.terraserver.GetTileMetaFromTileId,
com.terraserver_usa.terraserver.GetTileMetaFromTileIdResponse,
com.terraserver_usa.terraserver.GetTileResponse,
com.terraserver_usa.terraserver.LonLatPt,
com.terraserver_usa.terraserver.LonLatPtOffset,
com.terraserver_usa.terraserver.ObjectFactory,
com.terraserver_usa.terraserver.OverlappingThemeInfo,
com.terraserver_usa.terraserver.Place,
com.terraserver_usa.terraserver.PlaceFacts,
com.terraserver_usa.terraserver.PlaceType,
com.terraserver_usa.terraserver.ProjectionType,
com.terraserver_usa.terraserver.Scale, com.terraserver_usa.terraserver.Theme,
com.terraserver_usa.terraserver.ThemeBoundingBox,
com.terraserver_usa.terraserver.ThemeInfo,
com.terraserver_usa.terraserver.TileId,
com.terraserver_usa.terraserver.TileMeta,
com.terraserver_usa.terraserver.UtmPt
BindingInfo = org.apache.cxf.binding.soap.model.SoapBindingInfo@1d183b7
o = SOAPBinding ({http://schemas.xmlsoap.org/wsdl/soap/}binding):
required=null
transportURI=http://schemas.xmlsoap.org/soap/http
style=document
Caught: java.lang.NoSuchMethodError:
org.codehaus.groovy.runtime.InvokerHelper.asArray(Ljava/lang/Object;)
[Ljava/lang/Object;
        at wsTest.run(wsTest.groovy:15)
        at wsTest.main(wsTest.groovy)

I've tried the 0.3.1 version of both the standalone and the all-jar with the
same result.
(I'm using Groovy Version: 1.5.0 JVM: 10.0-b23)

I would very much appreciate any hints about this problem!

Posted by Wyss Remo on September 30, 2008 at 05:25 AM PDT #

See here for help, Wyss:
http://blogs.sun.com/geertjan/entry/groovy_web_services_and_org

Posted by Geertjan on September 30, 2008 at 05:42 AM PDT #

I don't understand why your main methods are
void main()
they are normally
static main()
in Groovy
or better yet just omit the main method and put those statements outside the class definition altogether as is done here:
http://groovy.codehaus.org/GroovyWS

Posted by Jeremy Leipzig on October 02, 2008 at 12:00 AM PDT #

Has anyone had any success getting GroovyWS to work with attachments? It seems fine for simple WS requests, but when I try to call a WS and include an attachment I get an error starting like this:

16/10/2008 16:24:22 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: java.lang.NullPointerException
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:174)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:131)

Posted by Rick on October 15, 2008 at 05:05 PM PDT #

>Unable to create JAXBContext for generated
>packages: "generated" doesn’t contain
>ObjectFactory.class or jaxb.index.

This is was a bug in Apache CXF, but I am not sure if the fix has yet propagated to Groovy WSClient. I suppose you could rebuild it from source but who has time for that?

Posted by Jeremy Leipzig on October 31, 2008 at 04:42 AM PDT #

Hi, I'm trying GroovyWS with the examples on the groovy site (http://groovy.codehaus.org/GroovyWS). I'm using the groovyConsole to try groovyWS, I've donwloaded the groovyws-standalone-0.4.jar and put it into C:\\groovy-1.0\\lib, and everytime I try to run an example I get en error on proxy.create(), what I'm doing wrong? thanks!

[TerraServer-USA by Microsoft example]

java.lang.NullPointerException
at groovyx.net.ws.WSClient.create(WSClient.java:254)
at gjdk.groovyx.net.ws.WSClient_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:131)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecodeAdapter.java:211)
at Script11.run(Script11:4)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:484)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:425)
at gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:131)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:503)
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:585)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
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:585)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at groovy.lang.Closure.call(Closure.java:188)
at groovy.lang.Closure.call(Closure.java:183)
at groovy.lang.Closure.run(Closure.java:264)
at java.lang.Thread.run(Thread.java:595)

Posted by pablo on November 30, 2008 at 01:23 AM PST #

Pablo, need a proxy.create() after WSClient instantiation (new CXF version impose it)

And if you're using JDK6 you don't need to set the endorsed dir.

Posted by Manu on January 06, 2009 at 05:15 PM PST #

Yo can download SoaMoa unde http://www.soamoa.org/download.html and let create the groovy script

Posted by Ridvan Yesiltepe on February 22, 2009 at 02:23 AM PST #

From where can I get the source code of groovyWS0.4 version to debug? I only see 0.2 and 0.3 in the SVN repository under branches and nothing under tags.

I am getting NPE when I use proxy.initialize().
Am I missing something?

My code looks like -
def wsdl = "http://www.travlenow.com/services/HotelServices200631?wsdl"
def proxy = new WSClient(wsdl, this.class.classLoader)
proxy.inilialize()

Exception -
java.lang.NullPointerException
at groovyx.net.ws.WSClient.invokeMethod(WSClient.java:69)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at Test2Controller$_closure1.doCall(Test2Controller.groovy:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Posted by Meeta on April 07, 2009 at 02:19 AM PDT #

@Meeta - try replacing proxy.initialize() with proxy.create() - I think the initialized method disapeard

I am also playing with groovyws as client, but I am currently stuck at method/class creation. my service provides a method that returns a list of Strings. The method is generated and I can invoke it, but it always returns a String (actually its always the first element of the list it should return). The returned value is of type java.lang.String and not java.util.List. Any ideas ? I tested the WS with a JAX-WS based client and that one generates the method properly and the returned values is the expected List but I would really like to have the dynamic class generation at runtime :) any help would be appreciated

cheers, thasso

Posted by Thasso Griebel on April 09, 2009 at 01:50 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on April 09, 2009 at 08:23 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on April 15, 2009 at 10:42 PM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 05, 2009 at 07:04 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 05, 2009 at 07:05 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 05, 2009 at 07:49 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 06, 2009 at 03:29 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 06, 2009 at 10:38 PM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 06, 2009 at 10:38 PM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 06, 2009 at 11:21 PM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 07, 2009 at 03:28 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 07, 2009 at 03:29 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 20, 2009 at 06:57 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 20, 2009 at 06:57 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 20, 2009 at 06:59 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 20, 2009 at 07:19 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on May 21, 2009 at 12:42 AM PDT #

PROBLEM
-------
I also get the error that "sean d" reported above.

I am trying to call the w3schools temperature conversion web service from behind an HTTP proxy.

When I call it, I get the exception: org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve URL "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL".

I will try again from my home, where there is no HTTP proxy.

CODE
----
import groovyx.net.ws.WSClient
def proxy = new WSClient("http://www.w3schools.com/webservices/tempconvert.asmx?WSDL", this.class.classLoader)
proxy.setProxyProperties( [ proxyHost:"proxy.ghc.org", proxyPort:"8080", "proxy.user":"user", "proxy.password":"password" ] )
proxy.initialize()
println "You are probably freezing at ${proxy.CelsiusToFahrenheit(0)} degrees Farhenheit"

ENVIRONMENT
-----------
Groovy 1.6.3

JARS
----
groovyws-minimal-0.5.0.jar
cxf-2.1.5.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.3.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.9.jar
junk.txt
neethi-2.0.4.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.6.jar
xml-resolver-1.2.jar
XmlSchema-1.4.5.jar

NOTES
-----
\* All jars, except for groovyws-minimal-0.5.0.jar, are specified by CXF 2.1.5's WHICH_JARS file.
\* I can access the WSDL URL via my web browser.
\* I use the same proxy parameters in my Maven settings.xml file.
\* proxy.initialize() is the correct way to initialize the client. Using proxy.create() causes a NPE, because there is no no argument create() method, unlike what "Manu" and "Thasso Griebel" said above.

Posted by devdanke on May 27, 2009 at 09:15 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on June 05, 2009 at 03:06 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funkti...

Posted by The Next Radio on June 05, 2009 at 04:11 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funktion...

Posted by The Next Radio on August 26, 2009 at 05:43 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funktion...

Posted by The Next Radio on August 26, 2009 at 05:45 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funktion...

Posted by The Next Radio on August 26, 2009 at 05:47 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funktion...

Posted by The Next Radio on August 26, 2009 at 06:38 AM PDT #

[Trackback] Auf der Suche nach eine Bibliothek zum Implementieren von Web Services bin ich letztens auf GroovyWS gestoßen. Auf der Projektseite finden sich einige Beispiele, die zeigen wie man mit extrem wenig Code lauffähige Dienste anbieten kann. Leider funktion...

Posted by The Next Radio on August 26, 2009 at 06:39 AM PDT #

Thanks for a nice post first.
Trying to use a external webservice in my grails project but does not work.
Please suggest.
CODE
=======================================================================
import groovyx.net.ws.WSClient

class LoadController {

def wsTest = {
println "Before calling Ws method>>>";

/* Call WS*/
def proxy = new WSClient("https://devora11.gryphon.priv/axis2/services/GDXAppWS?wsdl", this.class.classLoader)
proxy.initialize()
println "Proxy "+proxy ;
print proxy.isSQLAlive()

}
ERROR
===================================================================
Error 2011-12-19 16:04:56,989 ["http-bio-8080"-exec-1] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /GryphonMQ/load/wsTest
port out of range:-1. Stacktrace follows:
Message: port out of range:-1
Line | Method
->> 118 | <init> in java.net.InetSocketAddress
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 364 | <init> in com.sun.net.ssl.internal.ssl.SSLSocketImpl
| 71 | createSocket . in com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl
| 233 | getLocalWsdlUrl in groovyx.net.ws.cxf.SSLHelper
| 104 | initialize . . in groovyx.net.ws.WSClient
| 43 | doCall in com.ggw.LoadController$_closure3
| 26 | doFilter . . . in org.grails.plugin.resource.DevModeSanityFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . in ''
^ 662 | run in java.lang.Thread

using STS IDE and grails 2

thanks
Sadhna

Posted by guest on December 19, 2011 at 07:09 AM 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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today