0
votes

I cannot seem to get past the BeanShellInterpreter whenever I try and use __FileToString built-in function in a BeanShell PreProcessor script. The FileContents variable does get populated, but the script fails and I cannot work with it. Here is the code and the error messages...

try {
Integer count=vars.get("SessionId").length()-5;
vars.put("vAuth", vars.get("v_username") +     vars.get("SessionId").substring(count) + ":" );
log.info("Writing a info message");
   ${__FileToString(C:/tmp/DeltaConnectDemoTool_3_2_0S1_5515/bin/request.txt,,FileContents)};

log.info("Writing a second info message");
}
catch (Throwable ex ) {
    log.error("Failed to do this or that", ex);
}

The Error is

2016/11/17 15:52:18 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``try { Integer count=vars.get("SessionId").length()-5; vars.put("vAuth", vars.get . . . '' Encountered ":" at line 5, column 8.

2016/11/17 15:52:18 WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``try { Integer count=vars.get("SessionId").length()-5; vars.put("vAuth", vars.get . . . '' Encountered ":" at line 5, column 8.

2

2 Answers

0
votes

try putting the string path to file in double quotes, like:

${__FileToString("C:/tmp/DeltaConnectDemoTool_3_2_0S1_5515/bin/request.txt",,FileContents)};
0
votes

That's why inlining functions or variables into the script body is not recommended. You have 2 alternative options:

  1. Use the function in the "Parameters" section. If the functions returns some value you will be able to refer in later in the Beanshell code as Parameters or bsh.args[0] like:

    Beanshell Parameters

  2. Implement the function in the Beanshell code. In your case it can be FileUtils.readFileToString() function:

    String FileContent = org.apache.commons.io.FileUtils.readFileToString(new File("request.txt"));
    vars.put("FileContent", FileContent);
    

See How to Use BeanShell: JMeter's Favorite Built-in Component for some extra information on scripting in JMeter