Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=BLOCK|hidden=true" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6aGlkZGVuPXRydWV8YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUJMT0NLfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>create a SOAP server and make calls to remote SOAP servers using Groovy</p></td></tr></table></p> <table class="wysiwyg-macro" data-macro-name="info" data-macro-parameters="title=Deprecated Module" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm86dGl0bGU9RGVwcmVjYXRlZCBNb2R1bGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"> <p><strong>Before using GroovySOAP, make sure to check</strong> <strong><a href="http://groovy.codehaus.org/GroovyWS"><strong>GroovyWS</strong></a></strong></p></td></tr></table> <h1>Introduction</h1> <p><br class="atl-forced-newline" /> <table class="wysiwyg-macro" data-macro-name="unmigrated-inline-wiki-markup" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3VubWlncmF0ZWQtaW5saW5lLXdpa2ktbWFya3VwOmF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1CTE9DS30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>{link:SOAP|http://www.w3.org/TR/soap/}{link}</pre></td></tr></table> is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. Groovy has a SOAP implementation based on<br /> <table class="wysiwyg-macro" data-macro-name="unmigrated-inline-wiki-markup" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3VubWlncmF0ZWQtaW5saW5lLXdpa2ktbWFya3VwOmF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1CTE9DS30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>{link:Xfire |http://xfire.codehaus.org}{link}</pre></td></tr></table> which allows you to create a SOAP server and/or make calls to remote SOAP servers using Groovy. <br class="atl-forced-newline" /></p> <h1>Installation</h1> <p> You just need to download <a href="http://dist.codehaus.org/groovy/jars/groovysoap-all-jsr06-0.1.jar">this</a> jar file in your ${user.home}/.groovy/lib directory. This jar file embeds all the dependencies.</p> <h1>Getting Started</h1> <h2>The Server</h2> <p>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.</p> <ol> <li>MathService.groovy <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> public class MathService { double add(double arg0, double arg1) { return (arg0 + arg1) } double square(double arg0) { return (arg0 * arg0) } } </pre></td></tr></table> <br class="atl-forced-newline" /></li> <li>You can also using something more Groovy <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> double add(double arg0, double arg1) { return (arg0 + arg1) } double square(double arg0) { return (arg0 * arg0) } </pre></td></tr></table> <br class="atl-forced-newline" /></li> <li>Then the easy part ... no need for comments <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapServer def server = new SoapServer("localhost", 6980) server.setNode("MathService") server.start() </pre></td></tr></table> <br class="atl-forced-newline" /> That's all !</li> </ol> <h2>The Client</h2> <ol> <li>Oh ... you want to test it ... two more lines. <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapClient def proxy = new SoapClient("http://localhost:6980/MathServiceInterface?wsdl") def result = proxy.add(1.0, 2.0) assert (result == 3.0) result = proxy.square(3.0) assert (result == 9.0) </pre></td></tr></table></li> <li>You're done!</li> </ol> <h1>Custom Data Types</h1> <p>This example shows how to use custom data types with Groovy SOAP. The code can be downloaded from <a class="confluence-link unresolved" data-filename="custom.zip" data-linked-resource-default-alias="custom.zip" href="#">here</a>.</p> <h2>The Server</h2> <p>The <code>PersonService.groovy</code> script contains the service implementation and the custom data type (<code>Person</code>). <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=PersonService.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9UGVyc29uU2VydmljZS5ncm9vdnl9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> class Person { int id String firstname String lastname } Person findPerson(int id) { return new Person(id:id, firstname:'First', lastname:'Last') </pre></td></tr></table> <p><br class="atl-forced-newline" /> <code>Server.groovy</code> is equivalent to the previous example.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=Server.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9U2VydmVyLmdyb292eX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapServer; def server = new SoapServer("localhost", 6980); server.setNode("PersonService"); server.start(); </pre></td></tr></table> <p><br class="atl-forced-newline" /> For each class compiled by the groovy compiler a <code>metaClass</code> property is added to the bytecode. This property must be excluded from being mapped by XFire, otherwise an error will be reported when trying to obtain the WSDL document from <code><a href="http://localhost:6980/PersonServiceInterface?wsdl">http://localhost:6980/PersonServiceInterface?wsdl</a></code>. The reason is that XFire cannot map <code>groovy.lang.MetaClass</code>. To ignore the <code>metaClass</code> property a custom type mapping must be defined (for details refer to <a href="http://xfire.codehaus.org/Aegis+Binding">Aegis Binding</a>).</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=Person.aegis.xml" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfHRpdGxlPVBlcnNvbi5hZWdpcy54bWx9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <?xml version="1.0" encoding="UTF-8"?> <mappings xmlns:sample="http://DefaultNamespace"> <mapping name="sample:Person"> <property name="metaClass" ignore="true"/> </mapping> </mappings> </pre></td></tr></table> <p><br class="atl-forced-newline" /> However, if you compile custom data types from Java the bytecode won't contain a <code>metaClass</code> property and, hence, there is no need to define a custom mapping. <br class="atl-forced-newline" /></p> <h2>The Client</h2> <p><br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=Client.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9Q2xpZW50Lmdyb292eX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapClient def proxy = new SoapClient('http://localhost:6980/PersonServiceInterface?wsdl') def person = proxy.findPerson(12) println 'Person (' + person.id + ') = ' + person.firstname + ' ' + person.lastname </pre></td></tr></table> <p><br class="atl-forced-newline" /> <br class="atl-forced-newline" /></p> <h1>More Information</h1> <h2>Current limitations (and workaround)</h2> <ol> <li>No authentication (see JIRA issue 1457)</li> <li>No proxy support (see JIRA issue 1458)</li> <li>Numeric values are represented as strings in custom data types and arrays.</li> <li>Custom data types cannot be processed on client side when using the Groovy SOAP module with the current groovy-1.0 release.</li> <li>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 ?</li> </ol> <p>The client (ImageClient.groovy) <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.swing.SwingBuilder import groovy.net.soap.SoapClient import javax.swing.ImageIcon import org.apache.commons.codec.binary.Base64 proxy = new SoapClient("http://localhost:6980/ImageServiceInterface?WSDL") // get the string, transform it to a byte array and decode this array b64 = new Base64() bbytes = b64.decode(proxy.getImage().getBytes()) swing = new groovy.swing.SwingBuilder() // this is regular SwingBuilder stuff i1 = swing.label(icon:new ImageIcon(bbytes)) frame = swing.frame(title:'Groovy logo', defaultCloseOperation:javax.swing.WindowConstants.DISPOSE_ON_CLOSE) { panel(){ widget(i1) } } frame.pack() frame.show() </pre></td></tr></table> <p><br class="atl-forced-newline" /> The (ugly) server part embedding the image which is Base64 encoded (ImageServer.groovy):</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.net.soap.SoapServer def server = new SoapServer("localhost", 6980) server.setNode("ImageService") server.start() </pre></td></tr></table> <p><br class="atl-forced-newline" /> and the missing and secred part is <a class="confluence-link unresolved" data-filename="ImageService.groovy" data-linked-resource-default-alias="ImageService.groovy" href="#">here.</a><br class="atl-forced-newline" /></p> <h2>Demos with public web services</h2> <p>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.<br /> Here is a small swing sample that demonstrate the use of the service. Enjoy ! <br class="atl-forced-newline" /></p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import groovy.swing.SwingBuilder import groovy.net.soap.SoapClient proxy = new SoapClient("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL") def currency = ['USD', 'EUR', 'CAD', 'GBP', 'AUD'] def rate = 0.0 swing = new SwingBuilder() refresh = swing.action( name:'Refresh', closure:this.&refreshText, mnemonic:'R' ) 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 } </pre></td></tr></table> <p><br class="atl-forced-newline" /> And here is the result: <img class="confluence-embedded-image image-center" src="/download/attachments/231080229/GroovySOAP.png?version=1&modificationDate=1369557632966" data-image-src="/download/attachments/231080229/GroovySOAP.png?version=1&modificationDate=1369557632966" data-linked-resource-id="231376381" data-linked-resource-type="attachment" data-linked-resource-default-alias="GroovySOAP.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080229" title="null > GroovySOAP.png"><br /> <br class="atl-forced-newline" /> <br class="atl-forced-newline" /></p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced