Grails and consume SOAP webservice
Being fairly ne开发者_高级运维w to Grails i was wondering what people use to consume a webservice in Grails projects. So the client side of the system? Any recommendations? I see people using GroovyWS, Spring-WS etc.. What is a good and easy on to use?
GroovyWS is very easy to use and has great documentation I would definitely recommend it.
Using Grails CXF plugin here. Needed:
- classloader workaround -
DynamicClientFactoryit
changed a current classloader; - and to code WS invocations by hand.
Besides that, the consumer code is pretty slim.
Edit: sorry, no more then this, and I'm not sure I'm not breaking and NDA yet:
#1:
def arrayOfLong = objectFactory.createArrayOfLong(XXX, ids)
result = client.invoke(methodName, arrayOfLong as Object[])
#2:
def dcf = DynamicClientFactory.newInstance()
def classLoader = Thread.currentThread().getContextClassLoader()
// create a WS client
// and assign end point address to it
def client = dcf.createClient(WSDL_URL, classLoader)
client.conduit.target.address.setValue(endpointUrl)
// reacquire classloader because 'createClient' changes it
def changedClassLoader = Thread.currentThread().getContextClassLoader()
def objectFactory = changedClassLoader.
loadClass(FACTORY_CLASS_NAME).newInstance()
Using Grails 1.3.7 I am consuming my own web service with WS-Client Grails plugin. It is actually based on GroovyWS, which in turn uses CXF. It is very easy to use at least in my simple scenario, where I only get Strings from the backend web service. I have no idea how it works with complex data types yet though.
I had never consumed or created a webservice before but using that plugin in the frontend and the Grails CXF plugin in the backend I got a SOAP discussion between my grails apps in two days. You don't really need to use CXF or GroovyWS directly with the very nice ws-client plugin. Speed (of development) and simplicity.
精彩评论