Posts Tagged ‘Grails’Creating, consuming and testing SOAP webservices on GrailsPublished Friday, February 12th, 2010 by ANWe 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. Getting up and running was certainly a breeze.
Grails is a plugin-based framework. And the cxf plugin seems to be the best plugin for webservices right now. Exposing the services was then as simple as adding a
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 DTO plugin 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). To consume webservices, the most straighforward way is to simply dump the minimal jar of the GroovyWS module 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. 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 functional-tests plugin and the GroovyWS client we already had installed.
class MyServiceFunctionalTests extends functionaltestplugin.FunctionalTestCase {
def myServicePort
protected void setUp() {
super.setUp();
myServicePort = new WSClient("http://localhost:9091/myservice/services/my?wsdl", this.class.classLoader)
myServicePort.initialize()
}
public void testAMethod(){
final List resultVals = myServicePort.aMethod();
assertEquals(4, resultVals.size());
}
}
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.
Still, would I recommend Grails for a large SOAP project. Yes, I would. My first patch to Grails acceptedPublished Monday, November 23rd, 2009 by milI recently wrote a patch for Grails to support This patch has now been applied to 1.2-SNAPSHOT. http://jira.codehaus.org/browse/GRAILS-4540 The IBM Developerworks has a great article on mock testing in Grails here. How to debug grails run-app loopPublished Wednesday, November 11th, 2009 by milI recently had a problem where Google told me that the problem probably was an empty Java file in my However, no files did that. The solution was to modify ant.groovyc(destdir:classesDirPath, classpathref:classpathId, encoding:"UTF-8", listFiles:true, compilerPaths.curry(classpathId, false)) And it turned out Google was right, I had a Java file with only the Console output from Grails testsPublished Thursday, September 24th, 2009 by ANFor casual testing in Grails, it would be nice to be able to just have the output of the tests dumped to the console that the tests were run from. This doesn’t seem possible in the default setup, but adding these lines
if(argsMap['no-reports']){
println testRunner.out.toString()
println testRunner.err.toString()
}
should do the trick, if you add them to $GRAILS_HOME/script/_GrailsTest.groovy in the “runTests” closure, right after ” With those lines in place you can run your test like Dependent dropdowns in GrailsPublished Friday, September 18th, 2009 by ANIt does really seem to be a very common problem with the dependend or chained drop-downs. At least it was one of the first problems I faced in the Grails app I’m working on now. The solution is not really more or less elegant than the one for Seam and Richfaces. I followed the guide on Grails.org but decided to make the solution a bit more general. So I pass the name of the select-element-to-update as a string to the update function. This way I can also put the function in a separate file for inclusion (updateselect.js).
function updateSelect(e, elemId) {
// The response comes back as a bunch-o-JSON
var values = eval("(" + e.responseText + ")") // evaluate JSON
if (values) {
updateSelectFromJSON(values, elemId);
}
}
function updateSelectFromJSON(values, elemId) {
var rselect = document.getElementById(elemId)
// Clear all previous options
rselect.options.length = 0
// Rebuild the select
for (var i=0; i < values.length; i++) {
var opt = document.createElement('option');
opt.text = values[i].name
opt.value = values[i].id
try {
rselect.add(opt, null) // standards compliant; doesn't work in IE
} catch(ex) {
rselect.add(opt) // IE only
}
}
}
Which is then called like this
...
<form>
optionKey="id" optionValue="name" name="country.name" id="country.name" from="${Country.list()}"
onchange="${remoteFunction(
controller:'country',
action:'ajaxGetCities',
params:''id=' + escape(this.value)',
onComplete:'''updateSelect(e, 'city')''')}"
>
</form>
One thing is missing from this solution, though. Unlike the solution on grails.org, the chained select is not updated based on the default value of the previous select. This can be fixed by inserting the following in the head element of the .gsp page.
function init() {
document.cityform['country.name'].onchange();
}
window.onload = init;
Grails bash completionPublished Monday, September 7th, 2009 by ANI’ve started doing some Grails development. So far it seems great. Here are a couple of notes to start with. Grails is not packaged officially for Ubuntu yet. And the packages that can be downloaded from grails.org don’t have bash completion. This guy however packaged grails for Debian/Ubuntu, and it include a bash completion script. The package seems to work great, and for one of my machines where I already installed grails from the usual tar.gz download, I pulled out the bash completion from the deb-package. To make it work completely with the tar.gz dowload I just had to modify the location of the grails installation (to use $GRAILS_HOME). Ahhhh. Somewhat less useful (but fun), I also added the Ubuntu “notify-send” notification feature described here. I feel all set for Grails development. Creating, consuming and testing SOAP webservices on Grails
Friday, February 12th, 2010
We are currently making a backend system, that has its services exposed as webservices. Since ... My first patch to Grails accepted
Monday, November 23rd, 2009
I recently wrote a patch for Grails to support dateCreated and lastUpdated when using mockDomain ... |
||
|
© 2008 Code3 ApS | Rådmandsgade 45A, 1. | 2200 København N | +45 7020 3383 | kontakt@code3.dk
![]() ![]() |
||