Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Description

The Wsclient plugin adds a remoting client capable of communicating via SOAP. It is compatible with Grails' Xfire plugin 0.8.1.

Installation

The current version of griffon-wsclient-plugin is 0.5
To install just issue the following command

Code Block
griffon install-plugin wsclient

Usage

The plugin will inject the following dynamic methods:

  • withWs(Map params, Closure stmts) - executes stmts issuing SOAP calls to a remote server.
  • withWs(Map params, CallableWithArgs<T> stmts) - executes stmts issuing SOAP calls to a remote server.

Where params may contain

Property

Type

Required

Notes

wsdl

String

(tick)

WSDL location

soapVersion

String

(error)

either "1.1" or "1.2". Defaults to "1.1"

classLoader

ClassLoader

(error)

classLoader used for proxy classes

timeout

long

(error)

 

mtom

boolean

(error)

enable mtom

basicAuth

Map

(error)

must define values for username and password keys

proxy

Map

(error)

proxy settings. Keys must match groovyx.net.ws.cxf.SettingsConstants

ssl

Map

(error)

ssl settings, Keys must match groovyx.net.ws.cxf.SettingsConstants

These methods are also accessible to any component through the singleton griffon.plugins.wsclient.WsclientConnector. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call WsclientConnector.enhance(metaClassInstance).

Code Block
titlegroovyx.net.ws.cxf.SettingsConstants
    /** Http proxy user */
    public static final String HTTP_PROXY_USER = "http.proxy.user";
    /** Http proxy password */
    public static final String HTTP_PROXY_PASSWORD = "http.proxy.password";
    /** Http proxy host */
    public static final String HTTP_PROXY_HOST = "http.proxyHost";
    /** Http proxy port */
    public static final String HTTP_PROXY_PORT = "http.proxyPort";

    /** SSL truststore */
    public static final String HTTPS_TRUSTSTORE = "https.truststore";
    /** SSL truststore password */
    public static final String HTTPS_TRUSTSTORE_PASS = "https.truststore.pass";
    /** SSL keystore */
    public static final String HTTPS_KEYSTORE = "https.keystore";
    /** SSL keystore password */
    public static final String HTTPS_KEYSTORE_PASS = "https.keystore.pass";

    /** Http basic authentication user */
    public static final String HTTP_USER = "http.user";
    /** Http basic authentication password */
    public static final String HTTP_PASSWORD = "http.password";

Examples

This example relies on Grails as the service provider. Follow these steps to configure the service on the Grails side:

  1. Download a copy of Grails and install it.
  2. Create a new Grails application. We'll pick 'exporter' as the application name.
    Code Block
    grails create-app exporter
    
  3. Change into the application's directory. Install the xfire plugin.
    Code Block
    grails install-plugin xfire
    
  4. Create a MathService
    Code Block
    grails create-service MathService
    
    Code Block
    titlegrails-app/services/MathService.groovy
    class MathService {
        boolean transactional = false
        static expose = ["xfire"]
    
        double add(double arg0, double arg1){
            println "add($arg0, $arg1)" // good old println() for quick debugging
            return arg0 + arg1
        }
    }
    
  5. Start the application
    Code Block
    grails run-app
    

Now we're ready to build the Griffon application

  1. Create a new Griffon application. We'll pick MathClient as the name
    Code Block
    griffon create-app mathClient
    
  2. Install the wsclient plugin
    Code Block
    griffon install-plugin wsclient
    
  3. Fix the view script to look like this
    Code Block
    titlegriffon-app/views/MathClientView.groovy
    application(title: 'Wsclient Plugin Example',
      pack: true,
      locationByPlatform: true,
      iconImage: imageIcon('/griffon-icon-48x48.png').image,
      iconImages: [imageIcon('/griffon-icon-48x48.png').image,
                   imageIcon('/griffon-icon-32x32.png').image,
                   imageIcon('/griffon-icon-16x16.png').image]) {
        gridLayout(cols: 2, rows: 4)
        label("Num1:")
        textField(columns: 20, text: bind(target: model, targetProperty: "num1"))
        label("Num2:")
        textField(columns: 20, text: bind(target: model, targetProperty: "num2"))
        label("Result:")
        label(text: bind{model.result})
        button("Calculate", enabled: bind{model.enabled}, actionPerformed: controller.calculate)
    }
    
  4. Let's add required properties to the model
    Code Block
    titlegriffon-app/models/MathClientModel.groovy
    import groovy.beans.Bindable
    
    class MathClientModel {
       @Bindable String num1
       @Bindable String num2
       @Bindable String result
       @Bindable boolean enabled = true
    }
    
  5. Now for the controller code. Notice that there is minimal error handling in place. If the user types something that is not a number the client will surely break, but the code is sufficient for now.
    Code Block
    titlegriffon-app/controllers/MathClientController.groovy
    class MathClientController {
        def model
    
        def calculate = { evt = null ->
            double a = model.num1.toDouble()
            double b = model.num2.toDouble()
            model.enabled = false
            doOutside {
                try {
                    def result = withWs(wsdl: "http://localhost:8080/exporter/services/math?wsdl") {
                        add(a, b)
                    }
                    doLater { model.result = result.toString() }
                } finally {
                    model.enabled = true
                }
            }
        }
    }
    
  6. Start the application
    Code Block
    griffon run-app
    

All dynamic methods will create a new client when invoked unless you define an id: attribute. When this attribute is supplied the client will be stored as a property on the instance's metaClass. You will be able to access it via regular property access or using the id: again.

Configuration

Dynamic method injection

Dynamic methods will be added to controllers by default. You can change this setting by adding a configuration flag in Config.groovy

Code Block
griffon.ws.injectInto = ["controller", "service"]

History

Version

Date

Notes

0.5

12-08-11

Release sync with Griffon 0.9.4

0.4.2

05-23-11

Release sync with Griffon 0.9.2

0.4.1

11-08-10

Fix a metaclass problem when injecting dynamic methods

0.4

10-27-10

Release sync with Griffon 0.9.1

0.3.1

08-12-10

Fixed GRIFFON-233

0.3

07-22-10

Release sync with Griffon 0.9

0.2.1

03-15-10

Fixed GRIFFON-149

0.2

03-01-10

Upgraded to Griffon 0.3

0.1

10-26-09

Initial release