cxf

The docs for the 2.x branch can be found here. A lot of the previous documentation is somewhat applicable, but I will be creating new docs in the coming weeks.

Grails CXF Plugin

The 3.x branch of the plugin is a grails plugin that contains simplified features to get simple soap endpoints exposed in grails 3 applications.

Getting Started

At the core, this plugin is a simple wrapper for geeting grails service classes wired up as direct soap endpoints. As many of the previous features from the 2.x branch as could be ported for the initial release were ported. There will be continued support added for the more complex CXF features going forward.

Basic Usage

Exposing a service class is as simple as adding the GrailsCxfEndpoint annotation and annotating the methods you wish to expose in the service with WebMethod and WebResult

SERVLET MAPPING

The default behavior is to expose the CxfServlet at the /services/* endpoint. If you with to override this behavior you can set the following config:

cxf:
servlet:
mapping: /webservices/*

EXPOSING CLASSES VIA ANNOTATION

When using the annotation, the property values will only be used if the corresponding annotation value is not provided or is set to the default value. The following are available to configure via the annotation:

The address property is used to adjust the endpoint address that the service will be deployed to. By default if not provided or is the value is empty (""), this will be the name of the Service or Endpoint with the first letter lowercase and the word Endpoint or Service removed from the end of the name. The default behavior would deploy the BoatService as /services/boat.

If you wish to override this and provide your own service name or address (for versioning support for example) you may set this value.

The name property will tell the plugin how you wish to name the service. This will change the wsdl name property from the default for the example below from CarService to simply just Car like this <wsdl:definitions name="Car" targetNamespace="http://demo.gpc.com">

@GrailsCxfEndpoint(name='Car')
class CarService {
...
}

PORT

The port property will tell the plugin how you wish to name the service port binding. This will change the wsdl name property of the port from the default for the example below from CarServicePort to simply just CarPort like this <wsdl:port binding="tns:CarServiceSoapBinding" name="CarPort">

@GrailsCxfEndpoint(port='CarPort')
class CarService {
...
}

SOAP12

To tell a service to default to SOAP 1.2 instead of 1.1 simply set this to true. The default value is false which will use SOAP 1.1.

This is a list of bean names in List<String> to inject to the cxf service endpoint. You will need to define your interceptor beans via normal spring dsl (in resources.groovy for example).

This is helpful when the default cxf annotation of @org.apache.cxf.interceptor.InInterceptors (interceptors = {"com.example.Test1Interceptor" }) does not satisfy your needs.

When chosing between the this property and the cxf provided one, if you require value injection, the cxf provided annotation will most likely NOT meet your needs and you should use this property instead.

Note: Make sure to set any beans you wish injected into your interceptors to bean.autowire = 'byName' or use the @Autowire annotation.

OUTINTERCEPTORS

If you wish to inject a custom in interceptor bean, use this property. This is helpful when the default cxf annotation of @org.apache.cxf.interceptor.OutInterceptors (interceptors = {"com.example.Test1Interceptor" }) does not satisfy your needs.

See above for examples of using inInterceptor which should be very similar.

INFAULTINTERCEPTORS

If you wish to inject a custom in interceptor bean, use this property. This is helpful when the default cxf annotation of @org.apache.cxf.interceptor.InFaultInterceptors (interceptors = {"com.example.Test1Interceptor" }) does not satisfy your needs.

See above for examples of using inInterceptor which should be very similar.

OUTFAULTINTERCEPTORS

If you wish to inject a custom in interceptor bean, use this property. This is helpful when the default cxf annotation of @org.apache.cxf.interceptor.OutFaultInterceptors (interceptors = {"com.example.Test1Interceptor" }) does not satisfy your needs.

See above for examples of using inInterceptor which should be very similar.

CONCLUSION

Using the annotation will help reduce the clutter of having many static properties in your class to configure cxf.

Demo Project

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.