Wslite plugin

  • Tags : soap, rest
  • Latest : 0.7.2.0
  • Last Updated: 09 March 2013
  • Grails version : 1.2.2 > *
1 vote
Dependency :
compile ":wslite:0.7.2.0"
Custom repositories :
mavenRepo "https://oss.sonatype.org/content/groups/public/"

Documentation Source Issues

Summary

This plugin brings the power of https://github.com/jwagenleitner/groovy-wslite library to yourGrails app. Thanks to Andres Almiray to provided code at https://github.com/griffon/griffon-wslite-plugin!

Description

Usage

The plugin will inject the following dynamic methods:

  • `withRest(Map params, Closure stmts)` - executes stmts using a RESTClient
  • `withHttp(Map params, Closure stmts)` - executes stmts using an HTTPClient
  • `withSoap(Map params, Closure stmts)` - executes stmts using a SOAPClient
to your controllers/services.

The following properties will be set on the implicit HTTPClient when using either `withRest` or `withSoap`:

  • connectTimeout
  • readTimeout
  • followRedirects
  • useCaches
  • sslTrustAllCerts
  • sslTrustStoreFile
  • sslTrustStorePassword
  • proxy
  • httpConnectionFactory
  • authorization
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 in a cache managed by the `WsliteProvider` that handled the call.

These methods are also accessible to any component through the singleton `groovy.org.grauls.plugins.wslite.WsliteEnhancer`. You can inject these methods to non-artifacts via metaclasses. Simply grab hold of a particular metaclass and call `WsliteEnhancer.enhance(metaClassInstance)`.

Samples

withRest(url: 'http://api.twitter.com/1/') {
   def response = get(path: '/users/show.json',
                      query: [screen_name: 'jwagenleitner', include_entities: true])
   println response.json
}

withSoap(serviceURL: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx') {
   def response = send(SOAPAction: 'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
      body {
         GetMothersDay(xmlns: 'http://www.27seconds.com/Holidays/US/Dates/') {
            year(2011)
         }
      }
   }

println response.GetMothersDayResponse.GetMothersDayResult.text() }

withSoap(serviceURL: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx') {
   def response = send {
      body {
         GetMothersDay(xmlns: 'http://www.27seconds.com/Holidays/US/Dates/') {
            year(2011)
         }
      }
   }

println response.GetMothersDayResponse.GetMothersDayResult.text() }

withSoap(serviceURL: 'http://www.w3schools.com/webservices/tempconvert.asmx') {
   def response = send(SOAPAction: 'http://tempuri.org/CelsiusToFahrenheit') {
      body {
         CelsiusToFahrenheit(xmlns: 'http://tempuri.org/') {
            Celsius("0")
         }
      }
   }

def result = response.CelsiusToFahrenheitResponse.CelsiusToFahrenheitResult.text() println "You are probably freezing at ${result} degrees Farhenheit" }

withSoap(serviceURL: 'http://www.w3schools.com/webservices/tempconvert.asmx') {
   def response = send {
      body {
         CelsiusToFahrenheit(xmlns: 'http://tempuri.org/') {
            Celsius(0)
         }
      }
   }

def result = response.CelsiusToFahrenheitResponse.CelsiusToFahrenheitResult.text() println "You are probably freezing at ${result} degrees Farhenheit" }