From 968bbb5f5a236b7790c7365bc98ec76653b8c4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E5=85=89=EF=BC=9A=E5=9F=8E=E4=B8=AD=E5=9F=8E?= <806783409@qq.com> Date: Tue, 25 Jun 2019 22:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9swagger=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swagger/controller/MgDocumentController.java | 15 +++++++++------ .../swagger/controller/MgOpenDocController.java | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java index f29f809e..c49ce0b2 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java @@ -44,6 +44,9 @@ public class MgDocumentController { @Resource private MgStorageService storageService; + // 文档请求超时时间 + int docTimeout = 8000; + /** * 获取所有的文档地址 * @@ -114,7 +117,7 @@ public class MgDocumentController { String resourcesStr = HttpRequest.get(resourcesUrl) .form(this.getGlobalParamObjMap(globalParamList, "form")) .addHeaders(this.getGlobalParamMap(globalParamList, "header")) - .timeout(3000).execute().body(); + .timeout(docTimeout).execute().body(); resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); } catch (Exception e) { logger.error("获取文档失败:{},{}", resourcesUrl, e.getMessage()); @@ -144,7 +147,7 @@ public class MgDocumentController { String resourceStr = HttpRequest.get(location.getLocation()) .form(this.getGlobalParamObjMap(globalParamList, "form")) .addHeaders(this.getGlobalParamMap(globalParamList, "header")) - .timeout(3000).execute().body(); + .timeout(docTimeout).execute().body(); String resourcesUrl = location.getLocation(); int indexV2 = location.getLocation().indexOf("/v2"); if (indexV2 >= 0) { @@ -240,7 +243,7 @@ public class MgDocumentController { // List resourceList = null; // String resourcesUrl = resourcesInfoVo.getUrl(); // try { -// String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body(); +// String resourcesStr = HttpRequest.get(resourcesUrl).timeout(docTimeout).execute().body(); // resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); // } catch (Exception e) { // logger.error("获取文档失败:{},{}", resourcesUrl, e.getMessage()); @@ -253,7 +256,7 @@ public class MgDocumentController { // for (SwaggerResource resource : resourceList) { // String location = this.getLocationUrl(resourcesUrl, resource.getLocation(), resource.getName()); // try { -// String resourceStr = HttpRequest.get(location).timeout(3000).execute().body(); +// String resourceStr = HttpRequest.get(location).timeout(docTimeout).execute().body(); // Map jsonObject = JSON.parseObject(resourceStr, new TypeReference>(){}); // if (jsonObject == null || jsonObject.isEmpty()) { // continue; @@ -317,7 +320,7 @@ public class MgDocumentController { .form(this.getGlobalParamObjMap(globalParamList, "form")) .addHeaders(this.getGlobalParamMap(globalParamList, "header")) .header("Accept", "application/json, text/javascript, */*; q=0.01") - .timeout(3000).execute().body(); + .timeout(docTimeout).execute().body(); boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl, openVisit); if (!isLocation) { List resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); @@ -366,7 +369,7 @@ public class MgDocumentController { String resourcesStr = HttpRequest.get(resourcesUrl) .form(this.getGlobalParamObjMap(globalParamList, "form")) .addHeaders(this.getGlobalParamMap(globalParamList, "header")) - .timeout(3000).execute().body(); + .timeout(docTimeout).execute().body(); List resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); if (resourceList == null || resourceList.isEmpty()) { return DocResponseJson.warn("该地址未找到文档"); diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java index 5e3f9b85..d3b16b59 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgOpenDocController.java @@ -35,6 +35,9 @@ public class MgOpenDocController { @Resource private MgStorageService storageService; + // 文档请求超时时间 + int docTimeout = 8000; + @PostMapping(value = "/checkConfig") public DocResponseJson checkConfig() { return DocResponseJson.ok(); @@ -74,7 +77,7 @@ public class MgOpenDocController { String resourceStr = HttpRequest.get(location.getLocation()) .form(this.getGlobalParamObjMap(globalParamList, "form")) .addHeaders(this.getGlobalParamMap(globalParamList, "header")) - .timeout(3000).execute().body(); + .timeout(docTimeout).execute().body(); String resourcesUrl = location.getLocation(); int indexV2 = location.getLocation().indexOf("/v2"); if (indexV2 >= 0) {