Service Virtualization

Expand all | Collapse all

Error while using scriptable data protocol

Jump to Best Answer
  • 1.  Error while using scriptable data protocol

    Posted 03-05-2018 02:06 PM

    Hi,

     

    I am writing a simple scriptable data protocol in which i need to modify the incoming request.

     

    String theBody = lisa_vse_request.toString();

     

    after this few line of code to interpret the request.

     

    But i am getting error at processing this single line.

     

    below is the error

    Did not get a valid Request object so we ignore processing this transaction.
    java.lang.NullPointerException
    at bsh.ParseException.getErrorLineNumber(ParseException.java:276)
    at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:93)
    at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:669)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:426)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:582)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:531)
    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.common.DataProtocolStandardControlFilter.subPostFilter(DataProtocolStandardControlFilter.java:229)
    at com.itko.lisa.test.FilterBaseImpl.subFilter(FilterBaseImpl.java:148)
    at com.itko.lisa.test.FilterBaseImpl.postFilter(FilterBaseImpl.java:122)
    at com.itko.lisa.test.TestNode.doFilters(TestNode.java:1464)
    at com.itko.lisa.test.TestNode.doPostFilters(TestNode.java:1421)
    at com.itko.lisa.test.TestNode.executeNode(TestNode.java:995)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1280)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1195)
    at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1180)
    at com.itko.lisa.editor.WalkThruPanel.prepAndExecNode(WalkThruPanel.java:1048)
    at com.itko.lisa.editor.WalkThruPanel.access$900(WalkThruPanel.java:68)
    at com.itko.lisa.editor.WalkThruPanel$10.doCallback(WalkThruPanel.java:961)
    at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:194)
    at java.lang.Thread.run(Unknown Source)

     

    But when i am changing data protocol to Web services(soap) i am getting the response.

     

    can someone please tell me what additional thing i need to do to have a valid Request object.



  • 2.  Re: Error while using scriptable data protocol

    Posted 03-05-2018 03:06 PM

    Is it possible to post the entire script so we can look over it? 

    It is possible that an error elsewhere in the script throws and the interpreter gets confused as to the line number.

    If you want the body of the request, try using:  String theBody = lisa_vse_request.getBodyAsString(); 

    Arguments and MetaData can be accessed if DPHs prior to the Scriptable have populated them.

    The VS_<yourServiceName>.log also has a display showing the Inbound Request so you can check to ensure that a malformed request is not being processed.  The log entries look something like this:

    yyyy-MM-dd HH:mm:ss,794Z (10:29)[xxxx [VS_xxxxx_Run]/1] INFO - Inbound Request {"id":0,"operation":"POST /some/uri","arguments":{"arg_key_1":"arg_value_1","arg_key_2":"arg_value_2"}, "metadata":{<metaData key/value pairs here}, and so on }



  • 3.  Re: Error while using scriptable data protocol

    Posted 03-05-2018 03:10 PM

    Hi Joel,

     

    I am getting error for this line only I removed my remaining code and tried with above line only and got the same error. 



  • 4.  Re: Error while using scriptable data protocol

    Posted 03-05-2018 03:18 PM

    Ok, that would be a good test to verify the error.  I am interested in why the Request object is null.  

    Can you provide information as to what the incoming request looks like (i.e., transport HTTP, type of data such as REST, XML, binary, etc., if any DPHs are in the chain before this one, and a dump of the Inbound Request)?  Please remove any identifiable information if the input has customer specific data.



  • 5.  Re: Error while using scriptable data protocol

    Posted 03-06-2018 05:23 AM

    This is how the request looks like

    end point url: http://localhost:8030/itkoExamples/EJB3AccountControlBean

     

    <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><depositMoney xmlns="http://ejb3.examples.itko.com/"><accountId xmlns="">2295050569862</accountId><amount xmlns="">50.00</amount><desc xmlns="">ATM Deposit</desc></depositMoney></soapenv:Body></soapenv:Envelope>

     

    there no DPH before this one



  • 6.  Re: Error while using scriptable data protocol
    Best Answer

    Posted 03-06-2018 10:18 AM
      |   view attached

    I cannot explain why the exception is thrown, but the following is working in my local environment.

     

    Since the example is Soap XML, I would suggest using the Soap DPH as the first DPH in the chain and then follow on with a Scriptable. 

    The function of the Soap DPH is to parse the XML and set the operation. There is no real reason to use a Scriptable for parsing XML manually.

    The attached project ZIP file shows the differences. 

    Assume we have an input request containing XML as follows:

     

    Sending the request to the example_withoutSoapDPH.vsm running in ITR mode.  Stop after the Listen Step and look at the Events tab.

    The Scriptable DPH in the VSM places log messages showing the request and the body. 

     

    Running the example_withSoapDPH.vsm in ITR mode.

    In this VSM, the SOAP DPH fires first and is followed by a Scriptable that simply displays what the SOAP DPH created.

    Stop the previous service and run this service in ITR mode.

    Stop after the Listen Step and review the Events tab.

    The highlighted displays below show that the operation and arguments were parsed from the XML by the Soap DPH.

    The Scriptable in both VSMs accesses the lisa_vse_request object and retrieves different things from them. 

    Attachment(s)

    zip
    Prat130193.zip   21K 1 version


  • 7.  Re: Error while using scriptable data protocol

    Posted 03-06-2018 03:22 PM

    What if I have my XML request in escape format witch &Ltd; and &gt; how to

    process such request can you suggest any way ?

     

    On Tue, 6 Mar 2018 at 8:48 PM, Joel_Nesmith <



  • 8.  Re: Error while using scriptable data protocol

    Posted 03-07-2018 09:30 AM
      |   view attached

    In this scenario, you could consider two DPHs. DPHs fire in the order they occur in the Listen Step Filters. So, our first DPH converts the data into a format that another DPH can accept and process.

     

    DPH 1 could be a Scriptable DPH. In this DPH decode the XML string and set it back into the Request body:

    import com.itko.util.XMLUtils;

    String decodedXML = XMLUtils.decodeString( lisa_vse_request.getBodyAsString() );

    lisa_vse_request.setBody( decodedXML  );

     

    DPH2 is the SOAP DPH. This DPH parses the decoded XML into an arg list.

    Example of encoding and decoding an XML is attached as a Test Case.

     

    NOTE: DPHs do not operate on the original incoming transaction. This preserves the original request in case Live Invocation is used. This is a point of confusion for many in the Community. We see the question asked quite a bit about modifying the original request prior to sending it to the Live Invocation endpoint. DevTest's philosophy is that the Live Invocation should use the payload passed by the consumer. Modifying the original payload prior to sending 'live' is not an accurate representation of what the consumer application is expecting when the call is made. 

    Attachment(s)