Service Virtualization

Expand all | Collapse all

How to set arguments using scriptable DPH?

  • 1.  How to set arguments using scriptable DPH?

    Posted May 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");

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

     

    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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ms="http://service.xyz.com/entity/msg/2017/" xmlns:hg="http://service.xyz.com/pdr/HG/entity/envelope/2017/">
      <SOAP-ENV:Header>
        <ms:Context>
          <ms:messageId>1</ms:messageId>
        </ms:Context>
        <hg:arContext>
          <service>DT</service>
          <action>getInformation</action>
        </hg:arContext>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <ns:process xmlns:ns="http://service.xyz.com/provider/HG/data/DT/2017/">

    &lt;![CDATA[{
      "TransactionsRequest": {
       "startDate":"2017-08-07T00:00:00-00:00",
       "endDate":"2017-08-08T00:00:00-00:00",
       "Key":{
         "Number":123456,
      "ProductCode":"ABCDE",
      
       }
      }
    }]]&gt;

    </ns:process>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

     

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



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

    Broadcom Employee
    Posted May 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 May 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="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <ns2:WFContext xmlns:ns2="http://service.name.com/message/2003/">
          <ns2:messageId>b62b-d9e75d015089</ns2:messageId>
          <ns2:sessionId>f4fb1f834218</ns2:sessionId>
          <ns2:sessionSequenceNumber xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
          <ns2:creationTimestamp>2018-04-09</ns2:creationTimestamp>
          <ns2:activitySourceId>abc</ns2:activitySourceId>
          <ns2:subActivitySourceId>account</ns2:subActivitySourceId>
          <ns2:hostName>12345</ns2:hostName>
          <ns2:originatorId>678543</ns2:originatorId>
          <ns2:originatorIdType>ID</ns2:originatorIdType>
          <ns2:initiatorId>123</ns2:initiatorId>
          <ns2:initiatorIdType>INITI</ns2:initiatorIdType>
        </ns2:WFContext>
        <ns3:hulaContext xmlns:ns3="http://service.name.com/message/2003/">
          <service>Source</service>
          <action>Details</action>
          <ns2:processingMode>SYNC</ns2:processingMode>
          <contextType>Request</contextType>
          <password/>
          <keyword/>
          <ns2:behaviorVersion>0</ns2:behaviorVersion>
        </ns3:hulaContext>
      </soap:Header>
      <soap:Body>
        <ns4:process xmlns:ns2="<![CDATA[{"getAccountRequest":{"accountKeyList":[{"Number":"000","Code":"AAA","Number":"1245678"}]}}]]>http://service.name.com/message/2003/">&lt;![CDATA[{"getAccountRequest":{"accountKeyList":[{"Number":"000","Code":"AAA","Number":"1245678"}]}}]]&gt;</ns4:process>
      </soap:Body>
    </soap:Envelope>



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

    Broadcom Employee
    Posted May 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 May 09, 2018 11:49 AM

    below is the real message.

     

    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <ns2:WFContext xmlns:ns2="http://service.name.com/entity/message/2003/">
          <ns2:messageId>d9e75d015089</ns2:messageId>
          <ns2:sessionId>f4fb1f834218</ns2:sessionId>
          <ns2:sessionSequenceNumber xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
          <ns2:creationTimestamp>2018-04-09T14:56:57.133-07:00</ns2:creationTimestamp>
          <ns2:activitySourceId>AAA</ns2:activitySourceId>
          <ns2:subActivitySourceId>account-aggregation</ns2:subActivitySourceId>
          <ns2:hostName>host</ns2:hostName>
          <ns2:originatorId>1139</ns2:originatorId>
          <ns2:originatorIdType>ID</ns2:originatorIdType>
          <ns2:initiatorId>5362</ns2:initiatorId>
          <ns2:initiatorIdType>INTUIT</ns2:initiatorIdType>
        </ns2:WFContext>
        <ns3:Context xmlns:ns3="http://service.name.com/provider/HCFG/entity/envelope/2004/" xmlns:ns2="http://service.name.com/entity/message/2003/">
          <service>DataSource</service>
          <action>accountDetails</action>
          <ns2:processingMode>SYNC</ns2:processingMode>
          <contextType>REQUEST</contextType>
          <password/>
          <keyword/>
          <ns2:behaviorVersion>0</ns2:behaviorVersion>
        </ns3:Context>
      </soap:Header>
      <soap:Body>
        <ns4:process xmlns:ns2="http://service.name.com/entity/message/2003/" xmlns:ns3="http://service.name.com/provider/HCFG/entity/envelope/2004/" xmlns:ns4="http://service.name.com/provider/HCFG/data/digitalTrustedDataSource/2016/" contentType="application/json" encoding="charset=utf-8">&lt;![CDATA[{"getAccountRequest":{"accountKeyList":[{"companyNumber":"000","hoganProductCode":"abc","accountNumber":"1234"}]}}]]&gt;</ns4:process>
      </soap:Body>
    </soap:Envelope>



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

    Broadcom Employee
    Posted May 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:

    %beanshell%

    String theBody = lisa_vse_request.getBodyText();
    theBody = theBody.substring(theBody.indexOf("{"), theBody.lastIndexOf("}") + 1);
    _logger.info("{}", theBody);
    lisa_vse_request.setBodyText(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 May 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.

     

    Thanks,



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

    Broadcom Employee
    Posted May 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

    Attachment(s)

    zip
    sample.vrs.zip   831 B 1 version
    zip
    sample_rrpair.vsm.zip   2 KB 1 version
    zip
    sample_rrpair.vsi.zip   2 KB 1 version


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

    Broadcom Employee
    Posted May 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 May 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(ScriptExecHandler.java:919)
     at com.itko.lisa.test.ScriptExecHandler.wrapScriptEngine(ScriptExecHandler.java:906)
     at com.itko.lisa.test.ScriptExecHandler.makeScriptEngine(ScriptExecHandler.java:762)
     at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:426)
     at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:595)
     at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:532)
     at com.itko.lisa.test.TestExec.executeScript(TestExec.java:1917)
     at com.itko.lisa.vse.stateful.protocol.scriptable.ScriptableDataProtocolHandler.updateRequest(ScriptableDataProtocolHandler.java:70)
     at com.itko.lisa.vse.stateful.protocol.Marker.getTransaction(Marker.java:151)
     at com.itko.lisa.vse.stateful.protocol.TransactionLine$Line.next(TransactionLine.java:234)
     at com.itko.lisa.vse.stateful.protocol.TransactionLine$Line.next(TransactionLine.java:190)
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.getNextTransaction(TrafficMerger.java:520)
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.loadStatelessTransactions(TrafficMerger.java:474)
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.populateTraffic(TrafficMerger.java:147)
     at com.itko.lisa.vse.stateful.recorder.TrafficMerger.populateTraffic(TrafficMerger.java:124)
     at com.itko.lisa.vse.stateful.recorder.DefaultRecordingSession.storeRecordedTransactions(DefaultRecordingSession.java:876)
     at com.itko.lisa.vse.stateful.recorder.RecordingSession.storeRecordedTransactions(RecordingSession.java:551)
     at com.itko.lisa.vse.stateful.recorder.BuildProgressPanel$Worker.run(BuildProgressPanel.java:416)
     at java.lang.Thread.run(Thread.java:745)

     

    Thanks,

    Venu



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

    Broadcom Employee
    Posted May 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 May 09, 2018 04:45 PM

    thanks.. Rick for your solution.

     

    Now issue got resolved.