DO NOT REPLY [Bug 45174] TCPSampler support for sending files

[email protected]
Newsgroups gmane.comp.jakarta.jmeter.devel
Message-ID <[email protected]>
https://issues.apache.org/bugzilla/show_bug.cgi?id=45174

--- Comment #2 from Soumen Sarkar <[email protected]> 2009-11-20 13:36:49 UTC ---
I extended JMeter TCPClient to implement "read from file" feature in test plan. 

The extension works as follows for end users:

In the TCP Sampler UI, in the field "Text to send" a variable like notation is
allowed. This notation looks like $FILE{path}. For example, in my test plan I
am using $FILE{C:\work\projects\JMeter\test_binary_file_send.msg}. In the field
text and $FILE{path} can be mixed. All $FILE{path} is substituted with file
content and sent to system under test (SUT).

From java coding standpoint, the extension is developed as follows:

1. Implement org.apache.jmeter.protocol.tcp.sampler.TCPClient with your own
class

http://svn.apache.org/repos/asf/jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPClient.java

as shown below:

package com.acme.jmeter.protocol.tcp.sampler;

import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.log.Logger;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.protocol.tcp.sampler.TCPClient;

public class TCPClientImplWithFileReader implements TCPClient 
{
...
...
}

2. Override the following method:

 /**
     *
     * @param os -
     *            OutputStream for socket
     * @param is -
     *            InputStream to be written to Socket
     */
    void write(OutputStream os, InputStream is);

    /**
     *
     * @param os -
     *            OutputStream for socket
     * @param s -
     *            String to write
     */
    void write(OutputStream os, String s);

What you need to do is parse the content in 2nd parameter to look for
$FILE{path} pattern and substitute with file content. Then write the whole
thing to OutputStream.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.