我在Jmeter中有一个java Request,我编写了扩展AbstractJavaSamplerClient和Implemented覆盖方法的代码 我正在点击,可以在远程机器的日志中看到响应 但我无法在视图结果树中看到响应,并在jmeter中保存对文件的响应 下面是runtest代码片段,请告诉我如何在Jmeter中捕获java请求响应
public SampleResult runTest(JavaSamplerContext context) {
System.out.println("run Test method actual method is called here..");
XCardService xcardService = null;
String urlString = context.getParameter( "rubyURL" );
SampleResult result = new SampleResult();
boolean success = true;
result.sampleStart();
//try with Junit
String[] rubyURL = new String[1];
rubyURL[0] = urlString;
try {
System.out.println("RubyUrl::"+rubyURL);
xcardService = XCardFactory.getService(rubyURL, 165, appPassword, 5000);
} catch (AuthenticationFailureException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IncompatibleVersionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceInitFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XCardTimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DiagnosticContext dc = new ServerDiagnosticContext("Junit TestCase");
try {
System.out.println("xcardService::"+xcardService);
AccountInfo account = xcardService.getAccountInfo(dc, 1089765);
System.out.println("getAccount Info ::"+account.toString());
} catch (InvalidArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientNotAuthenticatedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XCardTimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XCardException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
result.sampleEnd();
result.setSuccessful(success);
System.out.println("Response Message:::"+result.getResponseMessage());
return result;
}
答案 0 :(得分:0)
AbstractJavaSamplerClient实现的一个很好的例子是org.apache.jmeter.protocol.java.test.SleepTest。
http://www.javadocexamples.com/java_source/org/apache/jmeter/protocol/java/test/SleepTest.java.html
作为一般规则,我会把result.sampleEnd();在最后一个街区。