Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
fix(接口定义): 修复tcp执行报错500的缺陷 (#37)
Browse files Browse the repository at this point in the history
--bug=1017926 --user=王孝刚 【接口测试】github#18415,TCP协议的JMX脚本,导入MS系统执行报500
https://www.tapd.cn/55049933/s/1261057

Co-authored-by: wxg0103 <727495428@qq.com>
  • Loading branch information
metersphere-bot and wxg0103 committed Oct 26, 2022
1 parent 1cd8a03 commit da66b3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* the end of the stream is reached.
* The EOL byte is defined by the property "tcp.eolByte".
*/
public class MsTCPClientImpl extends TCPClientImpl {
public abstract class MsTCPClientImpl extends TCPSampler {
private static final Logger log = LoggerFactory.getLogger(MsTCPClientImpl.class);

private static final int EOL_INT = JMeterUtils.getPropDefault("tcp.eolByte", 1000); // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String getCharset() {
private static final ThreadLocal<Map<String, Object>> tp =
ThreadLocal.withInitial(HashMap::new);

private transient MsTCPClientImpl protocolHandler;
private transient TCPClient protocolHandler;

private transient boolean firstSample; // Are we processing the first sample?

Expand Down Expand Up @@ -319,14 +319,14 @@ private Class<?> getClass(String className) {

}

private MsTCPClientImpl getProtocol() {
MsTCPClientImpl tcpClient = null;
private TCPClient getProtocol() {
TCPClient tcpClient = null;
Class<?> javaClass = getClass(getClassname());
if (javaClass == null){
return null;
}
try {
tcpClient = (MsTCPClientImpl) javaClass.getDeclaredConstructor().newInstance();
tcpClient = (TCPClient) javaClass.getDeclaredConstructor().newInstance();
if (getPropertyAsString(EOL_BYTE, "").length()>0){
tcpClient.setEolByte(getEolByte());
log.info("Using eolByte={}", getEolByte());
Expand Down Expand Up @@ -388,7 +388,11 @@ public SampleResult sample(Entry e)// Entry tends to be ignored ...
// TODO handle filenames
res.setSamplerData(req);
//替换原来的编码
protocolHandler.write(os, req , getCharset());
if (protocolHandler instanceof MsTCPClientImpl) {
((MsTCPClientImpl) protocolHandler).write(os, req , getCharset());
} else {
protocolHandler.write(os, req);
}
String in = protocolHandler.read(is, res);
isSuccessful = setupSampleResult(res, in, null, protocolHandler);
}
Expand Down

0 comments on commit da66b3d

Please sign in to comment.