Example usage for org.apache.commons.net.pop3 POP3Client sendCommand

List of usage examples for org.apache.commons.net.pop3 POP3Client sendCommand

Introduction

In this page you can find the example usage for org.apache.commons.net.pop3 POP3Client sendCommand.

Prototype

public int sendCommand(String command, String args) throws IOException 

Source Link

Document

Sends a command an arguments to the server and returns the reply code.

Usage

From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java

private SampleResult sampleCommand(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    POP3Client client = null;
    int responseCode;
    if (soclient instanceof POP3Client)
        client = (POP3Client) soclient;/*from  www .  ja  va 2s.  c om*/

    String request = "COMMAND\n";
    request += "Client : " + getClient() + "\n";
    request += "Command : " + getCommand() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                String command, args = null;
                int index = getCommand().indexOf(' ');
                if (index != -1) {
                    command = getCommand().substring(0, index);
                    if (index + 1 < getCommand().length())
                        args = getCommand().substring(index + 1, getCommand().length() - 1);
                } else
                    command = getCommand();

                responseCode = (args != null ? client.sendCommand(command, args) : client.sendCommand(command));
                if (getAdditionalReply())
                    client.getAdditionalReply();
                setSuccessfulByResponseCode(sr, responseCode);
                setResponse(sr, client.getReplyStrings());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + client + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}