<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code3 &#187; SOAP</title>
	<atom:link href="http://www.code3.dk/tag/soap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.code3.dk</link>
	<description>Techchat</description>
	<lastBuildDate>Thu, 17 Nov 2011 13:10:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Creating, consuming and testing SOAP webservices on Grails</title>
		<link>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/</link>
		<comments>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 09:05:14 +0000</pubDate>
		<dc:creator>AN</dc:creator>
				<category><![CDATA[Techchat]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.code3.dk/?p=341</guid>
		<description><![CDATA[We are currently making a backend system, that has its services exposed as webservices. Since making web applications in Grails [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently making a backend system, that has its services exposed as webservices. Since making web applications in Grails is pretty nice, we decided to try it for webservices.</p>
<p>Getting up and running was certainly a breeze.</p>
<p><code><br />
grails create-app ...<br />
grails install-plugin cxf<br />
</code></p>
<p>Grails is a plugin-based framework. And the <a href="http://grails.org/plugin/cxf/">cxf plugin</a> seems to be the best plugin for webservices right now. Exposing the services was then as simple as adding a</p>
<p><code>static expose=['cxf']</code></p>
<p>to the the grails service classes. We wante to allow our service interfaces to operate with complex objects. And to do that best we decided to use the <a href="http://www.grails.org/plugin/dto">DTO plugin</a> and specify our interfaces in terms of DTOs mostly generated from our domain objects. This was only a semi-good idea, I think, as the conversion to/from complex domain objects was not great out of the box (more on that in another post).</p>
<p>To consume webservices, the most straighforward way is to simply dump the <a href="http://groovy.codehaus.org/GroovyWS+installation">minimal jar of the GroovyWS module</a> in the lib folder of the project. Since we already had all the dependencies included by the cxf plugin the minimal jar is all that is needed.</p>
<p>To test the services, most of our test were simply the usual integration tests of the service classes. But for functional tests we used the <a href="http://www.grails.org/plugin/functional-test">functional-tests plugin</a> and the GroovyWS client we already had installed. </p>
<pre class="brush: java">
class MyServiceFunctionalTests extends functionaltestplugin.FunctionalTestCase {

	def myServicePort

	protected void setUp() {
		super.setUp();

		myServicePort = new WSClient(&quot;http://localhost:9091/myservice/services/my?wsdl&quot;, this.class.classLoader)
		myServicePort.initialize()
	}

	public void testAMethod(){
		final List resultVals = myServicePort.aMethod();

		assertEquals(4, resultVals.size());
	}
}
</pre>
<p>It feels a bit wrong to work with old and crufty technology like SOAP with shiny new technology like Groovy on Grails. But with that in mind it works surprisingly well. Points where I found the greatest room for improvement were.</p>
<ul>
<li>Grails has great support for Controllers as entrypoints, with interceptors for logging and authorization. For Services this seems harder if not impossible. I haven&#8217;t succeeded in using either groovys <a href="http://groovy.codehaus.org/Using+invokeMethod+and+getProperty">invokeMethod</a> or the built-in spring support for aspect-oriented-programing.</li>
<li>As mentioned above, the DTO plugin could use a more flexible mapping tool than the one it has.</li>
<li>With code that has no immediate GUI feedback, testing is extremely important. But the Grails test run so slow that it is annoying.</li>
</ul>
<p>Still, would I recommend Grails for a large SOAP project. Yes, I would.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code3.dk/creating-consuming-and-testing-soap-webservices-on-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

