Service Virtualization

Expand all | Collapse all

How to call a script on Magic String Argument

Jump to Best Answer
  • 1.  How to call a script on Magic String Argument

    Posted 11-17-2017 12:33 PM

    Hi,

    We have a case where we want to run a simple script on a Magic String Argument Response to modify the Run Time Response value pickup-up from the Request. Typical usage could be a string simple parsing or concat ... etc 

     

    The Magic String Documentation mentions that: "{{=request_.... }} can execute arbitrary Java code ....  but no clue how to implement it concretely ?

    Thanks



  • 2.  Re: How to call a script on Magic String Argument
    Best Answer

    Posted 11-17-2017 04:42 PM

    Others may be able to provide examples. 

     

    1) Is it possible to use a JSR step, Request/Response-Side Scriptable or Custom DPH in the VSM to implement logic to generate and store a value in testExec?  For example:

    <addPersonResponse>
        <status>SUCCESS</ns0:status>
        <personId>123456</personId>
        <uniqueId>{{myNewField}}</uniqueId>
    So long as myNewField is created prior to the Response step, the value should be able to substitute.

     

    2) Invoke a Static method on a class.  For example:

    The response body, can contain something like this:

    <addPersonResponse>
        <status>SUCCESS</ns0:status>
        <personId>123456</personId>
        <uniqueId>{{=java.util.UUID.randomUUID().toString();}}</uniqueId>
    The result is a response that looks like this:

    <addPersonResponse>
        <status>SUCCESS</status>
        <personId>123456</personId>
        <uniqueId>9a8f11ce-8eaa-478a-9e3a-4c58a5754f3c</uniqueId>

     

    3)  (Caveat: I have not tried this)  If one had a custom class / method that returns a string, you might:

    <uniqueId>{{=com.ca.MyClass.someMethod(lisa_vse_request);}}</uniqueId>

    someMethod's signature accepts com.itko.lisa.vse.stateful.model.Request; thereby giving access to all of the methods on the lisa_vse_request object as well as other classes.