Java Code Examples for org.apache.jmeter.samplers.SampleResult#setSamplerData()

The following examples show how to use org.apache.jmeter.samplers.SampleResult#setSamplerData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RosterAction.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    // sending message
    String recipient = sampler.getPropertyAsString(RECIPIENT);
    String body = sampler.getPropertyAsString(BODY);
    boolean wait_response = sampler.getPropertyAsBoolean(WAIT_RESPONSE);
    if (wait_response) {
        body += "\r\n" + System.currentTimeMillis() + "@" + NEED_RESPONSE_MARKER;
    }

    Message msg = new Message(recipient);
    msg.setType(Message.Type.fromString(sampler.getPropertyAsString(TYPE, Message.Type.normal.toString())));
    msg.addBody("", body);
    res.setSamplerData(msg.toXML().toString());
    sampler.getXMPPConnection().sendPacket(msg);
    res.setSamplerData(msg.toXML().toString()); // second time to reflect the changes made to packet by conn

    if (wait_response) {
        return waitResponse(res, recipient);
    }
    return res;
}
 
Example 3
Source File: SendPresence.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    Presence.Type typeVal = Presence.Type.valueOf(sampler.getPropertyAsString(TYPE, Presence.Type.available.toString()));
    Presence.Mode modeVal = Presence.Mode.valueOf(sampler.getPropertyAsString(MODE, Presence.Mode.available.toString()));

    Presence presence = new Presence(typeVal);
    presence.setMode(modeVal);

    String to = sampler.getPropertyAsString(RECIPIENT);
    if (!to.isEmpty()) {
        presence.setTo(to);
    }

    String text = sampler.getPropertyAsString(STATUS_TEXT);
    if (!text.isEmpty()) {
        presence.setStatus(text);
    }

    sampler.getXMPPConnection().sendPacket(presence);
    res.setSamplerData(presence.toXML().toString());
    return res;
}
 
Example 4
Source File: AbstractIPSampler.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult sample(Entry entry) {
    SampleResult res = new SampleResult();
    res.setSampleLabel(getName());
    res.setSamplerData(getRequestData());
    res.sampleStart();
    res.setDataType(SampleResult.TEXT);
    res.setSuccessful(true);
    res.setResponseCode(RC200);
    try {
        res.setResponseData(processIO(res));
    } catch (Exception ex) {
        if (!(ex instanceof SocketTimeoutException)) {
            log.error(getHostName(), ex);
        }
        res.sampleEnd();
        res.setSuccessful(false);
        res.setResponseCode(RC500);
        res.setResponseMessage(ex.toString());
        res.setResponseData((ex.toString() + CRLF + ExceptionUtils.getStackTrace(ex)).getBytes());
    }

    return res;
}
 
Example 5
Source File: JSONToXMLConverter.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult sample(Entry e) {
    SampleResult result = new SampleResult();

    result.setSampleLabel(getName());
    result.setSamplerData(this.getJsonInput());
    result.setDataType(SampleResult.TEXT);

    result.sampleStart();

    if (!getJsonInput().equalsIgnoreCase("")) {
        try {
            this.convertToXML();
            result.setResponseData(this.getXmlOutput().getBytes());
            result.setSuccessful(true);
        } catch (Exception e1) {
            result.setResponseData(e1.getMessage().getBytes());
            result.setSuccessful(false);
        }
    }

    result.sampleEnd();
    return result;
}
 
Example 6
Source File: DubboSample.java    From jmeter-plugins-for-apache-dubbo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
   public SampleResult sample(Entry entry) {
       SampleResult res = new SampleResult();
       res.setSampleLabel(getName());
       //构造请求数据
       res.setSamplerData(getSampleData());
       //调用dubbo
       res.setResponseData(JsonUtils.toJson(callDubbo(res)), StandardCharsets.UTF_8.name());
       //构造响应数据
       res.setDataType(SampleResult.TEXT);
       return res;
   }
 
Example 7
Source File: SendFileXEP0096.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: RawXML.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(final JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    final String xml = sampler.getPropertyAsString(XML);
    res.setSamplerData(xml);
    sampler.getXMPPConnection().sendPacket(new Packet() {
        @Override
        public CharSequence toXML() {
            return xml;
        }
    });
    return res;
}
 
Example 9
Source File: ServiceDiscovery.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: MUC.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    String room = sampler.getPropertyAsString(ROOM);
    String nick = sampler.getPropertyAsString(NICKNAME);
    res.setSamplerData("Join Room: " + room + "/" + nick);
    MultiUserChat muc = new MultiUserChat(sampler.getXMPPConnection(), room);
    muc.join(nick);
    return res;
}
 
Example 11
Source File: Login.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    XMPPConnection conn = sampler.getXMPPConnection();
    String loginStr = sampler.getPropertyAsString(LOGIN);
    String pwdStr = sampler.getPropertyAsString(PASSWORD);
    String resStr = sampler.getPropertyAsString(RESOURCE);
    res.setSamplerData("Username: " + loginStr + "\nPassword: " + pwdStr + "\nResource: " + resStr);
    AbstractXMPPConnection absConn = (AbstractXMPPConnection) conn;
    if (loginStr.isEmpty()) {
        absConn.loginAnonymously();
    } else {
        absConn.login(loginStr, pwdStr, resStr);
    }
    return res;
}
 
Example 12
Source File: CassandraSampler.java    From jmeter-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
    public SampleResult sample(Entry e) {
        log.debug("sampling CQL");

        SampleResult res = new SampleResult();
        res.setSampleLabel(getName());
        res.setSamplerData(toString());
        res.setDataType(SampleResult.TEXT);
        res.setContentType("text/plain"); // $NON-NLS-1$
        res.setDataEncoding(ENCODING);

        // Assume we will be successful
        res.setSuccessful(true);
        res.setResponseMessageOK();
        res.setResponseCodeOK();


        res.sampleStart();
        Session conn = null;

        try {
            if(JOrphanUtils.isBlank(getSessionName())) {
                throw new IllegalArgumentException("Variable Name must not be null in "+getName());
            }

            try {
                conn = CassandraConnection.getSession(getSessionName());
            } finally {
                res.latencyEnd(); // use latency to measure connection time
            }
            res.setResponseHeaders(conn.toString());
            res.setResponseData(execute(conn));
        }  catch (Exception ex) {
            res.setResponseMessage(ex.toString());
            res.setResponseCode("000");
            res.setResponseData(ex.getMessage().getBytes());
            res.setSuccessful(false);
        }
// Doesn't apply
//        finally {
//            close(conn);
//        }

        // TODO: process warnings? Set Code and Message to success?
        res.sampleEnd();
        return res;
    }
 
Example 13
Source File: KafkaProducerSampler.java    From kafkameter with Apache License 2.0 2 votes vote down vote up
/**
 * Start the sample request and set the {@code samplerData} to {@code data}.
 *
 * @param result
 *          the sample result to update
 * @param data
 *          the request to set as {@code samplerData}
 */
private void sampleResultStart(SampleResult result, String data) {
  result.setSamplerData(data);
  result.sampleStart();
}