diff --git a/backend/framework/sdk/src/main/resources/i18n/commons.properties b/backend/framework/sdk/src/main/resources/i18n/commons.properties index 5bcadfd747..533c38a467 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons.properties @@ -541,3 +541,5 @@ current_user_can_not_operation_api_key=当前用户无操作该ApiKey的权限 #全局请求头 global_request_header=全局请求头 + +url_format_error=请检查Swagger URL是否输入正确! diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index 60add6a40c..e1cff4ca04 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -578,4 +578,6 @@ api_key_not_exist=API key does not exist current_user_can_not_operation_api_key=The current user cannot operate the API key #全局请求头 -global_request_header=Global request header \ No newline at end of file +global_request_header=Global request header + +url_format_error=Please check if the Swagger URL is entered correctly! diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index 7c9e7eb9ba..e19d30d4f9 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -575,4 +575,6 @@ api_key_not_exist=ApiKey不存在 current_user_can_not_operation_api_key=当前用户无操作该ApiKey的权限 #全局请求头 -global_request_header=全局请求头 \ No newline at end of file +global_request_header=全局请求头 + +url_format_error=请检查Swagger URL是否输入正确! \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 2852fc1006..6e032ada38 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -575,4 +575,6 @@ api_key_not_exist=ApiKey不存在 current_user_can_not_operation_api_key=當前用戶無法操作ApiKey #全局请求头 -global_request_header=全局請求頭 \ No newline at end of file +global_request_header=全局請求頭 + +url_format_error=请检查Swagger URL是否输入正确! \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java index ea256e3e3f..191fda1d33 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java @@ -57,6 +57,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import java.net.HttpURLConnection; +import java.net.URI; import java.util.*; import java.util.stream.Collectors; @@ -112,6 +114,9 @@ public class ApiDefinitionImportUtilService { if (StringUtils.equals(request.getType(), "SCHEDULE")) { request.setProtocol(ModuleConstants.NODE_PROTOCOL_HTTP); } + if (StringUtils.equals(request.getPlatform(), ApiImportPlatform.Swagger3.name()) && StringUtils.isNotBlank(request.getSwaggerUrl())) { + testUrlTimeout(request.getSwaggerUrl(), 30000); + } try { apiImport = (ApiDefinitionImport) Objects.requireNonNull(runService).parse(file == null ? null : file.getInputStream(), request); //TODO 处理mock数据 @@ -128,6 +133,23 @@ public class ApiDefinitionImportUtilService { } } + public static void testUrlTimeout(String address, int timeOutMillSeconds) { + HttpURLConnection connection = null; + try { + URI uriObj = new URI(address); + connection = (HttpURLConnection) uriObj.toURL().openConnection(); + connection.setUseCaches(false); + connection.setConnectTimeout(timeOutMillSeconds); // 设置超时时间 + connection.connect(); // 建立连接 + } catch (Exception e) { + LogUtils.error(e); + throw new MSException(Translator.get("url_format_error")); + } finally { + if (connection != null) { + connection.disconnect(); // 关闭连接 + } + } + } public void checkFileSuffixName(ImportRequest request, String suffixName) { if (FILE_JMX.equalsIgnoreCase(suffixName)) {