Highlighted
Established Member.. DamienCurrier
Established Member..
1955 views

Extracting XML Values from a SOAP response using Web Services

Jump to solution

Hello,

I am struggling with some code in my web services script.  I am sending a web_service_call and getting a valid response.  However, the response has an error message from the server.  I am trying to write a bit of code that will extract that error message and test it.  If the error message has a specific code(s) in it, I want to fail the transaction [lr_end_transaction("Transaction Name",LR_FAIL);]  

I believe the problem is in the Query I built in the lr_xml_extract function.  I built the Query based on what I saw in the SOAP response.  Unfortunately, this response contains CDATA which may be throwing the XPath off, as well as in the response there are both < > and &lt; &gt; characters which may also be throwing the XPath off.  And I have no idea what an ICD resource bundle is....  😕

Here is the code I have:

    web_service_call( "StepName=executeService_101",
        "SOAPMethod=MyWebService|MyWebServicePort|executeService",
        "ResponseParam=response",
        "Service=MyWebService",
        "ExpectedResponse=SoapResult",
        "Snapshot=t1466529294.inf",
        BEGIN_ARGUMENTS,
        "arg0={xmlToSend}",
        END_ARGUMENTS,
        BEGIN_RESULT,
        END_RESULT,
        LAST);
    
    lr_output_message("Response is: %s", lr_eval_string("{response}"));
    
    lr_xml_extract("XML={response}",
        "XMLFragmentParam=Result",
        "Query=/Body/dlwmin:executeServiceResponse/return/jobResponse/request/status/error/",
        LAST);
    
    lr_output_message("Extracted value is: %s", lr_eval_string("{Result}"));

 

Here is the error I'm receiving in the play back log:

Action.c(29): Notify: Parameter Substitution: parameter "response" = "<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><dlwmin:executeServiceResponse xmlns:dlwmin="http://ws.xml.app.xx.xxxx.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><return>&lt;jobResponse&gt;&lt;header&gt;&lt;clientId&gt;123456789&lt;/clientId&gt;&lt;cust&gt;9999&lt;/cust&gt;&lt;/header&gt;&lt;request&gt;&lt;transactionId&gt;2487808&lt;/transactionId&gt;&lt;data&gt;&lt;![CDATA[&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;inquiryKeys&gt;&lt;userNumber&gt;12345678&lt;/userNumber&gt;&lt;cust&gt;9999&lt;/cust&gt;&lt;key1/&gt;&lt;/inquiryKeys&gt;]]&gt;&lt;/data&gt;&lt;errors/&gt;&lt;warnings/&gt;&lt;status&gt;&lt;error code="S812" description="No Data Found."/&gt;&lt;/status&gt;&lt;/request&gt;&lt;/jobResponse&gt;</return></dlwmin:executeServiceResponse></soapenv:Body></soapenv:Envelope>"
Action.c(29): Error: The message was not found in the ICU resource bundle.
The message was not found in the ICU resource bundle.The message was not found in the ICU resource bundle.( '/')
Action.c(29): Error: "lr_xml_extract" execution failed

 

Tags (1)
0 Likes
1 Solution

Accepted Solutions
OlaBerggren Acclaimed Contributor.
Acclaimed Contributor.

Re: Extracting XML Values from a SOAP response using Web Services

Jump to solution

Hi

As this is a soap call, yuo need to do this in theps.

First you need to extract the "<return>"-tag with lr_xml_extract.

Then you will need to change the format from HTML to PLAIN with web_convert_param. This will transform all &gt; to > and so on.

Then at last you will need to do a lr_xml_extract on the transformed xml, to find the error-tag

 

.
1 Reply
OlaBerggren Acclaimed Contributor.
Acclaimed Contributor.

Re: Extracting XML Values from a SOAP response using Web Services

Jump to solution

Hi

As this is a soap call, yuo need to do this in theps.

First you need to extract the "<return>"-tag with lr_xml_extract.

Then you will need to change the format from HTML to PLAIN with web_convert_param. This will transform all &gt; to > and so on.

Then at last you will need to do a lr_xml_extract on the transformed xml, to find the error-tag

 

.
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.