diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/HarParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/HarParser.java index 8d3cdeea7b..56f28591d2 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/HarParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/HarParser.java @@ -43,8 +43,7 @@ public class HarParser extends HarAbstractParser { public ApiDefinitionImport parse(InputStream source, ApiTestImportRequest request) { Har har = null; try { - String sourceStr = getApiTestStr(source); - har = HarUtils.read(sourceStr); + har = HarUtils.read(source); } catch (Exception e) { MSException.throwException(e.getMessage()); LogUtil.error(e.getMessage(), e); diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/HarUtils.java b/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/HarUtils.java index b5e4cfa2f2..ecbcd8de4c 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/HarUtils.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/api/har/HarUtils.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.IOException; +import java.io.InputStream; /** * Utility class for working with HAR files. @@ -42,11 +43,11 @@ public class HarUtils { } - public static Har read(String harJson) throws JsonSyntaxException, IOException { - if (StringUtils.isEmpty(harJson)) { + public static Har read(InputStream source) throws JsonSyntaxException, IOException { + if (source == null) { 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; } } diff --git a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/HarScenarioParser.java b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/HarScenarioParser.java index 7e00aa46c0..c65ae5b520 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/HarScenarioParser.java +++ b/api-test/backend/src/main/java/io/metersphere/api/parse/scenario/HarScenarioParser.java @@ -27,8 +27,7 @@ public class HarScenarioParser extends HarScenarioAbstractParser public ScenarioImport parse(InputStream source, ApiTestImportRequest request) { Har har = null; try { - String sourceStr = getApiTestStr(source); - har = HarUtils.read(sourceStr); + har = HarUtils.read(source); } catch (Exception e) { MSException.throwException(e.getMessage()); LogUtil.error(e.getMessage(), e);