當前位置: 首頁>>代碼示例>>Java>>正文


Java SampleResult.setResponseCode方法代碼示例

本文整理匯總了Java中org.apache.jmeter.samplers.SampleResult.setResponseCode方法的典型用法代碼示例。如果您正苦於以下問題:Java SampleResult.setResponseCode方法的具體用法?Java SampleResult.setResponseCode怎麽用?Java SampleResult.setResponseCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.jmeter.samplers.SampleResult的用法示例。


在下文中一共展示了SampleResult.setResponseCode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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();
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:25,代碼來源:SendMessage.java

示例2: 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;
}
 
開發者ID:emqtt,項目名稱:mqtt-jmeter,代碼行數:17,代碼來源:SubSampler.java

示例3: 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;

	}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:33,代碼來源:HlsSampler.java

示例4: 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;
	}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:36,代碼來源:HlsSampler.java

示例5: 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;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:33,代碼來源:NoOp.java

示例6: fillOKResult

import org.apache.jmeter.samplers.SampleResult; //導入方法依賴的package包/類
private SampleResult fillOKResult(SampleResult result, int size, String message, String contents) {
	result.setResponseCode("200");
	result.setSuccessful(true);
	result.setResponseMessage(message);
	result.setBodySize(size);
	result.setBytes(size);
	result.setResponseData(contents.getBytes());
	result.sampleEnd();
	return result;
}
 
開發者ID:emqtt,項目名稱:mqtt-jmeter,代碼行數:11,代碼來源:SubSampler.java

示例7: getFragments

import org.apache.jmeter.samplers.SampleResult; //導入方法依賴的package包/類
public List<SampleResult> getFragments(Parser parser, List<DataFragment> uris, String url) {
	List<SampleResult> res = new ArrayList<>();

	if (!uris.isEmpty()) {
		SampleResult result = new SampleResult();
		String uriString = uris.get(0).getTsUri();
		if ((url != null) && (!uriString.startsWith("http"))) {
			uriString = url + uriString;
		}

		result.sampleStart();

		try {

			DataRequest respond = parser.getBaseUrl(new URL(uriString), result, false);

			result.sampleEnd();

			String[] urlArray = uriString.split("/");
			String lastPath = urlArray[urlArray.length - 1];

			result.setRequestHeaders(respond.getRequestHeaders() + "\n\n" + getCookieHeader(uriString) + "\n\n"
					+ getRequestHeader(this.getHeaderManager()));
			result.setSuccessful(respond.isSuccess());
			result.setResponseMessage(respond.getResponseMessage());
			result.setSampleLabel(lastPath);
			result.setResponseHeaders("URL: " + uriString + "\n" + respond.getHeadersAsString());
			result.setResponseCode(respond.getResponseCode());
			result.setContentType(respond.getContentType());
			result.setBytes(result.getBytesAsLong() + (long) result.getRequestHeaders().length());
			int headerBytes = result.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

			result.setHeadersSize((int) headerBytes);
			result.setSentBytes(respond.getSentBytes());
			result.setDataEncoding(respond.getContentEncoding());

			res.add(result);

		} catch (IOException e1) {
			e1.printStackTrace();
			result.sampleEnd();
			result.setSuccessful(false);
			result.setResponseMessage("Exception: " + e1);
			res.add(result);
		}

		uris.remove(0);
		List<SampleResult> aux = getFragments(parser, uris, url);
		for (SampleResult s : aux) {
			if(!res.contains(s))
				res.add(s);
		}
	}
	return res;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:62,代碼來源:HlsSampler.java

示例8: sample

import org.apache.jmeter.samplers.SampleResult; //導入方法依賴的package包/類
@Override
public SampleResult sample(Entry entry) {
    SampleResult res = new SampleResult();
    res.setSampleLabel(getName());
    res.setDataType(SampleResult.TEXT);
    res.setSuccessful(true);
    res.setResponseCode("200");
    res.setResponseMessage("OK");

    res.sampleStart();
    try {
        if (connConfig == null) {
            throw new RuntimeException("Cannot sample XMPP without XMPP Connection component");
        }

        XMPPConnection conn = getXMPPConnection();

        if (conn == null) {
            throw new RuntimeException("No XMPP Connection available");
        }

        String headers = "Connection ID: " + conn.getConnectionID() + "\r\n";

        String action = getAction();
        if (!conn.isConnected() && !action.equals(Connect.class.getCanonicalName())) {
            log.error("Please call Connect before calling other actions");
            throw new SmackException.NotConnectedException();
        }

        headers += "User: " + conn.getUser() + "\r\n";

        res.setRequestHeaders(headers);

        AbstractXMPPAction actObject = connConfig.getActions().get(action);
        if (actObject.perform(this, res) == null) {
            return null;
        }
    } catch (Exception e) {
        log.error("Error in XMPP Sampler: ", e);
        res.setSuccessful(false);
        res.setResponseCode("500");
        res.setResponseMessage((e.getMessage() == null || e.getMessage().isEmpty()) ? e.toString() : e.getMessage());
        res.setResponseData(ExceptionUtils.getStackTrace(e).getBytes());
    }

    res.sampleEnd();
    return res;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:49,代碼來源:JMeterXMPPSampler.java

示例9: sample

import org.apache.jmeter.samplers.SampleResult; //導入方法依賴的package包/類
@Override
public SampleResult sample(Entry entry) {
	SampleResult result = new SampleResult();
	result.setSampleLabel(getName());
	try {
		if (!DEFAULT_PROTOCOL.equals(getProtocol())) {
			mqtt.setSslContext(Util.getContext(this));
		}
		
		mqtt.setHost(getProtocol().toLowerCase() + "://" + getServer() + ":" + getPort());
		mqtt.setVersion(getMqttVersion());
		mqtt.setKeepAlive((short) Integer.parseInt(getConnKeepAlive()));
		
		String clientId = null;
		if(isClientIdSuffix()) {
			clientId = Util.generateClientId(getConnPrefix());
		} else {
			clientId = getConnPrefix();
		}
		
		mqtt.setClientId(clientId);
		mqtt.setConnectAttemptsMax(Integer.parseInt(getConnAttamptMax()));
		mqtt.setReconnectAttemptsMax(Integer.parseInt(getConnReconnAttamptMax()));

		if (!"".equals(getUserNameAuth().trim())) {
			mqtt.setUserName(getUserNameAuth());
		}
		if (!"".equals(getPasswordAuth().trim())) {
			mqtt.setPassword(getPasswordAuth());
		}

		result.sampleStart();
		connection = mqtt.futureConnection();
		Future<Void> f1 = connection.connect();
		f1.await(Integer.parseInt(getConnTimeout()), TimeUnit.SECONDS);

		Topic[] topics = { new Topic("topic_" + clientId, QoS.AT_LEAST_ONCE) };
		connection.subscribe(topics);

		result.sampleEnd();
		result.setSuccessful(true);
		result.setResponseData("Successful.".getBytes());
		result.setResponseMessage(MessageFormat.format("Connection {0} connected successfully.", connection));
		result.setResponseCodeOK();
	} catch (Exception e) {
		logger.log(Priority.ERROR, e.getMessage(), e);
		result.sampleEnd();
		result.setSuccessful(false);
		result.setResponseMessage(MessageFormat.format("Connection {0} connected failed.", connection));
		result.setResponseData("Failed.".getBytes());
		result.setResponseCode("500");
	}
	return result;
}
 
開發者ID:emqtt,項目名稱:mqtt-jmeter,代碼行數:55,代碼來源:ConnectionSampler.java


注:本文中的org.apache.jmeter.samplers.SampleResult.setResponseCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。