Introduction
SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. Groovy has a SOAP implementation based on
Xfire which allows you to create a SOAP server and to make calls on remote SOAP servers.
Installation
You just need to download this jar file in your ${user.home}/.groovy/lib directory.
Example
The Server
You can develop your web service using a groovy script and/or a groovy class. The following two groovy files are valid for building a web-service.
- MathService.groovy
- You can also using something more Groovy
- Then the easy part ... no need for comments
That's all !
The Client
- Oh ... you want to test it ... two more lines.
- You're done!
More Information
Current limitations (and workaround)
- No authentication (see JIRA issue 1457)
- No proxy support (see JIRA issue 1458)
- It looks like the XFire dynamic client does not support complex datatypes. This may be a concern if you need for example to transfer an Image as a byte array. The workaround I use is to transform this in a String an transfer that String - As this is a bit painful I am investigating moving to the regular XFire client. Here is a little program demo-ing this (look at this "disco age" image - Is Groovy that old ?
The client (ImageClient.groovy)
The (ugly) server part embedding the image which is Base64 encoded (ImageServer.groovy):
and the missing and secred part is here.
Demos with public web services
There exist a lot of web-services available for testing. One which is pretty easy to evaluate is the currency rate calculator from webservicex.net.
Here is a small swing sample that demonstrate the use of the service. Enjoy !
And here is the result: