groovy-wslite SOAP

Recently I needed to consume an SOAP service from an Spring application, my first approach was creating an snippet that works from Groovy console, my code worked and looks like this:


import wslite.soap.SOAPClient

def file = new File("/tmp/file.xml")
assert file.exists()

String wsdl = 'https://server/servicios/soap/stamp.wsdl'

def client = new SOAPClient(wsdl)
def response = client.send(SOAPAction: 'stamp') {
  body {
    stamp('xmlns': 'https://server/WSDL') {
println response.dump()

Unfortunately when I convert this to a Spring bean was not working anymore, since I can not find a response in Stack Overflow, I needed to figure out was happening by my own and after that I wrote this post. My code in Spring looks like this:

package com.tim.one.billing.services.impl

import org.springframework.stereotype.Service
import org.springframework.beans.factory.annotation.Autowired
import javax.annotation.PostConstruct
import wslite.soap.SOAPClient

import com.tim.one.billing.services.StampProvider
import com.tim.one.billing.state.ApplicationState

import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

class StampProviderImpl implements StampProvider {

  String wsdl
  String namespace

  Properties properties

  Log log = LogFactory.getLog(getClass())

  void initialize(){
    wsdl = properties.getProperty(ApplicationState.STAMP_WSDL)
    namespace = properties.getProperty(ApplicationState.STAMP_NAMESPACE)

  def stamp(File factura, String username, String password){
    def client = new SOAPClient(wsdl)
    def response = client.send(SOAPAction: 'stamp') {
      body {
        stamp('xmlns':namespace) {


The issue was a closure scope, and using delegate inside the nested closure, wslite sent the right parameters to the service.

Return to the main article

With your donation, you help me to maintain this site and posts.

comments powered by Disqus