Add support to TCPSampler for sending content from a specified file.
The TCP Sampler is intended to be extended by the user. I doubt very much that this enhancement will be implemented in the near future unless someone supplies patches for the code, test cases and documentation.
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.
(In reply to comment #1) > The TCP Sampler is intended to be extended by the user. > I doubt very much that this enhancement will be implemented in the near future > unless someone supplies patches for the code, test cases and documentation. I can supply patches for the code, test cases and documentation ... but I need some training first in regards to how to contribute to Apache JMeter correctly. I will look for developer tutorial later. I also need to explain my design first to you so that it is deemed to be acceptable. Let me know ...
Another way to solve this problem is to supply a built in function for reading file, like shown below: ${__ReadFile(path, mode)} where mode is ASCII or BINARY.
Please also see bug 47565 [Function] FileToString https://issues.apache.org/bugzilla/show_bug.cgi?id=47565 The function FileToString is not documented. Wondering whether this function i for ASCII or BINARY file support ...
Closing according to sebb first response on which I agree.
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2123