AnsweredAssumed Answered

Dymanic response with java code at runtime

Question asked by kartik.audichya on Jun 28, 2017
Latest reply on Jul 4, 2017 by kartik.audichya

Hi All,

I have  a request.




there can be any (1,2 0r...n) number of <bookstore> tags in request. number of <bookstore> tags in request vary.

I want to generate dynamic response with same number of <bookstore> tags in request.

in above case we have two <bookstore> tags so want same no here two tags in response.


I have added below java code in JSR-script step.


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import com.itko.lisa.vse.stateful.model.Request;

import com.itko.util.ParameterList;
import sun.misc.Request;


Request req =  testExec.getStateValue("lisa.vse.request");
           String xmlbody =req.getBodyText();




            DocumentBuilderFactory dbFactory  = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlbody);

            NodeList nList1 = doc.getElementsByTagName("bookstore");

            String str="";
            for (int temp = 0; temp < nList1.getLength(); temp++) {
                Node nNode = nList1.item(temp);

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;

                    str=str+ "<bookstore><isbn>"+eElement




I want to populate this "responsexml" in my mapped response.


mapped response:







I have also put xml parsing jars in hot deploy folder of devtest.

test is getting aborted at jsr-Script step.

please correct the above java code to build dynamic response at runtime.??

also help me with which jars I should put in hot deploy folder.??

I have also tried by adding scriptable data protocol at lisner step with same above code to store generated xmlresponse in variable(str).




Kartik Audichya