2015-11-08 106 views
0

我想寫使用BSF後處理器JMeter的變量的值到一個文件,但如果我把它有沒有價值獲得空指針異常

temp6 = vars.get("host_2_g1"); 
out.write(temp6); 

以下是一個變量正在一個錯誤在行[腳本]:消息我在JMeter的日誌文件中看到

2015/11/08 21:47:29 WARN - jmeter.extractor.BSFPostProcessor: Problem in BSF script org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: // VALUES is the Reference Name in regex ext . . . '' : vars .get ("host_2_g1") 

BSF信息0柱:columnNo

我已經知道沒有返回b變量提供Ÿ名稱「host_2_g1」,我如何處理它,以至少我的代碼工作?

回答

0

有多種問題,你的腳本:

  1. out應該大寫:OUT
  2. OUTPrintStream的簡寫。它不會寫字符串,因此需要字節數組,因此您需要通過getBytes()方法將host_2_g1變量轉換爲字節數組方法
  3. 如果您的host_2_g1變量可能未設置 - 最好添加顯式檢查。

修改後的代碼:

temp6 = vars.get("host_2_g1"); 

if (temp6 != null) { 
    OUT.write(temp6.getBytes()); 
} 
else { 
    OUT.write("host_2_g1 is null".getBytes()); 
} 

How to Use BeanShell: JMeter's Favorite Built-in Component參見指南在JMeter的BeanShell的腳本的詳細信息。