fix: 修复没有参数时发送tcp请求系统报错的问题

修复没有参数时发送tcp请求系统报错的问题
This commit is contained in:
song-tianyang 2021-06-08 17:24:11 +08:00 committed by 刘瑞斌
parent 024f105884
commit e4c3e4cf49
1 changed files with 11 additions and 9 deletions

View File

@ -235,18 +235,20 @@ public class MsTCPSampler extends MsTestElement {
this.parameters.forEach(item -> {
names.add(new StringProperty(new Integer(new Random().nextInt(1000000)).toString(), item.getName()));
String value = item.getValue();
value = this.formatMockValue(value);
if(StringUtils.isNotEmpty(this.getConnectEncoding())){
if(StringUtils.equalsIgnoreCase("utf-8",this.getConnectEncoding())){
value = new String(value.getBytes(),StandardCharsets.UTF_8);
}else if(StringUtils.equalsIgnoreCase("gbk",this.getConnectEncoding())){
try {
value = new String(value.getBytes(),"GBK");
}catch (Exception e){
if(StringUtils.isNotEmpty(value)){
value = this.formatMockValue(value);
if(StringUtils.isNotEmpty(this.getConnectEncoding())){
if(StringUtils.equalsIgnoreCase("utf-8",this.getConnectEncoding())){
value = new String(value.getBytes(),StandardCharsets.UTF_8);
}else if(StringUtils.equalsIgnoreCase("gbk",this.getConnectEncoding())){
try {
value = new String(value.getBytes(),"GBK");
}catch (Exception e){
}
}
}
threadValues.add(new StringProperty(new Integer(new Random().nextInt(1000000)).toString(), value));
}
threadValues.add(new StringProperty(new Integer(new Random().nextInt(1000000)).toString(), value));
});
}
userParameters.setNames(new CollectionProperty(UserParameters.NAMES, names));