Sign in to edit and +1 items.
Login required
Download

CXF plug-in for Grails

(5)
Author(s) Ryan Crum
Current Release 0.9.0   (2 months ago)
Grails Version 2.0.0 > *
Tags
Dependency
compile ":cxf:0.9.0"
Expose Grails services through SOAP using Apache CXF.
Last updated by admin 2 years ago
grails install-plugin cxf
Last updated by thorstadt 1 year ago
This plugin allows you to expose Grails services as SOAP web services via CXF.

The code can be found here: http://github.com/thorstadt/grails-cxf

Installation

Type this command in your Grail application directory

$> grails install-plugin cxf

or if you have a plugin archive locally.

$> grails install-plugin /path/to/grails-cxf-0.7.0.zip

Dependencies

All required JARs are included in the plugin.

Getting Started

This plugin detects a static list property named 'expose' of a grails service class. If the 'expose' property contains 'cxf' keyword, then the plugin exposes the service as a SOAP web service.

For example, type this:

$> grails create-service Test
You will get "TestService.groovy" in your service directory.

Then, declare the static property "expose" and any methods will become web methods.

class TestService {

static expose=['cxf'] static exclude=["ignoredMethod"]

boolean serviceMethod(YourDomainClass dc){ return true; }

boolean ignoredMethod() { return "you shouldn't see me" }

}

Note that any classes being returned or passed as parameters must be annotated with @XmlAccessorType(XmlAccessType.FIELD). This is because JAXB gets choked up on the metaclass.

For example:

@XmlAccessorType(XmlAccessType.FIELD)
class YourDomainClass {
}

After running the command "grails run-app", you can access the WSDL of this example from

http://127.0.0.1:8080/your_grails_app/services/test?wsdl

Please note that TestService.groovy becomes 'test' in the URL.

If you need more control over your WSDL, you can enable JaxWS annotations on your class like this:

import javax.jws.*

class TestService { static expose=['cxfjax']

@WebResult(name="addResult") @WebMethod(operationName="add") int add(@WebParam(name="a")int a, @WebParam(name="b")int b) { return a + b } }

Note that the expose static property is now "cxfjax" instead of just "cxf". With cxfjax, no methods will be exposed by default. You must put the @WebMethod annotation on any methods that you want to expose. This mode can be useful when attempting to match a WSDL without having to go through the trouble of statically generating proxy code with something like wsdl2java.

Last updated by admin 2 years ago
Last updated by admin 2 years ago