Forum Discussion

babusr01's avatar
babusr01
Contributor
9 years ago

Dynamic request creation with Groovy - element Create

As per my project, i have to create part of SOAP request as per input data,  I have developed below code and not able to get, could some one help me.   import groovy.xml.StreamingMarkupBuilder im...
  • nmrao's avatar
    nmrao
    9 years ago

    Here is the script:

     

    import groovy.xml.StreamingMarkupBuilder
    import groovy.xml.XmlUtil
    def createRequest = {accountNumbers ->
    def nameSpacesMap = [
    soapenv: 'http://schemas.xmlsoap.org/soap/envelope/',
    ns: 'ABC',
    ]
    def builder = new StreamingMarkupBuilder()
    builder.encoding ='utf-8'
    def soapRequest = builder.bind {
    namespaces << nameSpacesMap
    soapenv.Envelope {
    soapenv.Header{}
    soapenv.Body {
    ns.TOPPER{
    RequestHeader{
    MessageId("ABC")
    }
    accountNumbers.each { actNo ->
    RequestElement {
    accountnumber(actNo)
    }
    }

    }
    }
    }
    }
    XmlUtil.serialize(soapRequest)
    }
    def accountdetails = [84144135,84023193]
    log.info createRequest(accountdetails)

     

    The same can be tried from here