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 (! lisa_vse_request.getOperation().equals("useLoginRequest")){
System.out.println("No useLoginRequest detected, exiting script");
return;
}
ArrayList alResponse = testExec.getStateObject("lisa.vse.response");
TransientResponse response = alResponse.get(0);
responseBody = response.getBodyText();
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("
String requestID = expr.evaluate(dDoc);
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:
- 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?
- If no matching response is found, how can i prevent to send a feedback request? How can i achieve this in my VSM?