Service Virtualization

  • 1.  Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Oct 08, 2015 02:41 PM

    Hello All,

     

    We are trying to send an incoming request to LIVE system by changing couple of argument values. We have applied all solutions present on community but in vain. Below are the codes we are using currently. Any help is appreciated:

     

    Code 1:

     

    import com.itko.lisa.vse.stateful.model.Request;

    import com.itko.util.ParameterList;

     

     

    ParameterList args = lisa_vse_request.getArguments();

    arg1 = args.getParameterValue("body_serviceOrder_orderLines_orderLine_service_characteristics_characteristic_values_value_5");

    arg2 = args.getParameterValue("body_serviceOrder_orderLines_orderLine_service_characteristics_characteristic_values_value_4");

    args.setParameterValue("body_serviceOrder_orderLines_orderLine_service_characteristics_characteristic_values_value_5", "epc3928");

    args.setParameterValue("body_serviceOrder_orderLines_orderLine_service_characteristics_characteristic_values_value_4", "cisco");

    testExec.setStateValue("arg1",arg1);

    testExec.setStateValue("arg2",arg2);

    lisa_vse_request.setArguments(args);

     

    Code 2 (from community https://communities.ca.com/message/241828411#241828411):

     

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

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

    HTTPTransaction transaction = ((HTTPTransaction) testExec.getStateObject("lisa.vse.http.current.transaction"));

     

    //construct the logic to replace the username and password values as per your requirement

    transaction.getRequestContentAsString().replace("eurodocsiscm", "cisco");

    transaction.getRequestContentAsString().replace("Cable Modem", "epc3928");

     

     

    testExec.setStateObject("lisa.vse.http.current.transaction",transaction);

    return testExec.getStateValue("lisa.vse.http.current.transaction");

     

    Our prime goal is to replace argument values with cisco and epc3928 and send this changed request to LIVE system.

     

    With code 1, though we are able to change attribute values but the request sent to LIVE system is the same as incoming request which we find strange.

     

    With code 2, it is not at all replacing the values.

     

    Thanks,

     

    Ankush



  • 2.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Broadcom Employee
    Posted Oct 12, 2015 03:18 PM

    Hi Ankush, I am not sure that you need to write the code to direct your request to LIVE system.

     

    What I understood is if your request doesn't match the specific transaction then you want go to LIVE system. If this is the scnario, then  you should get a Meta response if the specific transaction is not returned and return something in Meta response and check that in the VSM with an assertion and change the flow to LIVE Invocation step.

     

    For example:

    - In META Response--> Meta data, add isMeta=true.

    - In VS Image response selection step, add an assertion to check the lisa.vse.response has isMeta=true then set the VSM Flow to go to LIVE Invocation step.

    Hoe the information helps you.



  • 3.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Community Manager
    Posted Oct 14, 2015 02:42 PM

    Ankush -- did Prema's information help you?



  • 4.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Oct 15, 2015 04:19 PM

    If you have exact matches defined for the virtualized responses you want, you could set "return false;" in the match script for the meta responses, and use VSM executions mode "Stand In" to send unmatched responses to the live system.



  • 5.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Oct 15, 2015 04:32 PM

    Hello Ankush,

     

                  If you are looking at changing the request arguments in the request XML, one way is for you to pick the request body from the incoming request and replace the values using replace java function and use the updated request body to trigger the live service by adding a Web Service XML execution step, just put the property in Request XML tab of that step.

     

    req=testExec.getStateObject("lisa.vse.request");

    testExec.log(testExec.getStateValue("lisa.vse.request").toString());

    String payload = req.getBodyText();

    payload=payload.replace(Value,New Value);

    testExec.setStateValue("Request",payload);

     

    Now in the web service XML execution step, use {{Request}} under RawXML.Then, you can build the response object, based on the response from the web service execution step as below. (Add a javascript step after Web service execution step)

     

    com.itko.lisa.vse.stateful.model.TransientResponse r = new com.itko.lisa.vse.stateful.model.Response().createTransientCopy();

    r.setBodyText(testExec.getStateValue("lisa.Web Service.rsp").toString());

    com.itko.util.ParameterList pl = new com.itko.util.ParameterList();

    pl.addParameter(new com.itko.util.Parameter("HTTP-Response-Code", "200"));

    pl.addParameter(new com.itko.util.Parameter("HTTP-Response-Code-Text", "OK"));

    pl.addParameter(new com.itko.util.Parameter("Content-Type", "text/xml"));

    r.setMetaData(pl);

    testExec.setStateValue("lisa.vse.response", r);

     

    Now the response that you build here, will be sent in the Virtual Service Responder step.

     

    Hope this helps. I am not sure if there is an easier way to do this, but this approach worked for us.

     

    Thanks,

    Surya.



  • 6.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Jan 23, 2017 07:48 AM

    Hi Surya,

     

    The same requirement i have to implement in my project.

    Am following the steps which you have recommended, am having a couple of queries on this solution

     

    * Could you please guide me where should i add below piece of code in my VSM.

    req=testExec.getStateObject("lisa.vse.request");

    testExec.log(testExec.getStateValue("lisa.vse.request").toString());

    String payload = req.getBodyText();

    payload=payload.replace(Value,New Value);

    testExec.setStateValue("Request",payload);

     

    * Should i need to inherit any classes to make the above code work?

     

    Steps which i have followed:

    1) After listen step i have added java script step and used below code 

    req=testExec.getStateObject("lisa.vse.request");

    testExec.log(testExec.getStateValue("lisa.vse.request").toString());

    String payload = req.getBodyText();

    payload=payload.replace(Value,New Value);

    testExec.setStateValue("Request",payload);

     

    2) After the above step i added web service execution step to call the live system with modified request

    3) After the web service execution step i added one more java script step to build the response object.

    4) The response object which has been built is sent virtual Responder step.

     

    I have kept VSM in ITR mode to test a sample request, it's throwing below exception while executing the first code.

     

    ============================================================================
    | Exception:
    ============================================================================
    | Message: Script throw an exception: bsh.EvalError: Sourced file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : Undefined argument: BUY : at Line: 4 : in file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : ( BUY , New_BUY )
    in inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' at line number 4
    ----------------------------------------------------------------------------
    | Trapped Exception: bsh.EvalError: Sourced file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : Undefined argument: BUY : at Line: 4 : in file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : ( BUY , New_BUY )
    in inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' at line number 4
    | Trapped Message: javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : Undefined argument: BUY : at Line: 4 : in file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : ( BUY , New_BUY )
    in inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' at line number 4
    ----------------------------------------------------------------------------
    STACK TRACE
    javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : Undefined argument: BUY : at Line: 4 : in file: inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' : ( BUY , New_BUY )
    in inline evaluation of: ``req=testExec.getStateObject("lisa.vse.request"); testExec.log(testExec.getState . . . '' at line number 4
    at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:102)
    at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:669)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:426)
    at com.itko.lisa.test.UserScriptNode._execute(UserScriptNode.java:202)
    at com.itko.lisa.test.UserScriptNode.execute(UserScriptNode.java:172)
    at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1280)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1195)
    at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1180)
    at com.itko.lisa.editor.WalkThruPanel.prepAndExecNode(WalkThruPanel.java:1048)
    at com.itko.lisa.editor.WalkThruPanel.access$900(WalkThruPanel.java:68)
    at com.itko.lisa.editor.WalkThruPanel$10.doCallback(WalkThruPanel.java:961)
    at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:194)
    at java.lang.Thread.run(Unknown Source)
    ============================================================================

     

    Could you please help me on this?

    You can also mail me at aravindtv123@gmail.com

     

    Regards,

    Aravind 



  • 7.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Jul 07, 2016 12:16 PM

    I do have a same requirement as Ankush.

     

    Change lisa.vse.request which is sent to live invocation step.

    As per Prema's comment, It assumes that VSI Selection Step has happened. Although in my case, and I assume in Ankush's case as well, we want to modify the lisa.vse.request and execute live invocation step even before VSI selection happens. Consider that we are not using VSI selection at all and just creating a VSM by scratch which is just passing the request to live system with some modifications in the request headers/body and send the response back. I know we can use a VSI selection step in this one too (so that it prepares a proper lisa.vse.response object), but I don't want to use an extra step.

     

    The modification is happening as per Option 1 from ankush's comment, although the request received by live system is the one received initially by the virtual service.

     

    VSM steps -

    HTTP Listen - has a scriptable dph which modifies lisa.vse.request

    HTTP Live Invoc - I see the lisa.vse.request object being changed but the request sent to live system has the initial lisa.vse.request at HTTP Listen step.

    HTTP Respond

     

    Thanks,

    Prakhar



  • 8.  Re: Modify argument values in request to send in LIVE SYSTEM/Image Validation mode?

    Posted Jun 07, 2018 06:21 PM

    Hi, Need help to resolve a issue with live request invocation.

     

    Overview: I have a REST(GET) call to virtualize, with dynamic parameter as 'zip code' in URI .. the identifier is represented here by {URLPARAM0} .. now along with the host, port and URI part, we do have some arguments that needs to be passed in the request(basically some key) so that real system recognize the call and responds back, without those arguments it denies the access to the system and the call fails.

     

    Issue: Now our requirement is to route the call to live system if specific response is not found. To implement this, I have created the meta response filter and put an assertion in the VSM, and able to see, for unknown zip code the request is getting routed to Live system... GOOD, BUT once the request goes to live, it is failing ... because while doing the live invocation VSM is not passing the arguments (though it is receiving the same as part of original incoming request) and live system is denying the access

     

    What do I need to do to make sure, VSM passes the required arguments along with the URI while making the live invocation? It doesn't have to change or add anything, it just has to pass whatever it has received from the client

     

    Any kind of suggestions are highly appreciated

     

    Thanks

    Mohammad