Notes on Grails CXF Plugin - The Risberg Family

flashypumpkincenterSoftware and s/w Development

Dec 14, 2013 (3 years and 10 months ago)

99 views

Page
1

Notes on
Grails CXF Plugin

Created
03/28
/13

Updated 06/03/13
, Updated 07/02/13
,
Updated 07/17
/13
, Updated 07/25/13
, Updated 08/04/13

Introduction

This plugin b
rings easy exposure of service and endpoint classes as Apache CXF SOAP Services to Grails.


A WS
DL document defines services as collections of network endpoints, or ports. In WSDL, the abstract definition
of endpoints and messages is separated from their concrete network deployment or data format bindings. This allows
the reuse of abstract definition
s: messages, which are abstract descriptions of the data being exchanged, and port
types which are abstract collections of operations. The concrete protocol and data format specifications for a
particular port type constitutes a reusable binding. A port is

defined by associating a network address with a reusable
binding, and a collection of ports define a service.


Hence, a WSDL document uses the following elements in the definition of network services:



Types



a container for data type definitions using s
ome type system (such as XSD).



Message



an abstract, typed definition of the data being communicated.



Operation



an abstract description of an action supported by the service.



Port Type



an abstract set of operations supported by one or more endpoints.



Binding



a concrete protocol and data format specification for a particular port type.



Port



a single endpoint defined as a combination of a binding and a network address.



Service



a collection of related endpoints.

Jeff’s understanding of Concepts

Plu
gin allows decoration of services or endpoints.

Endpoints are the WS term, in this case ‘services’ is a Grails term

Hence, you can decorate an *existing* grails service, or write a new endpoint that may invoke some code (perhaps a
Grails service)

The anno
tation and property
-
based decorations offer the same capabilities

A ‘Simple’ endpoint is one where the methods are all made
visible (i.e., in the WSDL)

A ‘JAX
-
WS’ endpoint is one where the methods are only public if they have @WebMethod on them.

Decorating

a service

SIMPLE SERVICES

To expose as a simple endpoint
http://cxf.apache.org/docs/simple
-
frontend
-
configuration.html

add the following to
your endpoint or service class:



static

expose

=

EndpointType
.
SIMPLE


It states clearly in the documentation at
http://cxf.apache.org/docs/simple
-
frontend.html

the following:


There is a known issue for the JAXB data binding
with POJO, please see Dan Kulp's comment in
https://issues.apache.org/jira/browse/CXF
-
897
. If you want to use JAXB binding you should use the JAX
-
WS
Frontend. Mixing Simple Frontend and JAXB bin
ding leads to problems. The article A simple JAX
-
WS service
shows a code first JAX
-
WS service that is almost as easy to use as the Simple Frontend.

JAX WEB SERVICES

Page
2

To expose as a jax web service endpoint
http://cxf.apache.org/docs/jax
-
ws
-
configuration.html

add the following to
your endpoint or service class:



static

expose

=

EndpointType
.
JAX_WS


There are many ways to configure the plugin using static properties. The legacy way was to

use the
static expose =
['cxf']

in your service classes. Legacy support for both
static expose = ['cxf']

,
static expose = ['cxfjax']

and
static
expose = ['cxfrs']

services remains, but the new preferred way is to use one of the following methods of expos
ure.


The properties available for use are:


static expose = ...

static soap12 = ...

static address = ...

static wsdl = ...

static excludes = ...


See the description above in the
Exposing Classes via Annotation

section for more details on the meanings of the
properties. The end result of the static properties is the same as the equivalent annotation properties.

Here is an
example:


import

javax.jws.WebMethod

import

org.grails.cxf.utils.EndpointType


class

HelloEndpoint {



static

expose

= EndpointType.
JAX_WS



@WebMethod


String ping(String s) { s }



@WebMethod


String sayHello(String name) {
"Hello, $name"

}

}

Java JAXB Version Update

This library is used

to define the data formats and field/element information of the Web Services.


We require JAXB
version 2.2, but Java 1.6 comes with JAXB 2.1.


So you will need to update your Java JRE, these instructions, which
are extracted from
http://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html



Go to the $JAVA_HOME/jre/lib directory.


Notice that you may have two of these: one as the main JRE
for running a
pplications, and one as a JRE that contained within the JDK directory.



Create a directory called "endorsed"



In that library, place a copy of jaxb
-
api
-
2.2.6.jar, which can be downloaded from
http://jaxb.java.net/2.
2.6/


Using the Grails CXF
-
Client Plugin

There are a few different plugins for co
nsuming SOAP web services with G
rails, but none currently deal with the
issue of caching port references. The ws
-
client plugin works, but its limitations are in how it create
s and consumes
Page
3

the wsdl. It relies on real time creation of proxy classes and services which can be very processor and memory
(time) consuming with a large or complex service contract. We need a way to speed up service invocation so this
plugin was created

to facilitate that need when c
onsuming SOAP services using CXF
.


The CXF

Client plugin will allow you to
use existing (or new) apache CXF

wsdl2java generated content and cache
the port reference to speed up your
SOAP

service end point invocations through
an easy configuration driven
mechanism.


class DemoController {


SimpleServicePortType simpleServiceClient


ComplexServicePortType complexServiceClient



def simpleServiceDemo = {


SimpleRequest request = new SimpleRequest(age: 100, name: "
Bob")


SimpleResponse response = simpleServiceClient.simpleMethod(request)



render(view: '/index', model:


[simpleRequest: request, simpleResponse: response])


}

}

Open Issues/Questions

None at present