非法使用未定义的变量,类或'void'文字

时间:2013-06-26 23:56:47

标签: javascript jmeter beanshell jmeter-plugins

每当尝试使用以下代码调用JavaScript函数时,我都会遇到异常:

  

断言失败消息:org.apache.jorphan.util.JMeterException:调用bsh方法时出错:eval源文件:内联评估:``vars.put(“FinalData”,decode64(PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiI ...'':非法)使用未定义的变量,类或'void'文字

以下是BSFPostProcess:

function decode64(input) {
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;

     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
     var base64test = /[^A-Za-z0-9\+\/\=]/g;
     if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
              "Expect errors in decoding.");
     }
     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

     do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
           output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
           output = output + String.fromCharCode(chr3);
        }

        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

     } while (i < input.length);
     return output;
}

我试图使用下面的代码在BSF Assertion Sampler下调用它。

vars.put("FinalData", decode64(${Data}));

OR

vars.put("FinalData", decode64(vars.get("Data")));

数据是可变的并存储值:

  

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI / Pgo8UmVxdWVzdFBhcnRzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly9zZXJ2aWNlcy5teWNjY3BvcnRhbC5jb20vQWx0ZXJuYXRlUGFydFNvdXJjaW5nL0FsdGVybmF0ZVBhcnRTb3VyY2luZyI + CiAgICA8UGFydFJlcXVlc3RJZGVudGlmaWVyPjQwNTM4MTU8L1BhcnRSZXF1ZXN0SWRlbnRpZmllcj4KPC9SZXF1ZXN0UGFydHNSZXNwb25zZT4 =

FinalData是预定义变量。

1 个答案:

答案 0 :(得分:1)

这不是预处理器的工作原理,您有两个选择:

无论如何,你会删除预处理器中的函数声明