Service Virtualization

  • 1.  Issue with response after VS Image Response Selection step

    Posted Jun 22, 2017 05:41 AM

    Hi,

     

    When receiving a "valid" request, my virtual service extracts a value from the response after the "VS Image Response Selection" step, puts it in a property and then uses this property to send a feedback request.

     

    My VSM looks as follows:

    The script looks as follows:

    import java.util.ArrayList;
    import com.itko.lisa.vse.stateful.model.TransientResponse;
    import javax.xml.parsers.*;
    import javax.xml.xpath.*;
    import org.w3c.dom.*;
    import org.xml.sax.InputSource;

    //If the operation is not a useLoginRequest, exit the script
    if (! lisa_vse_request.getOperation().equals("useLoginRequest")){
        System.out.println("No useLoginRequest detected, exiting script");
        return;
    }

    // Retrieve the responses-list from the environment
    // and get the first response (only response for synchronous HTTP)
    ArrayList alResponse = testExec.getStateObject("lisa.vse.response");
    TransientResponse response = alResponse.get(0); // No looping over list of responses needed as there can only be one
    responseBody = response.getBodyText(); //get hold of response body

    // Get the value of the requestID argument from the response body using xPath
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    Document dDoc = builder.parse(new InputSource(new StringReader(responseBody)));

    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xPath.compile("//requestId");
    String requestID = expr.evaluate(dDoc);

    //Set the requestID value into a property prpRequestID
    testExec.setStateValue("prpRequestID", requestID);

     

    All of this is working fine as long as the "VS Image Response Selection" step finds a match for the initial request.

    If i send a "wrong" request (let's say i misspelled an argument or operation name), so that no match is found, the script fails at:

    ArrayList alResponse = testExec.getStateObject("lisa.vse.response");

     

    With following error code:

    Target exception: java.lang.ClassCastException: Cannot cast java.util.Arrays$ArrayList to java.util.ArrayList
    in inline evaluation of: ``import java.util.ArrayList;  import com.itko.lisa.vse.stateful.model.TransientRe . . . '' at line number 21 exception is javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``import java.util.ArrayList;  import com.itko.lisa.vse.stateful.model.TransientRe . . . '' : Typed variable declaration : at Line: 21 : in file: inline evaluation of: ``import java.util.ArrayList;  import com.itko.lisa.vse.stateful.model.TransientRe . . . '' : ArrayList alResponse = testExec .getStateObject ( "lisa.vse.response" )

     

    Does this mean that the type of response with no match is different from the type of response with a match?

     

    My questions:

    1. How can i add some kind of validation that the script does not need to execute (or needs to exit) when the "VS Image Response Selection" step does not come up with a matching response?
    2. If no matching response is found, how can i prevent to send a feedback request? How can i achieve this in my VSM?


  • 2.  Re: Issue with response after VS Image Response Selection step
    Best Answer

    Posted Jun 22, 2017 07:36 AM

    Hi Davy,

     

    If I understand your requirement correct, you need to change the flow of the test if there is a no match response on VS Image response selection step.

     

    For this,

     

    1. Change the HTTP response code for unknown stateless or conversational requests in service image tab. say 404

    2. Add an assertion on the VS Image response selection step ensure property matches expression and select the property key as lisa.VS Image Response Selection.rsp or LASTRESPONSE and expression as (.*)404(.*).

    3. Change the flow to your desired step if the assertion is passed.

     

    Thanks,

    Venkatesh.



  • 3.  Re: Issue with response after VS Image Response Selection step

    Posted Jun 22, 2017 07:57 AM

    Davy,

     

    Did Venkatesh's recommendations help you out with this issue?



  • 4.  Re: Issue with response after VS Image Response Selection step

    Posted Jun 22, 2017 09:14 AM

    Thank you very much Venkatesh!

     

    It works for my first question, but I cannot seem to re-use for my second question.

     

    I added also the same assertion to the Virtual HTTPS Responder step, but it is not working.

    Do you have any idea on how i can skip the "sendFeedback Request" step if I don't have a matched response?

     

    Flow if matched response (which is fully working now):

    Listener --> Response Selection --> Responder --> sendFeedback --> Listener

     

    Flow if no matched response:

    Listener --> Response Selection --> Responder --> Listener



  • 5.  Re: Issue with response after VS Image Response Selection step

    Posted Jun 22, 2017 09:36 AM

    I was able to solve it now by using also the "lisa.VS Image Response Selection.rsp" in the "Ensure property matches expression" assertion used in the "Virtual HTTPS Responder" step, instead of the "lisa.Virtual HTTPS Responder.rsp" which returned nothing. 

     

    Now everything is fully operational :-)