How to get SOAP Response using groovy wslite?

Aira Veronica Dizon February 24, 2021

I have a post-function that sends a POST request from Jira to BMC Remedy, I can do the request successfully but I don't know how can I get the SOAP response?

I should be getting a value which is the Change ID along with the Error Code and Error Description.

This is a sample response that I should receive:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns0:CreateResponse xmlns:ns0="urn:JR_Create">
<ns0:ChangeID>CR1000</ns0:ChangeID> <ns0:ErrCode>OK</ns0:ErrCode> <ns0:ErrDesc>Successful</ns0:ErrDesc>
</ns0:CreateResponse> </soapenv:Body> </soapenv:Envelope>

 How can I get the response right after I sent the request successfully? 

 

I'm trying to follow this example, but I'm getting too many errors:

def client = new SOAPClient("http://...")
def response = client.send(SOAPAction: "SomeAction",
                           connectTimeout:5000,
                           readTimeout:10000,
                           useCaches:false,
                           followRedirects:false,
                           sslTrustAllCerts:true) {
    version SOAPVersion.V1_2        // SOAPVersion.V1_1 is default
    soapNamespacePrefix "SOAP"      // "soap-env" is default
    encoding "ISO-8859-1"           // "UTF-8" is default encoding for xml
    envelopeAttributes "xmlns:hr":"http://example.org/hr"
    header(mustUnderstand:false) {
        auth {
            apiToken("1234567890")
        }
    }
    body {
        GetWeatherByZipCode(xmlns:"http://example.weather.org") {
            ZipCode("93657")
        }
    }
}

 

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 27, 2021

You say you are getting too many errors in the provided example, but you also claim that you can do the request successfully.

Can you share how you do this successful request? Is it using a different code example? 

If you can load the "response" variable correctly and it is loaded with an xml that matches the response you shared, I would expect that you should be able to get the change ID with

def changeId = response.Body.CreateResponse.ChangeID
Aira Veronica Dizon March 1, 2021

Hello Peter, sorry for the late reply. 

 

This is how I do the request:

 

def client = new SOAPClient("webservice URL")
def request = client.send(SOAPAction: "CreateOperation", """soapenv:https://schemes.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:CreateRFC">
<soapenv:Header>
<urn:AuthenticationInfo>
<urn:userName>username</urn:userName>
<urn:password>password</urn:password>
<urn:/AuthenticationInfo>
<soapenv:Body>
<urn:CreateOperation>
<urn:Title>${title}</urn:Title>
<urn:Description>${description}</urn:Description>
</urn:CreateOperation>
</soapenv:Body>
</soapenv:Envelope>""")

log.debug(request)

 

Basically, what my request does is to create an RFC in Remedy, and my request works successfully. However, I'm not sure how I can get the Change ID in the response.

In the XML, there is another method for getting the response which is "CreateOperation_Response" wherein I can get here the Error Code, Error Description, and Change ID.

Can you help me how can I achieve getting the response using this?

def changeId = response.Body.CreateOperation_Response.ChangeID

 

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 1, 2021

Try adding

log.debug groovy.xml.XmlUtil.serialize(request.body)

This will confirm that the .send() method worked and received a wslite.soap.SOAPResponse and show you the full xml of the body

Then assuming the response match the XML you provided above, you should see that the first node in your xml: ns0:CreateResponse

So try to go down one level deeper:

log.debug groovy.xml.XmlUtil.serialize(request.body.CreateResponse)
And so on... until you get

request.body.CreateResponse.ChangeID

If you are not sure what the node names are you can always temporarily output

log.debug request.body.childNodes()*.name()
Aira Veronica Dizon March 1, 2021

Omg thank you so much! I'm getting the Change ID now.

Can't believe this is the only line I needed to get the response lol.

log.debug groovy.xml.XmlUtil.serialize(request.body)

Suggest an answer

Log in or Sign up to answer