Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get SOAP Response using groovy wslite?

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

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

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

 

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()

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you