fix(接口测试): 解决har文件导入报错问题

--user=郭雨琦
This commit is contained in:
guoyuqi 2022-12-06 14:41:47 +08:00 committed by 刘瑞斌
parent 6fc4f75e10
commit 8ae1d16e98
3 changed files with 6 additions and 7 deletions

View File

@ -43,8 +43,7 @@ public class HarParser extends HarAbstractParser {
public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) { public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) {
Har har = null; Har har = null;
try { try {
String sourceStr = getApiTestStr(source); har = HarUtils.read(source);
har = HarUtils.read(sourceStr);
} catch (Exception e) { } catch (Exception e) {
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);

View File

@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* Utility class for working with HAR files. * Utility class for working with HAR files.
@ -42,11 +43,11 @@ public class HarUtils {
} }
public static Har read(String harJson) throws JsonSyntaxException, IOException { public static Har read(InputStream source) throws JsonSyntaxException, IOException {
if (StringUtils.isEmpty(harJson)) { if (source == null) {
throw new IllegalArgumentException("HAR Json cannot be null/empty"); throw new IllegalArgumentException("HAR Json cannot be null/empty");
} }
Har har = JSON.parseObject(harJson, Har.class); Har har = JSON.parseObject(source, Har.class);
return har; return har;
} }
} }

View File

@ -27,8 +27,7 @@ public class HarScenarioParser extends HarScenarioAbstractParser<ScenarioImport>
public ScenarioImport parse(InputStream source, ApiTestImportRequest request) { public ScenarioImport parse(InputStream source, ApiTestImportRequest request) {
Har har = null; Har har = null;
try { try {
String sourceStr = getApiTestStr(source); har = HarUtils.read(source);
har = HarUtils.read(sourceStr);
} catch (Exception e) { } catch (Exception e) {
MSException.throwException(e.getMessage()); MSException.throwException(e.getMessage());
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);