Bug 45174 - TCPSampler support for sending files
Summary: TCPSampler support for sending files
Status: RESOLVED WONTFIX
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.3.1
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-09 23:20 UTC by Samuli Saarinen
Modified: 2012-05-28 20:31 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuli Saarinen 2008-06-09 23:20:27 UTC
Add support to TCPSampler for sending content from a specified file.
Comment 1 Sebb 2008-06-10 03:22:57 UTC
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.
Comment 2 Soumen Sarkar 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.
Comment 3 Soumen Sarkar 2009-11-20 13:53:10 UTC
(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 ...
Comment 4 Soumen Sarkar 2009-11-21 13:38:09 UTC
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.
Comment 5 Soumen Sarkar 2009-11-23 12:03:50 UTC
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 ...
Comment 6 Philippe Mouawad 2012-05-28 20:31:34 UTC
Closing according to sebb first response on which I agree.
Comment 7 The ASF infrastructure team 2022-09-24 20:37:41 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2123