Service Virtualization

  • 1.  Modifying URLPARAM0 value dynamically

    Posted Oct 19, 2017 11:02 AM

    I am trying to modify URLPARAM0 argument in lisa.vse.request using beanshell. I have created JSR-223 step after HTTP/s Listner step. I have couple of issues in this:

     

    1. _logger.debug is not working for me.

    2. lisa_vse_request.setArguments(valueToAdd); is throwing error.

     

    =========================================================

    //Code: Beanshell

    =========================================================

    import com.itko.util.ParameterList;
    import com.itko.util.Parameter;

    _logger.debug("All Arguments:");
    ParameterList args = lisa_vse_request.getArguments();

    String valueToAdd = "";

    // I have only one Argument - which is URLPARAM0
    for(i=0;i<args.size();i++) {
       Parameter thisParameter = args.get(i);
       thisName = thisParameter.getName();
       thisValue = thisParameter.getValue();
       thisValue = thisValue.replaceAll("MigB6ScXQjCSnyg9-vQO7w", "MigB6ScXQjCSnyg9-vQO7Z");
       valueToAdd = valueToAdd + thisName + "=" + thisValue;
    }
    lisa_vse_request.setArguments(valueToAdd);
    //ParameterList args = lisa_vse_request.getArguments();
    return lisa_vse_request;

     

    Any help is greatly appreciated.



  • 2.  Re: Modifying URLPARAM0 value dynamically

    Posted Oct 19, 2017 11:44 AM

    Before we try to solve the code snippet...  Can you tell us why you need to change the last digit of the incoming URLPARAM0 from 'w' to 'Z'? Is there some reason the URLPARAM0 Comparison Operator and Value in the VSI can not handle a regex to accept both values or map the key ending with "Z" to the specific transaction ending with "w"?

     

    I believe the logic is syntactically incorrect. setArguments() has no signature to accept a String as input.

     

    Using the SDK - DevTest Solutions - 10.1 - CA Technologies Documentation  

    OR

    Look in the "doc" directory in your installation folder for an examples.zip file.

    Navigate to com/itko/util/ParameterList and review constructor, containsKey, get, put, and addParameters methods.

     

    _logger.debug(" ") only outputs if logging.properties is set to DEBUG. _logger.info("") will display lines in the log if logging.properties is set to INFO. INFO will also place an entry in the Events tab in ITR.

     

    The lisa_vse_request.setArguments() methods needs a ParameterList so you need to convert the String.

    The key/value pairs in the String need to be delimited by '&'.

    The ParameterList constructor can use the String as input. (e.g., "key1=value1&key2=value2")

    No need to return lisa_vse_request as it is globally available, but you could return valueToAdd which would set LASTRESPONSE for you. 



  • 3.  Re: Modifying URLPARAM0 value dynamically

    Posted Oct 19, 2017 03:25 PM

    Here is finally I am able to change the Arguments, Attributes, and Metadata values dynamically using Scripted DHP.

    =============================================

    import com.itko.util.ParameterList;
    import com.itko.util.Parameter;
    import com.itko.lisa.vse.stateful.model.Request;
    import com.itko.lisa.script.logger;
    import org.apache.log4j.Logger;

    //Change Operations;
    //ParameterList opts = lisa_vse_request.getOperation();
    //opts.removeAllParameters();
    //opts.addParameters("GET /v1/credit/accounts/MigB6ScXQjCSnyg9-vQO7Z/business_loan_activities");
    //return opts;

    //Change Arguments;
    ParameterList args = lisa_vse_request.getArguments();
    args.removeAllParameters();
    args.addParameters("URALPARAM0=MigB6ScXQjCSnyg9-vQO7Z");
    lisa_vse_request.setArguments(args);
    //return args;

    //Change HTTP Attributes URLPARAM0 is at Attr-3
    ParameterList atbs = lisa_vse_request.getAttributes();
    atbs.removeAllParameters();
    atbs.addParameters("HTTP-Segment-Attr-0=v1&HTTP-Segment-Attr-1=credit&HTTP-Segment-Attr-2=accounts&HTTP-Segment-Attr-3=MigB6ScXQjCSnyg9-vQO7Z&HTTP-Segment-Attr-4=business_loan_activities");
    lisa_vse_request.setAttributes(atbs);
    //return atbs;

    //Change MetaData Tag Value HTTP-URI">/v1/credit/accounts/MigB6ScXQjCSnyg9-vQO7s/business_loan_activities</parameter>
    ParameterList meta = lisa_vse_request.getMetaData();
    meta.removeAllParameters();
    meta.addParameters("HTTP-Method=GET&HTTP-URI=/v1/credit/accounts/MigB6ScXQjCSnyg9-vQO7Z/business_loan_activities&HTTP-Version=1.1&Host=localhost:10006&User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0&Accept=text/html,application/xhtml xml,application/xml;q=0.9,*/*;q=0.8&Accept-Language=en-US,en;q=0.5&Accept-Encoding=gzip, deflate&Connection=keep-alive&Upgrade-Insecure-Requests=1&lisa.vse.request.client.id=127.0.0.1:53838&matchedRule=GET /v1/credit/accounts/{URLPARAM0}/business_loan_activities/");
    lisa_vse_request.setMetaData(meta);
    //return meta;
    return lisa_vse_request;



  • 4.  Re: Modifying URLPARAM0 value dynamically

    Posted Oct 19, 2017 03:42 PM

    So, it seems that you want every request, regardless of the value of the original incoming request, to have these and only these values when the transaction enters the VSI?

     

    Why not just set the VSI Match Style = "operation" or "signature" when the operation is 

    GET /v1/credit/accounts/{URLPARAM0}/business_loan_activities and use a META for the response. 

     

    I do not see any difference except that you would not need the script logic.

    Are we missing something?



  • 5.  Re: Modifying URLPARAM0 value dynamically

    Posted Oct 19, 2017 04:18 PM

    Hi Joe,

     

    Situation: Consumer always use the same API Call (No change to any thing).

    we have to track the number of times the consumer consumes using counter with requestersid. Each time we have to provide different response depends on the counter. In the response, we have to provide a API link to get the current response status for future reference. That's why we are dynamically creating a new API link in the response as "Future Reference". All responses we have to save physically and able to use when consumer request next time.



  • 6.  Re: Modifying URLPARAM0 value dynamically
    Best Answer

    Posted Oct 19, 2017 04:59 PM

    OK, thanks for the insight into the requirement. It is helpful for understanding what you are trying to do.

    You may want to research the Persistent Model Map to see if it can help you at all.

    A sample guide to help with various scripting subject matter is located here: DevTest 8.0 - Scripting Guide - V1.1.pdf