Service Virtualization

 View Only
  • 1.  How to do modify raw message body using Scriptable Data protocol

    Posted Apr 01, 2019 08:15 AM

    How to filter whole y node and add it to the body using Scriptable  Data Protocol

     

    Request:

    <x>

    <y>

    <z>1</z>

    </y>

    </x>

    J_NeSmith

    PanditiAvinash

    Thanks

    Nikhil



  • 2.  Re: How to do modify raw message body using Scriptable Data protocol

    Broadcom Employee
    Posted Apr 01, 2019 12:54 PM

    I try to add as little scripting to a workflow as possible (because it might hide away important functional features of your .vsm or .tst somewhere deep down in a statement.

     

    • I would solve the hardest part of your problem - i.e. getting the <y> sub-xml-tree out of the body by using an standard XML XPath filter inside your Listen Step.
      • You can filter in: lisa.vse.http.current.transaction.body
      • You can store the <y> sub-xml-tree in a property of your choice: e.g. mySubTree

     

    • You now have the property {{mySubTree}} available. Maybe that is already ok for your functionality? You can use that property later in your .vsm wherever you want
    • If you really want to update the current request body with the <y> sub-xml-tree then you will need to add a scriptable DPH after the XML XPath filter and you only need one line:

     

    lisa_vse_request.setBody(mySubTree);

     

    (But be aware that updating the body of a request only is useful if you need to run another DPH on the request for whatever reason. Because the body of a request is not used at all in the matching mechanism)

     

    Hope this helps,

     

    Cheers,

    Danny



  • 3.  Re: How to do modify raw message body using Scriptable Data protocol

    Broadcom Employee
    Posted Apr 01, 2019 02:09 PM

    I have seen issue when the updated request is going to LIVE system with lisa_vse_request.setBody(mySubTree); 

     

    The property "lisa.vse.http.current.transaction" holds the current transaction information in VS and lisa.vse.http.current.transaction.body" holds the request payload. 


    To change the VSE request payload, need to capture it first and modify that with the desired value and then set the new payload in the current transaction. 

    In the VSM, this can be done in an "Execute Script" step or in a "Scripted Assertion" with the below Bean shell code

     

    ------------------------------------------------------------------------------------
    import com.itko.lisa.vse.http.HTTPTransaction; 
    import com.itko.lisa.vse.http.Transaction; 

    String OriginalRequestBody = testExec.getStateValue("lisa.vse.http.current.transaction.body"); 
    String MofifiedRequestBody = OriginalRequestBody.replace("Original Text to be replaced","Replacement Text"); 

    HTTPTransaction transaction = ((HTTPTransaction) testExec.getStateObject("lisa.vse.http.current.transaction")); 
    transaction.setPayload(MofifiedRequestBody); 
    return testExec.getStateValue("lisa.vse.http.current.transaction"); 
    -------------------------------------------------------------

    Support created a knowledge article and it is available at https://comm.support.ca.com/kb/how-to-update-vse-request-and-send-it-to-live-system/KB000127510 

     

    Hope this helps.

     

    -Prema



  • 4.  RE: Re: How to do modify raw message body using Scriptable Data protocol

    Posted Sep 02, 2019 06:39 AM

    Hi,

    This link not working. ;(

    There is another one working?

    "Support created a knowledge article and it is available at https://comm.support.ca.com/kb/how-to-update-vse-request-and-send-it-to-live-system/KB000127510"

    -MP