Service Virtualization

  • 1.  I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Sep 21, 2017 10:57 AM

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope >
      <SOAP-ENV:Header>
         </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns:process xmlns:ns="http://service.xyz.com">
    <![CDATA[
    {
      "listTransactionsRequest": {
       "startDate":"00:00:00-00:00",
       "endDate":"00:00:00-00:00",
       "includeUnpostedActivity": true,
       "accountKey":{
         "companyNumber":00

          "AccountNo": 00
      
       }
      }
    }
    ]]>
        </ns:process>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

     

    Problem is to create Argument of "CompanyNumber" / AccountNO?

     

    Step 1: I have used data protocol filter on Listener step and below is the script which I used.

    JSONParser parser = new JSONParser();

    String str1 = testExec.getStateValue("My_JSONMSG");
    String str = str1.substring(str1.indexOf("CDATA[")+6,str1.indexOf("]]}>"));
    str = str.trim();

    JSONObject jsonObject = (JSONObject) parser.parse(str);
    String ProductCode = (String) jsonObject.get("hoganProductCode");
           
    lisa_vse_request.setOperation("process");
    ParameterList args = lisa_vse_request.getArguments();
    args.addParameter(new Parameter("Hogan_Productcode", ProductCode));
    lisa_vse_request.setArguments(args);

     

    Step2: Added XML Xpath filter on Listener step

    //*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='ns:process']

     

    XML Xpath filter is not capturing the required argument. can some one help me to get the argument.



  • 2.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Broadcom Employee
    Posted Sep 21, 2017 01:27 PM

    Hi,

     

    If I understand what you're trying to do, a simple approach (without any scripting) is:

     

    1) Apply a Web Services SOAP DPH

    2) Next, apply the Request Data Manager DPH to copy the value of the "process" argument to the body.

    3) Use the JSON DPH

     

    --Mike



  • 3.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Sep 21, 2017 02:38 PM

    Hi Mike,

     

    Could you please provide step by step process... As I have followed below steps, but still Arugument is not captured at VSI>RequestData>Argument

     

    I have tried as below...

    Request Side Data Protocols

    Added SOAP DPH

    Added Request Data Manager DPH

    Added JSON DPH

    Then navigated to Next window where we can Add Action list.

    Added Action list as follow - Action - Copy, Source Type - Argument, Name -AccountNO, Target Type - Argument.

     

     

    Thanks,
    Venu



  • 4.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Broadcom Employee
    Posted Sep 21, 2017 03:17 PM

    Hi Venu,

     

    I created a sample project and got this to work.

     

    1) Instead of the SOAP DPH, I used the Generic XML Parser DPH.  This eliminates the need for the Request Data Manager.

    2) I selected local-name() of the process element and assigned it to the operation name

    3) I selected the string() of the process element and assigned it to the body.

    4) I added the JSON 2.0 DPH.

     

    Also, I fixed a minor typo if your JSONO document - a comma was missing after the companyNumber.

     

    I'm unable to attach a DevTest project here, so send your email address to mike.gavaghan@ca.com and I'll send you the project.

     

    --Mike



  • 5.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Sep 21, 2017 04:01 PM

    Hi Mike,

     

    I have tried your approach, but below string was added at "Operation" field in VSI below the Match Style option.

    I am using DevTest 8.5.

     

    <ns:process xmlns:ns="http://service.xyz.com"> <![CDATA[ {   "listTransactionsRequest": {   "startDate":"00:00:00-00:00",   "endDate":"00:00:00-00:00",   "accountKey":{                                "companyNumber":00,                 "accountNO":"00"   }   } } ]]>     </ns:process>

     

    Thanks,

    Venu



  • 6.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Broadcom Employee
    Posted Sep 21, 2017 04:28 PM

    Pass the XPath expression to local-name() to get the operation name.  Pass it to string() to get the content.

     

    --Mike



  • 7.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Sep 22, 2017 04:48 PM

    Hi Mike,

     

    I created as below.

    1) I selected Generic XML Parser DPH.  .

    2) I added the JSON  DPH.

    3) I selected local-name() of the process element and assigned it to the operation name.

    4) I selected the string() of the process element and assigned it to the body.

     

    local-name(/SOAP-ENV:Envelope/SOAP-ENV:Body/ns:process/text()[2])
    string(/SOAP-ENV:Envelope/SOAP-ENV:Body/ns:process/text()[2])

     

    Bust Still Arguments are not created in VSI > Request Body.



  • 8.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Apr 04, 2018 10:14 AM

    Hi MIke,

    Arguments are not created for below message format.

    could you please guide me how to create arguments in VSI, if CDATA section having &lt; and &gt; instead of < and > in the message before and after the CDATA..

     

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ms="http://service.xyz.com/entity/msg/2017/" xmlns:hg="http://service.xyz.com/pdr/HG/entity/envelope/2017/">
      <SOAP-ENV:Header>
        <ms:Context>
          <ms:messageId>1</ms:messageId>
        </ms:Context>
        <hg:arContext>
          <service>DT</service>
          <action>getInformation</action>
        </hg:arContext>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns:process xmlns:ns="http://service.xyz.com/provider/HG/data/DT/2017/">

    &lt;![CDATA[{
      "TransactionsRequest": {
       "startDate":"2017-08-07T00:00:00-00:00",
       "endDate":"2017-08-08T00:00:00-00:00",
       "Key":{
         "Number":123456,
      "ProductCode":"ABCDE",
      
       }
      }
    }]]&gt;

    </ns:process>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>



  • 9.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Broadcom Employee
    Posted Sep 22, 2017 05:12 PM

    Remove "/text()[2]" from the paths like this;



  • 10.  Re: I am facing a problem while parsing an XML which is having CDATA and JSON message and to create an arguments while creating a VS.

    Posted Sep 28, 2017 11:49 AM

    Hi Mike,

     

    I tried as you mentioned, but still Arguments are not created in VSI.

    below is the request message which  I am using to create VS.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ms="http://service.xyz.com/entity/msg/2017/" xmlns:hg="http://service.xyz.com/pdr/HG/entity/envelope/2017/">
      <SOAP-ENV:Header>
        <ms:Context>
          <ms:messageId>1</ms:messageId>
        </ms:Context>
        <hg:arContext>
          <service>DT</service>
          <action>getInformation</action>
        </hg:arContext>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns:process xmlns:ns="http://service.xyz.com/provider/HG/data/DT/2017/"><![CDATA[{
      "TransactionsRequest": {
       "startDate":"2017-08-07T00:00:00-00:00",
       "endDate":"2017-08-08T00:00:00-00:00",
       "Key":{
         "Number":123456,
      "ProductCode":"ABCDE",
      
       }
      }
    }]]></ns:process>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

     

    Thanks,

    Venu