本文整理汇总了Java中org.apache.jmeter.samplers.SampleResult.setResponseData方法的典型用法代码示例。如果您正苦于以下问题:Java SampleResult.setResponseData方法的具体用法?Java SampleResult.setResponseData怎么用?Java SampleResult.setResponseData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jmeter.samplers.SampleResult
的用法示例。
在下文中一共展示了SampleResult.setResponseData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
Action action = Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString()));
Roster roster = sampler.getXMPPConnection().getRoster();
String entry = sampler.getPropertyAsString(ENTRY);
res.setSamplerData(action.toString() + ": " + entry);
if (action == Action.get_roster) {
res.setResponseData(rosterToString(roster).getBytes());
} else if (action == Action.add_item) {
roster.createEntry(entry, entry, new String[0]);
} else if (action == Action.delete_item) {
RosterEntry rosterEntry = roster.getEntry(entry);
if (rosterEntry != null) {
roster.removeEntry(rosterEntry);
}
}
return res;
}
示例2: waitResponse
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException {
long time = 0;
do {
Iterator<Message> packets = responseMessages.iterator();
Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic
while (packets.hasNext()) {
Packet packet = packets.next();
Message response = (Message) packet;
if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) {
packets.remove();
res.setResponseData(response.toXML().toString().getBytes());
if (response.getError() != null) {
res.setSuccessful(false);
res.setResponseCode("500");
res.setResponseMessage(response.getError().toString());
}
return res;
}
}
time += conn.getPacketReplyTimeout() / 10;
Thread.sleep(conn.getPacketReplyTimeout() / 10);
} while (time < conn.getPacketReplyTimeout());
throw new SmackException.NoResponseException();
}
示例3: sample
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
public SampleResult sample(Entry arg0) {
SampleResult res = new SampleResult();
res.setSampleLabel("函数助手小工具");
res.sampleStart();
// 输出GUI界面所输入的函数方法返回结果
JMeterProperty properties = this.getProperty(FUNCTION);
System.out.println(properties);
//
if (properties != null) {
res.setResponseData("Function结果是:" + properties.getStringValue(), null);
res.setDataType(SampleResult.TEXT);
}
res.sampleEnd();
res.setSuccessful(true);
return res;
}
示例4: runTest
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
/**
* For each sample request this method is invoked and will return success/failure result
*
* @param context
* @return
*/
@Override
public SampleResult runTest(JavaSamplerContext context) {
SampleResult sampleResult = new SampleResult();
sampleResult.sampleStart();
Object message = JMeterContextService.getContext().getVariables().getObject(placeHolder);
try {
ProducerRecord<String, Object> producerRecord = new ProducerRecord<String, Object>(topic, message);
producer.send(producerRecord);
sampleResult.setResponseData(message.toString(), StandardCharsets.UTF_8.name());
sampleResult.setSuccessful(true);
sampleResult.sampleEnd();
} catch (Exception e) {
log.error("Failed to send message", e);
sampleResult.setResponseData(e.getMessage(), StandardCharsets.UTF_8.name());
sampleResult.setSuccessful(false);
sampleResult.sampleEnd();
}
return sampleResult;
}
示例5: setJsonResponse
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public void setJsonResponse(SampleResult sample, MartiniResult result) {
checkNotNull(sample, "null SampleResult");
checkNotNull(result, "null MartiniResult");
try (StringWriter writer = new StringWriter();
JsonWriter jsonWriter = gson.newJsonWriter(writer)) {
gson.toJson(result, MartiniResult.class, jsonWriter);
jsonWriter.flush();
String data = writer.toString();
sample.setResponseData(data, null); // Uses platform-dependent encoding.
}
catch (Exception e) {
logger.warn("unable to set JSON on SampleResult", e);
}
}
示例6: fillFailedResult
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private SampleResult fillFailedResult(boolean sampleByTime, SampleResult result, String message) {
result.setResponseCode("500");
result.setSuccessful(false);
result.setResponseMessage(message);
result.setResponseData(message.getBytes());
result.setEndTime(result.getStartTime());
if(sampleByTime) {
try {
TimeUnit.MILLISECONDS.sleep(Long.parseLong(getSampleElapsedTime()));
} catch (InterruptedException e) {
logger.info("Received exception when waiting for notification signal: " + e.getMessage());
}
}
return result;
}
示例7: getMasterList
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private DataRequest getMasterList(SampleResult masterResult, Parser parser) throws IOException {
masterResult.sampleStart();
DataRequest respond = parser.getBaseUrl(new URL(getURLData()), masterResult, true);
masterResult.sampleEnd();
masterResult.setRequestHeaders(respond.getRequestHeaders() + "\n\n" + getCookieHeader(getURLData()) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
masterResult.setSuccessful(respond.isSuccess());
masterResult.setResponseMessage(respond.getResponseMessage());
masterResult.setSampleLabel(this.getName());
masterResult.setResponseHeaders(respond.getHeadersAsString());
masterResult.setResponseData(respond.getResponse().getBytes());
masterResult.setResponseCode(respond.getResponseCode());
masterResult.setContentType(respond.getContentType());
masterResult.setBytes(masterResult.getBytesAsLong() + (long) masterResult.getRequestHeaders().length());
int headerBytes = masterResult.getResponseHeaders().length() // condensed
// length
// (without
// \r)
+ respond.getHeaders().size() // Add \r for each header
+ 1 // Add \r for initial header
+ 2; // final \r\n before data
masterResult.setHeadersSize((int) headerBytes);
masterResult.setSentBytes(respond.getSentBytes());
masterResult.setDataEncoding(respond.getContentEncoding());
return respond;
}
示例8: getPlayList
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
private DataRequest getPlayList(SampleResult playListResult, Parser parser) throws IOException {
String lastPath = "";
playListResult.sampleStart();
DataRequest subRespond = parser.getBaseUrl(new URL(playlist), playListResult, true);
playListResult.sampleEnd();
String[] urlArray = playlist.split("/");
lastPath = urlArray[urlArray.length - 1];
playListResult.setRequestHeaders(subRespond.getRequestHeaders() + "\n\n" + getCookieHeader(playlist) + "\n\n"
+ getRequestHeader(this.getHeaderManager()));
playListResult.setSuccessful(subRespond.isSuccess());
playListResult.setResponseMessage(subRespond.getResponseMessage());
playListResult.setSampleLabel(lastPath);
playListResult.setResponseHeaders(subRespond.getHeadersAsString());
playListResult.setResponseData(subRespond.getResponse().getBytes());
playListResult.setResponseCode(subRespond.getResponseCode());
playListResult.setContentType(subRespond.getContentType());
playListResult.setBytes(playListResult.getBytesAsLong() + (long) playListResult.getRequestHeaders().length());
int headerBytes = playListResult.getResponseHeaders().length() // condensed
// length
// (without
// \r)
+ subRespond.getHeaders().size() // Add \r for each header
+ 1 // Add \r for initial header
+ 2; // final \r\n before data
playListResult.setHeadersSize((int) headerBytes);
playListResult.setSentBytes(subRespond.getSentBytes());
playListResult.setDataEncoding(subRespond.getContentEncoding());
return subRespond;
}
示例9: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
long counter = 0;
for (Packet packet : incomingPackets) {
incomingPackets.remove(packet);
SampleResult subRes = new SampleResult();
subRes.setSuccessful(true);
subRes.setResponseCode("200");
subRes.setResponseMessage("OK");
subRes.setSampleLabel(packet.getClass().getSimpleName().isEmpty() ? packet.getClass().getName() : packet.getClass().getSimpleName());
subRes.setResponseData(packet.toXML().toString().getBytes());
if ((packet instanceof Presence) && (((Presence) packet).getType() == Presence.Type.error)) {
subRes.setSuccessful(false);
subRes.setResponseCode("500");
subRes.setResponseMessage(packet.getError().toString());
} else if ((packet instanceof Message) && (((Message) packet).getType() == Message.Type.error)) {
subRes.setSuccessful(false);
subRes.setResponseCode("500");
subRes.setResponseMessage(packet.getError().toString());
} else if ((packet instanceof IQ) && (((IQ) packet).getType() == IQ.Type.error)) {
subRes.setSuccessful(false);
subRes.setResponseCode("500");
subRes.setResponseMessage(packet.getError().toString());
}
res.addSubResult(subRes);
counter++;
}
res.setResponseData(("Received packets: " + counter).getBytes());
return counter > 0 ? res : null;
}
示例10: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
String recipient = sampler.getPropertyAsString(FILE_RECIPIENT);
String filePath = sampler.getPropertyAsString(FILE_PATH);
res.setSamplerData("Recipient: " + recipient + "\r\nFile: " + filePath + "\r\n");
OutgoingFileTransfer transfer = mgr.createOutgoingFileTransfer(recipient);
transfer.sendFile(new File(filePath), filePath);
waitForTransfer(transfer, sampler.getXMPPConnection().getPacketReplyTimeout());
res.setResponseData(("Bytes sent: " + transfer.getBytesSent()).getBytes());
return res;
}
示例11: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
BookmarkManager manager = BookmarkManager.getBookmarkManager(sampler.getXMPPConnection());
Collection<BookmarkedConference> confs = manager.getBookmarkedConferences();
StringBuilder text = new StringBuilder();
for (BookmarkedConference room : confs) {
text.append(room.getJid());
text.append("\r\n");
}
res.setResponseData(text.toString().getBytes());
return res;
}
示例12: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
String entID = sampler.getPropertyAsString(ENTITY_ID);
res.setSamplerData("Entity ID: " + entID);
ServiceDiscoveryManager discoMgr = ServiceDiscoveryManager.getInstanceFor(sampler.getXMPPConnection());
IQ info;
if (Type.valueOf(sampler.getPropertyAsString(TYPE)) == Type.info) {
info = discoMgr.discoverInfo(entID);
} else {
info = discoMgr.discoverItems(entID);
}
res.setResponseData(info.toXML().toString().getBytes());
return res;
}
示例13: perform
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection();
conn.connect();
res.setResponseData(sampler.getXMPPConnection().getConnectionID().getBytes());
return res;
}
示例14: process
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
@Override
public void process() {
SampleResult prev = getThreadContext().getPreviousResult();
if (prev == null) return;
String xml = prev.getResponseDataAsString();
if (xml == null) return;
try {
log.debug("Parsing xml response");
Document doc = stringToDocument(xml);
log.debug("Processing WSS header");
doc = this.process(doc); // Delegate in abstract method
prev.setResponseData(documentToString(doc), prev.getDataEncodingWithDefault());
}
catch (Exception e) {
log.error("Processing failed! ", e);
if (e instanceof WSSecurityException && JMeterUtils.getPropDefault(FAIL_ON_WSS_EXCEPTION, true)) {
AssertionResult assertionResult = new AssertionResult("WSSecurityException").setResultForFailure(e.getMessage());
assertionResult.setError(true);
assertionResult.setFailure(true);
prev.addAssertionResult(assertionResult);
prev.setSuccessful(false);
}
}
}
示例15: runTest
import org.apache.jmeter.samplers.SampleResult; //导入方法依赖的package包/类
/**
* 开始测试,从arg0参数可以获得参数值;
*/
public SampleResult runTest(JavaSamplerContext arg0) {
name = arg0.getParameter("name");
SampleResult sr = new SampleResult();
sr.setSampleLabel("Java请求--sayHelloToPerson");
try {
// jmeter 开始统计响应时间标记
sr.sampleStart();
Hello test = new Hello();
// 通过下面的操作就可以将被测方法的响应输出到Jmeter的察看结果树中的响应数据里面了。
resultData = test.sayHelloToPerson(name);
if (resultData != null && resultData.length() > 0) {
sr.setResponseData("结果是:" + resultData, null);
sr.setDataType(SampleResult.TEXT);
}
sr.setSuccessful(true);
} catch (Throwable e) {
sr.setSuccessful(false);
e.printStackTrace();
} finally {
// jmeter 结束统计响应时间标记
sr.sampleEnd();
}
return sr;
}