Service Virtualization

Expand all | Collapse all

Getting Error while using scriptable data protocol

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

    Posted 06-21-2018 12:19 PM

    While creating a virtual service , I have used scriptable data protocol to find the occurance of a string in an incoming request and set this occurance count as new arguement in the request . Below is the code :

     

    %javascript%
    import java.io.*;
    import java.util.*;
    import java.lang.String;
    import com.itko.util.ParameterList;

    String str1 = lisa_vse_request.getBodyText();
    int wordCount = 0;
    for (int i = 0; i < str1.length(); i++)
    {
    if (str1.charAt(i) == 'S')
    if(str1.charAt(i+1) == 'h')
    if(str1.charAt(i+2) == 'i')
    if(str1.charAt(i+3) == 'p')
    if(str1.charAt(i+4) == 'N')
    wordCount++;
    }
    wordCount = wordCount/2;
    wordCount -= 1;
    ParameterList p = new ParameterList();
    p.addParameter(new Parameter("shipNodeCnt", "wordCount"));

     

    I am getting below error :

    java.lang.RuntimeException: javax.script.ScriptException: <eval>:3:0 Expected an operand but found import
    import java.io.*;
    ^ in <eval> at line number 3 at column number 0
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:586)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:532)
    at com.itko.lisa.test.TestExec.executeScript(TestExec.java:1931)
    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)
    Caused by: javax.script.ScriptException: <eval>:3:0 Expected an operand but found import
    import java.io.*;
    ^ in <eval> at line number 3 at column number 0
    at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
    at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:534)
    at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:521)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:674)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:427)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:583)
    ... 14 more
    Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:3:0 Expected an operand but found import
    import java.io.*;
    ^
    at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:292)
    at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:277)
    at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:3182)
    at jdk.nashorn.internal.parser.Parser.expression(Parser.java:3282)
    at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:1150)
    at jdk.nashorn.internal.parser.Parser.statement(Parser.java:967)
    at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:773)
    at jdk.nashorn.internal.parser.Parser.program(Parser.java:709)
    at jdk.nashorn.internal.parser.Parser.parse(Parser.java:283)
    at jdk.nashorn.internal.parser.Parser.parse(Parser.java:249)
    at jdk.nashorn.internal.runtime.Context.compile(Context.java:1286)
    at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1253)
    at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:625)
    at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:532)
    ... 21 more

     

    Can anyone suggest the path forward for this.##



  • 2.  Re: Getting Error while using scriptable data protocol

    Posted 06-21-2018 12:29 PM

    I don't know javascript very well, but I didn't think it supports "import". Doesn't it require "importPackage()"?

     

    I would create it in beanshell, and probably try countMatches() rather than a for loop.



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



  • 4.  Re: Getting Error while using scriptable data protocol

    Posted 07-10-2018 04:09 AM

    Thanks Rick for the suggestion



  • 5.  Re: Getting Error while using scriptable data protocol

    Posted 06-25-2018 12:25 PM

    Hello Prasana,

     

    Did Rick's responses help you?

     

    Thank you,

    Heloisa



  • 6.  Re: Getting Error while using scriptable data protocol

    Posted 07-10-2018 04:10 AM

    Hello Maria ,

    sorry for the delayed response. Rick's suggestion did help. thanks.