修改swagger请求文档超时时间

This commit is contained in:
暮光:城中城
2019-06-25 22:14:21 +08:00
parent 65dd754580
commit 968bbb5f5a
2 changed files with 13 additions and 7 deletions

View File

@@ -44,6 +44,9 @@ public class MgDocumentController {
@Resource @Resource
private MgStorageService storageService; private MgStorageService storageService;
// 文档请求超时时间
int docTimeout = 8000;
/** /**
* 获取所有的文档地址 * 获取所有的文档地址
* *
@@ -114,7 +117,7 @@ public class MgDocumentController {
String resourcesStr = HttpRequest.get(resourcesUrl) String resourcesStr = HttpRequest.get(resourcesUrl)
.form(this.getGlobalParamObjMap(globalParamList, "form")) .form(this.getGlobalParamObjMap(globalParamList, "form"))
.addHeaders(this.getGlobalParamMap(globalParamList, "header")) .addHeaders(this.getGlobalParamMap(globalParamList, "header"))
.timeout(3000).execute().body(); .timeout(docTimeout).execute().body();
resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
} catch (Exception e) { } catch (Exception e) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage()); logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
@@ -144,7 +147,7 @@ public class MgDocumentController {
String resourceStr = HttpRequest.get(location.getLocation()) String resourceStr = HttpRequest.get(location.getLocation())
.form(this.getGlobalParamObjMap(globalParamList, "form")) .form(this.getGlobalParamObjMap(globalParamList, "form"))
.addHeaders(this.getGlobalParamMap(globalParamList, "header")) .addHeaders(this.getGlobalParamMap(globalParamList, "header"))
.timeout(3000).execute().body(); .timeout(docTimeout).execute().body();
String resourcesUrl = location.getLocation(); String resourcesUrl = location.getLocation();
int indexV2 = location.getLocation().indexOf("/v2"); int indexV2 = location.getLocation().indexOf("/v2");
if (indexV2 >= 0) { if (indexV2 >= 0) {
@@ -240,7 +243,7 @@ public class MgDocumentController {
// List<SwaggerResource> resourceList = null; // List<SwaggerResource> resourceList = null;
// String resourcesUrl = resourcesInfoVo.getUrl(); // String resourcesUrl = resourcesInfoVo.getUrl();
// try { // 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); // resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
// } catch (Exception e) { // } catch (Exception e) {
// logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage()); // logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
@@ -253,7 +256,7 @@ public class MgDocumentController {
// for (SwaggerResource resource : resourceList) { // for (SwaggerResource resource : resourceList) {
// String location = this.getLocationUrl(resourcesUrl, resource.getLocation(), resource.getName()); // String location = this.getLocationUrl(resourcesUrl, resource.getLocation(), resource.getName());
// try { // try {
// String resourceStr = HttpRequest.get(location).timeout(3000).execute().body(); // String resourceStr = HttpRequest.get(location).timeout(docTimeout).execute().body();
// Map<String, Object> jsonObject = JSON.parseObject(resourceStr, new TypeReference<HashMap<String, Object>>(){}); // Map<String, Object> jsonObject = JSON.parseObject(resourceStr, new TypeReference<HashMap<String, Object>>(){});
// if (jsonObject == null || jsonObject.isEmpty()) { // if (jsonObject == null || jsonObject.isEmpty()) {
// continue; // continue;
@@ -317,7 +320,7 @@ public class MgDocumentController {
.form(this.getGlobalParamObjMap(globalParamList, "form")) .form(this.getGlobalParamObjMap(globalParamList, "form"))
.addHeaders(this.getGlobalParamMap(globalParamList, "header")) .addHeaders(this.getGlobalParamMap(globalParamList, "header"))
.header("Accept", "application/json, text/javascript, */*; q=0.01") .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); boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl, openVisit);
if (!isLocation) { if (!isLocation) {
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
@@ -366,7 +369,7 @@ public class MgDocumentController {
String resourcesStr = HttpRequest.get(resourcesUrl) String resourcesStr = HttpRequest.get(resourcesUrl)
.form(this.getGlobalParamObjMap(globalParamList, "form")) .form(this.getGlobalParamObjMap(globalParamList, "form"))
.addHeaders(this.getGlobalParamMap(globalParamList, "header")) .addHeaders(this.getGlobalParamMap(globalParamList, "header"))
.timeout(3000).execute().body(); .timeout(docTimeout).execute().body();
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
if (resourceList == null || resourceList.isEmpty()) { if (resourceList == null || resourceList.isEmpty()) {
return DocResponseJson.warn("该地址未找到文档"); return DocResponseJson.warn("该地址未找到文档");

View File

@@ -35,6 +35,9 @@ public class MgOpenDocController {
@Resource @Resource
private MgStorageService storageService; private MgStorageService storageService;
// 文档请求超时时间
int docTimeout = 8000;
@PostMapping(value = "/checkConfig") @PostMapping(value = "/checkConfig")
public DocResponseJson<Object> checkConfig() { public DocResponseJson<Object> checkConfig() {
return DocResponseJson.ok(); return DocResponseJson.ok();
@@ -74,7 +77,7 @@ public class MgOpenDocController {
String resourceStr = HttpRequest.get(location.getLocation()) String resourceStr = HttpRequest.get(location.getLocation())
.form(this.getGlobalParamObjMap(globalParamList, "form")) .form(this.getGlobalParamObjMap(globalParamList, "form"))
.addHeaders(this.getGlobalParamMap(globalParamList, "header")) .addHeaders(this.getGlobalParamMap(globalParamList, "header"))
.timeout(3000).execute().body(); .timeout(docTimeout).execute().body();
String resourcesUrl = location.getLocation(); String resourcesUrl = location.getLocation();
int indexV2 = location.getLocation().indexOf("/v2"); int indexV2 = location.getLocation().indexOf("/v2");
if (indexV2 >= 0) { if (indexV2 >= 0) {