Service Virtualization

Expand all | Collapse all

How to set arguments using scriptable DPH?

Jump to Best Answer
  • 1.  How to set arguments using scriptable DPH?

    Posted 05-09-2018 10:10 AM

    I want to set arguments in VSI using scriptable DPH for xml message which is having CDATA with JSON message.

    I have approached below process, but still service is not working.


    1.Downloaded json-simple-1.1.jar file and placed into lib>core folder.

    2. Reloaded the devtest workstation

    3. while creating virtual service I have selected Scriptable DPH.

    4. added script as below.

    import org.json.simple.JSONArray;
    import org.json.simple.JSONObject;
    import org.json.simple.parser.JSONParser;
    import org.json.simple.parser.ParseException;
    import com.itko.util.ParameterList;
    import com.itko.util.Parameter;
    JSONParser parser = new JSONParser();
    String str1 = testExec.getStateValue("Test_Process");

    String str = str1.substring(str1.indexOf("CDATA[")+6,str1.lastIndexOf("}")+1);
    str = str.trim();
    JSONObject jsonObject = (JSONObject) parser.parse(str);
    String ProductCode = (String) jsonObject.get("hoganProductCode");

    ParameterList args = lisa_vse_request.getArguments();
    args.addParameter(new Parameter("Hogan_Productcode", ProductCode));


    5. created virtual service.

    6. added XML Xpath query filter on Listener step and added property as "Test_Process".

    7.  loaded VSI and added argument as "Hogan_Productcode".

    8. saved the changes and deployed the service into VSE.


    below is request message which I have used for this service.


    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ms="" xmlns:hg="">
        <ns:process xmlns:ns="">

      "TransactionsRequest": {



    can some one review my code and help me to resolve the issue.

  • 2.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 10:53 AM

    I would approach a requirement like this using as much out-of-the-box functionality as possible, before resorting to importing libraries ... assuming you're on a version of DevTest that was released in the past few years and therefore has built-in JSON DPH support.


    Your envelope is SOAP, so I would use the SOAP DPH first.

    You want to manipulate pieces from that, for example you want to add the Request Data Manager DPH to move your "process" argument to the body.


    At this point, your CDATA might have been transparently removed. If not, create a scriptable DPH that reads the body and strips out the CDATA start and end pieces, so you're left with JSON as the body.


    Finally, add the JSON DPH, and your JSON elements are added as arguments.

  • 3.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 11:30 AM


    Hi Rick,


    thanks for your reply.

    I am using Devtest 10.1 and also I have tried above approach as you mentioned. but still arguments are not identified in VSI.


    sharing updated request message. if possible please share proper process once you success to set arguments.


    <soap:Envelope xmlns:soap="">
        <ns2:WFContext xmlns:ns2="">
          <ns2:sessionSequenceNumber xmlns:xsi="" xsi:nil="true"/>
        <ns3:hulaContext xmlns:ns3="">
        <ns4:process xmlns:ns2="<![CDATA[{"getAccountRequest":{"accountKeyList":[{"Number":"000","Code":"AAA","Number":"1245678"}]}}]]>">&lt;![CDATA[{"getAccountRequest":{"accountKeyList":[{"Number":"000","Code":"AAA","Number":"1245678"}]}}]]&gt;</ns4:process>

  • 4.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 11:43 AM

    Your two messages are different, but both slightly invalid as SOAP messages, although they claim to use the SOAP envelope. Do you have a real message, or are you trying to construct it manually?

  • 5.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 11:49 AM

    below is the real message.


    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="">
        <ns2:WFContext xmlns:ns2="">
          <ns2:sessionSequenceNumber xmlns:xsi="" xsi:nil="true"/>
        <ns3:Context xmlns:ns3="" xmlns:ns2="">
        <ns4:process xmlns:ns2="" xmlns:ns3="" xmlns:ns4="" contentType="application/json" encoding="charset=utf-8">&lt;![CDATA[{"getAccountRequest":{"accountKeyList":[{"companyNumber":"000","hoganProductCode":"abc","accountNumber":"1234"}]}}]]&gt;</ns4:process>

  • 6.  Re: How to set arguments using scriptable DPH?
    Best Answer

    Posted 05-09-2018 01:22 PM

    For this message, you want SOAP -> XML -> Request Data Manager -> Scriptable -> JSON as your stack of DPH


    In the RDM, you probably want to move argument "Header_Context_action" to "operation"

    In RDM, you want to move argument "Body_process" to "request body"

    In the scriptable DPH, you want this:


    String theBody = lisa_vse_request.getBodyText();
    theBody = theBody.substring(theBody.indexOf("{"), theBody.lastIndexOf("}") + 1);"{}", theBody);


    I get this as my request in DevTest when I have that complete stack of DPHs. If you want fewer arguments, you can delete them in your RDM DPH:

  • 7.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 02:14 PM

    Hi Rick,


    thanks for your response.

    could you please share VSI and VSM which you developed for this?

    mean while I will try this approach as you mentioned, will het back to you If any issues.



  • 8.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 03:35 PM

    I copied one of the previous messages as sample-rsp.xml, and the real message as sample-req.xml.


    Attached is the model and image I created, along with the VRS that I created while generating the virtual service


    zip   831B 1 version
    zip   2K 1 version
    zip   2K 1 version

  • 9.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 03:41 PM

    I'm looking through similar discussions in this community. Is this the same question that you asked in September last year, and in April this year? Are all of those answered now?

  • 10.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 04:15 PM

    Hi Rick,

    yes, I have posted same questions last year and this year and now got answer for my posts.


    but still I am getting below error before finish option.


    java.lang.IllegalArgumentException: No engine registered for language [beanshell]
     at com.itko.lisa.test.ScriptExecHandler.checkNullScriptEngine(
     at com.itko.lisa.test.ScriptExecHandler.wrapScriptEngine(
     at com.itko.lisa.test.ScriptExecHandler.makeScriptEngine(
     at com.itko.lisa.test.ScriptExecHandler.executeScript(
     at com.itko.lisa.test.ScriptExecHandler.executeScript(
     at com.itko.lisa.test.ScriptExecHandler.executeScript(
     at com.itko.lisa.test.TestExec.executeScript(
     at com.itko.lisa.vse.stateful.protocol.scriptable.ScriptableDataProtocolHandler.updateRequest(
     at com.itko.lisa.vse.stateful.protocol.Marker.getTransaction(
     at com.itko.lisa.vse.stateful.protocol.TransactionLine$
     at com.itko.lisa.vse.stateful.protocol.TransactionLine$
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.getNextTransaction(
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.loadStatelessTransactions(
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.populateTraffic(
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.populateTraffic(
     at com.itko.lisa.vse.stateful.recorder.DefaultRecordingSession.storeRecordedTransactions(
     at com.itko.lisa.vse.stateful.recorder.RecordingSession.storeRecordedTransactions(
     at com.itko.lisa.vse.stateful.recorder.BuildProgressPanel$




  • 11.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 04:45 PM

    I don't know that error. Is it when using the VRS file or when doing it yourself?

  • 12.  Re: How to set arguments using scriptable DPH?

    Posted 05-09-2018 04:45 PM

    thanks.. Rick for your solution.


    Now issue got resolved.