我无法捕获使用httpsamplerresult的方法。
我该怎么做才能获得示例时间(MS),字节,已发送字节,延迟,连接时间和其他参数。
我无法在听众中获取这些详细信息:在表和其他听众中查看结果。
有人可以帮助我。我没有得到如何设置所有变量的实现。
以下是我的Java请求采样器的代码。
public HTTPSampleResult runTest(JavaSamplerContext arg0)
{
HTTPSampleResult result = new HTTPSampleResult();
//Below array contains the user id and password that comes with every chirp
byte[] idpwd = new byte[]{38,85,115,101,114,78,97,109,101,61,101,82,101,103,38,85,115,101,114,80,97,115,115,119,111,114,100,61,97,98,99,49,50,51};
//below we are converting the hex string coming as parameter to Byte Array.
byte arr[] = toByteArray(arg0.getParameter("HEX"));
//Below we are getting the lengths of both the arrays : idpwd & arr
int aLen = arr.length;
int bLen = idpwd.length;
////////////////////////////////////////////////////////////////////
//below we are initializing the byte array to contain both our hex string converted to byte array and the id-pwd.
byte[] actual_Chirp = new byte[aLen+bLen];
//Below we are concatenating both the arrays.
//first we are adding the arr to the actual_chirp.
//then we are adding the idpwd from the alen to blen.
System.arraycopy(arr, 0, actual_Chirp, 0, aLen);
System.arraycopy(idpwd, 0, actual_Chirp, aLen, bLen);
//Here we we actually hit the meter service
try
{
URL obj = new URL(arg0.getParameter("URL"));
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
result.sampleStart();
/////////////////////////////////////////////////////////////////////////
os.write(actual_Chirp);
os.flush();
os.close();
///////////////////////////////////////////////////////////////////////
result.sampleEnd();
result.setContentType(con.getContentType());
result.setSamplerData(POST_URL);
System.out.println(con.getContentType());
System.out.println(result.getHTTPMethod());
System.out.println(result.getRequestHeaders());
System.out.println(Hex.encodeHexString(result.getResponseData()));
result.setSuccessful(true);
System.out.println(con.getResponseMessage());
}
catch(Exception E)
{
}
//
return result;
}
我认为您缺少示例标签,或者更多。HTTPSampleResult
(或SampleResult
一般)是一种容器,用于累积与执行相关的所有数据。所有可视化器或记者仅依赖于统计数据的SampleResult
,因此,如果他们忽略了您的统计数据,则意味着您没有在其中放置足够的数据供他们消耗。您的良好参考将是httphc4impl.java的源代码。我可以发现一些缺少的东西:
-
最明显的标签,这是导致您的问题的原因
result.setSampleLabel("your label");
通常,这是在
result.sampleStart();
之前和构造函数之前设置的 -
我无法想象这可能会导致采样器被忽略,但无论如何:通常您应该设置响应代码和响应消息。这是上面提到的源代码的示例:
res.setResponseCode(Integer.toString(statusCode)); res.setResponseMessage(statusLine.getReasonPhrase());
-
还查看该代码中的其他字段。例如,对于HTTP,方法和URL具有特殊的属性,这使得它们在Result中的格式很好
result.setHTTPMethod("POST"); result.setURL(POST_URL);