How can I view a SOAP response?

Post Reply
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

How can I view a SOAP response?

Post by gabrielp »

Hey guys,

I'm stuck on this problem. I think I'm getting a SOAP exception as a response but I can't view it. I tried logging the response but it just shows "[object Network8::SOAP_ex]". Does anyone know how I could examine this response?



I tried taking the response and using writeToFile() but that function just returns a boolean on success and I don't know how to see the contents of that file. I also tried parseBody() but I don't know what the documentation means by the "element name".



Anyone have any idea how I can see what's in that response?





var wsdl = 'http://192.168.1.XX/EnterpriseWebServic ... .asmx?wsdl';



try{



var soap = new SOAP();

var xml = '<?xml version="1.0" encoding="utf-8"?>' +

'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +

'<soap:Body>' +

'<GetDetailJobStatus xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">' +

'<Credentials>' +

'<Username>myusername</Username>' +

'<Password>mypass</Password>' +

'</Credentials>' +

'<JobNumber>123456</JobNumber>' +

'</GetDetailJobStatus>' +

'</soap:Body>' +

'</soap:Envelope>';

soap.setBody(xml);



var response = soap.requestMessage(wsdl, 'http://localhost/EnterpriseWebService/E ... lJobStatus');



s.log(2, "Result is...");

s.log(2, response);



soap.writeToFile('request.xml');

response.writeToFile('response.xml');



} catch ( exception ) {



s.log(3, exception );

}

Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

How can I view a SOAP response?

Post by gabrielp »

Okay, answered my own question. These lines allowed me to overwrite the input file with the resulting response:



// Overwrite the input file with the response

response.writeToFile( job.getPath() );

job.sendToSingle( job.getPath() );



Now the issue I'm having is parsing the response. This is my response:



<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

<GetDetailJobStatusResponse xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">

<GetDetailJobStatusResult>1000 Digital Prepress</GetDetailJobStatusResult>

</GetDetailJobStatusResponse>

</soap:Body>

</soap:Envelope>



So how would I get that value of GetDetailJobStatusResult as a string?



I was hoping something like this would work, but it doesn't:



s.log(2, response.parseBody('GetDetailJobStatusResponse'));
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

How can I view a SOAP response?

Post by dkelly »









1000 Digital Prepress










Try something like:



s.log(-1, "Result: %1", result[http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse][GetDetailJobStatusResult]);

User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

How can I view a SOAP response?

Post by gabrielp »

dkelly wrote: Try something like:



s.log(-1, "Result: %1", result[http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse][GetDetailJobStatusResult]);




Getting this:

Error: Trying to access undefined member 'http://localhost/EnterpriseWebService/Enterprise Connect:GetDetailJobStatusResponse'



Which is a similar error to anything I try when guessing at the structure of that object. I really wish there was the equivalent of var_dump() or print_r() for cases like these. Luckily, I think I might actually just output an entire XML file so I can continue with this project, so I think I can avoid parsing the XML within the script. If anyone figures out how to parse through the response, I would be interested though!
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

How can I view a SOAP response?

Post by dkelly »

Here's a routine I wrote to dump any JS object.



function mydump(arr,level) {

var dumped_text = "";

if(!level) level = 0;



var level_padding = "";

for(var j=0;j<level+1;j++) level_padding += " ";



if(typeof(arr) == 'object') {

for(var item in arr) {

var value = arr[item];



if(typeof(value) == 'object') {

dumped_text += level_padding + "'" + item + "' ...n";

dumped_text += mydump(value,level+1);

} else {

dumped_text += level_padding + "'" + item + "' => "" + value + ""n";

}

}

} else {

dumped_text = "===>"+arr+"<===("+typeof(arr)+")";

}

return dumped_text;

}





Dwight Kelly
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

How can I view a SOAP response?

Post by gabrielp »

dkelly wrote: Here's a routine I wrote to dump any JS object.


Awesome Dwight. That will come in handy.



Jonas from Enfocus was able to answer my question. Here it is for anyone who might encounter this in the future:



s.log(2, response.parseBody("//GetDetailJobStatusResponse/GetDetailJobStatusResult"));

Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

How can I view a SOAP response?

Post by gabrielp »

One more update. It appears that the code above did not actually work. This is because EPMS Connect returns nodes with a null namespace when the default namespace of "soap" is set on the response. This means, you have to specify a null namespace when trying to grab values out in your xpath.



This code uses a more specific xpath and does work.

var responseMessage = response.parseBody("/soap:Envelope/soap:Body/*[name()='SubmitOrderResponse']/*[name()='SubmitOrderResult']/*[name()='Message']");

s.log(-1, responseMessage);



Dominick Peluso, peluso.dominick@gmail.com
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Scheer
Newbie
Posts: 4
Joined: Tue Mar 15, 2016 3:12 pm

Re: How can I view a SOAP response?

Post by Scheer »

An old topic, but very helpful! Thanks Dominick!
Post Reply