From b2c1d1fa794240a2c156bfac9649396bc21229ac Mon Sep 17 00:00:00 2001
From: song-tianyang <tianyang.song@fit2cloud.com>
Date: Wed, 19 Jan 2022 17:16:49 +0800
Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?=
 =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E8=87=AA?=
 =?UTF-8?q?=E5=8A=A8=E5=8C=96=E8=B0=83=E8=AF=95=E5=BC=95=E7=94=A8=E7=9A=84?=
 =?UTF-8?q?TCP=E6=A1=88=E4=BE=8B=E6=89=A7=E8=A1=8C=E5=A4=B1=E8=B4=A5?=
 =?UTF-8?q?=E7=9A=84=E7=BC=BA=E9=99=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

--bug=1009775 --user=宋天阳 【接口测试】场景里导入tcp接口执行失败,接口列表执行成功 {#_orginal_url#}
---
 .../api/service/ApiTestCaseService.java          |  4 +++-
 .../api/service/TcpApiParamService.java          | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java
index b3ef8569d5..3d4a636615 100644
--- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java
+++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java
@@ -100,6 +100,8 @@ public class ApiTestCaseService {
     private ApiTestCaseFollowMapper apiTestCaseFollowMapper;
     @Resource
     private ExtProjectVersionMapper extProjectVersionMapper;
+    @Resource
+    private TcpApiParamService tcpApiParamService;
 
     private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
 
@@ -350,7 +352,7 @@ public class ApiTestCaseService {
 
     private ApiTestCase updateTest(SaveApiTestCaseRequest request) {
         checkNameExist(request);
-
+        request.setRequest(tcpApiParamService.parseMsTestElement(request.getRequest()));
         if (StringUtils.isNotEmpty(request.getEsbDataStruct())) {
             request = esbApiParamService.handleEsbRequest(request);
         }
diff --git a/backend/src/main/java/io/metersphere/api/service/TcpApiParamService.java b/backend/src/main/java/io/metersphere/api/service/TcpApiParamService.java
index 70f17a0ab8..299215dd04 100644
--- a/backend/src/main/java/io/metersphere/api/service/TcpApiParamService.java
+++ b/backend/src/main/java/io/metersphere/api/service/TcpApiParamService.java
@@ -30,6 +30,22 @@ public class TcpApiParamService {
         return request;
     }
 
+    public MsTestElement parseMsTestElement(MsTestElement testElement) {
+        if (testElement == null) {
+            return null;
+        }
+        if (testElement instanceof MsTCPSampler) {
+            MsTCPSampler tcpSampler = this.handleTcpRequest(testElement);
+            if (tcpSampler != null) {
+                return tcpSampler;
+            } else {
+                return testElement;
+            }
+        } else {
+            return testElement;
+        }
+    }
+
     public MsTCPSampler handleTcpRequest(MsTestElement testElement) {
         MsTCPSampler tcpSampler = null;
         try {