Service Virtualization

  • 1.  Based on incoming value/format how to select different responses from VSI?

    Posted Sep 27, 2017 12:58 PM

    Greetings Team,

     

    How are you doing, today!!!

     

    I have deployed a JMS based Virtual service and incoming message is delimited text. Have applied Delimited and Scriptable DPH to parse the incoming request.

     

    The Source system generates two messages which is almost identical, the only difference is at val5 

     

    a) The create call has value in the format - AAA PARFLT 111-111111-M ABC

    b) Update Call has the value in format- AAA PARFLT 111-111111-111111 ABC

     

    Both these calls are under the same operation- Request 1.

     

    The challenge is for Add request have to extract only "111-111111-M" and for update "111-111111-111111" from the incoming request and insert it in the response.

     

    I have created 2 transactions and set the Match Style as "Exact" and Comparision as "Anything".

     

    How do I configure my VS to respond with different responses based on Add or Update incoming request?



  • 2.  Re: Based on incoming value/format how to select different responses from VSI?

    Broadcom Employee
    Posted Sep 27, 2017 03:38 PM

    Hi,

     

    It sounds like you're already using the Scriptable DPH.  In the same script, you can set the operation name using the setOperation() method on the incoming request.  Now, with different operation names, you can distinguish between them in the VSI.

     

    --Mike



  • 3.  Re: Based on incoming value/format how to select different responses from VSI?

    Posted Sep 27, 2017 03:44 PM

    Thanks Mike for the quick response.

     

    Could you please point me to resource where I can find details about different methods and their usage, that I can leverage to extend my DPH?

     

    In my case both the request are coming in the same operation, only the message initiation method changes depending on weather its Create or Update.



  • 4.  Re: Based on incoming value/format how to select different responses from VSI?
    Best Answer

    Broadcom Employee
    Posted Sep 27, 2017 04:19 PM

    Hi Maddy,

     

    You have two choices.

     

    First, when you initially create a Scriptable DPH, you're presented with some sample code.  Search for "setOperation()" to see how to change the operation.  Here's a copy of the sample code for convenience:

     

    %beanshell%
    /*
    // You can use %beanshell%, %groovy% or %javascript% or some other installed JSR-223 scripting language
    // This example is for beanshell

    import com.itko.util.ParameterList;

    // Manipulate operation
    String operation = lisa_vse_request.getOperation();
    lisa_vse_request.setOperation(operation + " - updated");

    // This is implicitly set by calling setBodyText() or setBodyBytes
    boolean isBinary = lisa_vse_request.isBinary();
    lisa_vse_request.setBinary(false);

    // Manipulate request body text
    String theBody = lisa_vse_request.getBodyText();
    lisa_vse_request.setBodyText("New body");

    // Manipulate request body as binary
    byte[] b = lisa_vse_request.getBodyBytes();
    lisa_vse_request.setBodyBytes(b);

    // Other
    String asString = lisa_vse_request.toString();
    long id = lisa_vse_request.getId();


    // Arguments, Attributes, and Metadata are all ParameterList

    ParameterList args = lisa_vse_request.getArguments();
    lisa_vse_request.setArguments(args);

    ParameterList attributes = lisa_vse_request.getAttributes();
    lisa_vse_request.setAttributes(attributes);

    ParameterList metadata = lisa_vse_request.getMetaData();
    lisa_vse_request.setMetaData(metadata);

    // Working with ParameterList

    ParameterList p = new ParameterList();

    // Do we want to allow dupes or not?
    p.setAllowDupes(true);
    boolean areDupesAllowed = p.isDupesAllowed();

    // Adding parameters
    p.addParameters("key1=val1&key2=val2");  // many at once
    p.addParameter(new Parameter("key3", "val3")); // one at a time

    // Looking up parameters
    String theVal = p.getParameterValue("key1");

    // Updating parameters
    p.setParameterValue("key3", "newVal");

    // Removing parameters
    p.removeParameter("key1");

    // Removing all parameters
    p.clear();
    */

    Alternatively, you can create a custom DPH:

     

    https://docops.ca.com/devtest-solutions/10-1/en/using/using-the-sdk

     

    --Mike



  • 5.  Re: Based on incoming value/format how to select different responses from VSI?

    Posted Sep 27, 2017 04:24 PM

    Thanks again Mike:) Will try out the options provided above.