rjc
rjc

Reputation: 2915

Grails support for consuming web services

Does Grails provide built-in or via a plugin support to consume (not to generate) XML based REST or SOAP web services ( esp. REST) ?

Upvotes: 3

Views: 2716

Answers (4)

In grails 3.x you can use the plugin in build.gradle

compile 'com.github.groovy-wslite:groovy-wslite:1.1.2'

Then add the import to your controller like in http://guides.grails.org/grails-soap/guide/index.html

import wslite.soap.*
import wslite.soap.SOAPClient
import wslite.soap.SOAPResponse

and use as the example available in https://github.com/jwagenleitner/groovy-wslite

def client = new SOAPClient('http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx')
def response = client.send(SOAPAction:'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
body {
    GetMothersDay('xmlns':'http://www.27seconds.com/Holidays/US/Dates/') {
        year(2011)
    }
}
}

assert "2011-05-08T00:00:00" == response.GetMothersDayResponse.GetMothersDayResult.text()
assert 200 == response.httpResponse.statusCode
assert "ASP.NET" == response.httpResponse.headers['X-Powered-By']

render (response.GetMothersDayResponse.GetMothersDayResult.text())

Upvotes: 0

javazquez
javazquez

Reputation: 93

In the past, I created a script (grails create-script) that used wsimport to create POJOs in the java src directory. Each time the script ran, it would delete the generated directory if it existed first, then generate new files.

I did this because the API that was being consumed was being developed and I wanted an easy way to consume the latest and greatest when new functionality was added.

Upvotes: 1

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

For SOAP based webservices, use WSClient. The plugin is a wrapper around GroovyWS. Under the hood, Apache CXF is working there.

Upvotes: 3

Gregg
Gregg

Reputation: 35864

http://www.grails.org/plugin/rest

Upvotes: 3

Related Questions