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?wsdlPlease 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.