use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class CurrentSystemHolder method initModuleApiInfos.
private static void initModuleApiInfos(BizSystemModule module) {
try {
String url;
if (module.getServiceId().startsWith("http")) {
url = String.format("%s/metadata", module.getServiceId());
} else {
url = String.format("http://%s/metadata", module.getServiceId());
}
AppMetadata appMetadata;
if (GlobalRuntimeContext.APPID.equals(module.getRouteName())) {
appMetadata = AppMetadataHolder.getMetadata();
} else {
appMetadata = new GenericApiRequest.Builder().requestUrl(url).responseClass(AppMetadata.class).backendInternalCall().build().waitResponse();
}
Map<String, ApiInfo> apiInfos = new HashMap<>(appMetadata.getApis().size());
String uri;
for (ApiInfo api : appMetadata.getApis()) {
if (GlobalRuntimeContext.APPID.equals(module.getRouteName())) {
uri = String.format("%s/%s", GlobalRuntimeContext.getContextPath(), api.getUrl());
} else {
uri = String.format("%s/%s/%s", GlobalRuntimeContext.getContextPath(), module.getRouteName(), api.getUrl());
}
uri = uri.replace("//", "/");
apiInfos.put(uri, api);
}
module.setApiInfos(apiInfos);
moduleApiInfos.put(module.getServiceId(), apiInfos);
} catch (Exception e) {
if (e instanceof JeesuiteBaseException && ((JeesuiteBaseException) e).getCode() == 404) {
module.setApiInfos(new HashMap<>(0));
moduleApiInfos.put(module.getServiceId(), module.getApiInfos());
} else {
log.warn(">> initModuleApiInfos error -> serviceId:{},error:{}", module.getServiceId(), e.getMessage());
}
}
}
Aggregations