Service Virtualization

  • 1.  Parsing of value from XML Request which contains <, >

    Posted Jul 26, 2017 02:59 PM

    Hi All,

     

    I have an XML request that has DOCUMENTOPTIONS that contains below sample code

     

    <DOCUMENTOPTIONS>
       <Document _Type="BOOK" _mode="AIR" />
    </DOCUMENTOPTIONS>


    The actual XML contains &lt and &gt as below.

    &lt;DOCUMENTOPTIONS&gt;

    &lt;Document _Type="BOOK" /&gt;
    &lt;Delivery _mode="AIR" /&gt;

    &lt;/DOCUMENTOPTIONS&gt;

     

    My requirement is to filter the value of _Type but I'm unable to read this value using filter options that are available since XML structure is broken due to &lt and &gt.

    Is there a way to read the value.



  • 2.  Re: Parsing of value from XML Request which contains <, >

    Posted Jul 27, 2017 12:04 PM

    I am not certain that your XML example above accurately maps to the sample encoded XML. However, try using a JSR-223 step or Scripted Assertion to see if you can decode the string.

     

    XML Example:

    <DocumentOptions>
        <Document _Type="Book" _Mode="Air"/>
    </DocumentOptions>

     

    Encoded XML for the example:

    &lt;DocumentOptions&gt;&lt;Document _Type=&quot;Book&quot; _Mode=&quot;Air&quot;/&gt;&lt;/DocumentOptions&gt;

     

    JSR-223 Script Logic (long hand):

    // assumes the Encoded XML is in a property called fl_encodedXML

    String s = com.itko.util.XMLUtils.decodeString( testExec.getStateValue("fl_encodedXML") );

    // store the decoded XML into a property

    testExec.setStateValue("fl_decodedXML", s );

    // display the XML in the step response or just return as appropriate

    // If using Scripted Assertion return true or false and set assertion branch accordingly

    return "decoded XML is: " + s;

     

    Alternative JSR-223 approach if you want to Xpath filter the LASTRESPONSE:

    return com.itko.util.XMLUtils.decodeString( testExec.getStateValue( "fl_encodedXML" ) );

     

    Apply an Xpath filter for the desired value by filtering fl_decodedXML or filtering on LASTRESPONSE



  • 3.  Re: Parsing of value from XML Request which contains <, >

    Posted Jul 28, 2017 12:44 PM

    Hi Joel, I tried it didn't work. With Xpath I am not able to filter the value since the complete xml is showing as text. 

     

    Below is sample request XML, From the below XML i need to retrieve value of BookingType and respond with corresponding response. Any suggestion will be greatly appreciated..

     

    <?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>
    <Process xmlns="http://HELLO.com/ZOOWS">
    <xmlRequest>&lt;PACKING_REQUEST_LIST _Version="x.x" _PSV="y.y" _PSN="orange" _BookingType="Internet"&gt;&lt;USER _Username="XXXXX" _Password="*******" /&gt;&lt;EMT_PAC XOSIdentifier="x.xx" _ID="NONE"&gt;&lt;/EMT_PAC&gt;&lt;/PACKAGE_REQUEST_LIST&gt;</xmlRequest>
    </Process>
    </soap:Body>
    </soap:Envelope> 



  • 4.  Re: Parsing of value from XML Request which contains <, >
    Best Answer

    Posted Jul 28, 2017 04:45 PM
      |   view attached

    The value of <xmlRequest>, above, is not valid XML, so Xpath will not work:

     

    &lt;PACKING_REQUEST_LIST _Version="x.x" _PSV="y.y" _PSN="orange" _BookingType="Internet"&gt;&lt;USER _Username="XXXXX" _Password="*******" /&gt;&lt;EMT_PAC XOSIdentifier="x.xx" _ID="NONE"&gt;&lt;/EMT_PAC&gt;&lt;/PACKAGE_REQUEST_LIST&gt;

     

    There is no ending element for PACKING_REQUEST_LIST. 

    <PACKING_REQUEST_LIST _Version="x.x" _PSV="y.y" _PSN="orange" _BookingType="Internet">
      <USER _Username="XXXXX" _Password="*******" />
      <EMT_PAC XOSIdentifier="x.xx" _ID="NONE"/>
    </PACKAGE_REQUEST_LIST>

     

    1. Read your entire Soap payload into a Parse Text as Response utility step.  Assign the value of the Soap document to fl_payload.

    A. Create an XML Xpath Filter that uses fl_payload and Xpaths the xmlRequest element. Assign the Filter a name such as fl_xmlToParse.  Also, notice that DevTest decoded the &gt; and &lt; as part of this step.

     

    B. Create an XML Xpath Filter that uses fl_xmlToParse and try to Xpath the attribute _bookingtype.  Assign the Filter a property name of fl_bookingType. 

    Run the filter and you will notice that the the fl_bookingType is empty.

     

     4. Copy Paste the Parse Text as Response from Step 1.

    A. Modify the body text and change the starting XML element to <PACKAGE_REQUEST_LIST.

    B. Test the Parse

    C. Rerun the Filters and examine the result.

    Attached is a sample test case with two steps that do the above.  The First step will not locate the _bookingtype attribute, but the second step does. Rather than adding code to decode, see if the approach in the Test Case step can be modified to do what you want it to do.

    Attachment(s)

    zip
    hack.tst.zip   1 KB 1 version


  • 5.  Re: Parsing of value from XML Request which contains <, >

    Posted Jul 31, 2017 08:40 PM

    Thanks Joel, I don't see the attachment, can you please upload. 



  • 6.  Re: Parsing of value from XML Request which contains <, >

    Posted Aug 02, 2017 03:45 PM
      |   view attached

    I see the attachment in the earlier reply.  Trying again.

    Attachment(s)

    zip
    hack.tst.zip   1 KB 1 version