AnsweredAssumed Answered

Issue with response after VS Image Response Selection step

Question asked by Konfu on Jun 22, 2017
Latest reply on Jun 22, 2017 by Konfu

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?

Outcomes