Ask a Question

Groovy: Fails to Display Request Status

SOLVED
Mis3
Frequent Contributor

Groovy: Fails to Display Request Status

I am building a Groovy script to read an external file and execute a testStep one by one.

Somehow log.info can successfully display the data (basicMSISDN, NAM, etc) of the XML response but not the request status.  In log.info, resultCode=Null and message=Null.

Not sure what to do to get the resultCode so I have a log file for tracking.

Thanks.

 

------------------------------------------------------------------------------------------------------------------------------------

My Groovy script:

...

def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)

def MESSAGE11 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/resultCode")
def MESSAGE12 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/message")

def MESSAGE1 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/imsiData/basicMsisdn")
def MESSAGE2 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/imsiData/serviceProfile/nam")
def MESSAGE3 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/imsiData/serviceProfile/roamingProfileId")
def MESSAGE4 = holder.getNodeValue("/soap:Envelope/soap:Body/ns2:getImsiDataResponse/imsiData/serviceProfile/odbProfileId")

log.info " Seq="+i+" "+data[0]+"| Result: "+MESSAGE1+", "+MESSAGE2+", "+MESSAGE3+", "+MESSAGE4+" "+MESSAGE11+" "+MESSAGE12

...

-----------------------------------------------------------------------------------------------------------------------------------------------

Response of the testStep:

<<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

   <soap:Body>

      <ns2:getImsiDataResponse resultCode="0" message="success" xmlns:ns2="http://www.netnumber.com/titan/sdm/soap/types">

         <imsiData imsi="302330000006120">

            <basicMsisdn>14313140097</basicMsisdn>

            <serviceProfile>

               <nam>csps</nam>

               <transferOfSm>cs</transferOfSm>

               <roamingProfileId>320</roamingProfileId>  ...

 

---------------------------------------------------------------------------------------------------------------------------------------------------

14 REPLIES 14
Mis3
Frequent Contributor

This is cool.  Thanks, Rao.  I am not a developer so this code is hard for me to understand.  

 

I added your code to my Groovy script (below) and yielded the following results:

Is there any way to equate these results to a variable; like Message1 = FlowId:1, Status:0?  This way, I can control the log.info and report file better.   I will run this Groovy for thousands times so, ideally, it will be better if log.info is one line per MDSISDN.

 

Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsiDataResponse ==> FlowId: 1, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeMsisdnDataResponse ==> FlowId: 2, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsSubscriberDataResponse ==> FlowId: 3, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsSubscriberDataResponse ==> FlowId: 8, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsPrivateUserDataResponse ==> FlowId: 4, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 5, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 6, Status: 0
Wed Jun 23 09:38:39 EDT 2021:INFO:changeImsPublicUserDataResponse ==> FlowId: 7, Status: 0

-----------------------------------------------------------------------------------------------------------------------------------------------------------

def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def xml = new XmlSlurper().parseText(xmlResponse)

//Closure to show the details of the item as input data
def showDetails = { item ->
def sdms = xml.'**'.findAll {it.name() == item }*.parent()
sdms.each {
// log.info "${item} ==> FlowId: ${it.@flowId}, ResultCode: ${it."$item".@resultCode}, Message: ${it."$item".@message}"
log.info "${item} ==> FlowId: ${it.@flowId}, Status: ${it."$item".@resultCode}"
}
}
showDetails('changeImsiDataResponse')
showDetails('changeMsisdnDataResponse')
showDetails('changeImsSubscriberDataResponse')
showDetails('changeImsPrivateUserDataResponse')
showDetails('changeImsPublicUserDataResponse')

//Closure to show the details of the item as input data
def showDetails = { item ->
def sdms = xml.'**'.findAll {it.name() == item }*.parent()
sdms.each {
// log.info "${item} ==> FlowId: ${it.@flowId}, ResultCode: ${it."$item".@resultCode}, Message: ${it."$item".@message}"
log.info "${item} ==> FlowId: ${it.@flowId}, Status: ${it."$item".@resultCode}"
}
}
showDetails('changeImsiDataResponse')
showDetails('changeMsisdnDataResponse')
showDetails('changeImsSubscriberDataResponse')
showDetails('changeImsPrivateUserDataResponse')
showDetails('changeImsPublicUserDataResponse')




nmrao
Champion Level 3

It should be possible. So far seen your response in pieces. But need the response in full so that it will help to understand.


Regards,
Rao.
nmrao
Champion Level 3

BTW, below statement is no more needed
def holder = groovyUtils.getXmlHolder(xmlResponse)


Regards,
Rao.
nmrao
Champion Level 3

BTW, the original question is answered i.e., how to access the attributes.
Also your extension question answered. Now it is good to close this question and open a fresh question.


Regards,
Rao.
Mis3
Frequent Contributor

Agreed.   Will start a new post.  
Thanks.  

cancel
Showing results for 
Search instead for 
Did you mean: