Search in sources :

Example 6 with ApiInfo

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());
        }
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) HashMap(java.util.HashMap) ApiInfo(com.jeesuite.common.model.ApiInfo) AppMetadata(com.jeesuite.springweb.model.AppMetadata) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

ApiInfo (com.jeesuite.common.model.ApiInfo)6 BizSystemModule (com.jeesuite.gateway.model.BizSystemModule)2 ActionLog (com.jeesuite.logging.integrate.ActionLog)2 JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)1 ApiMetadata (com.jeesuite.common.annotation.ApiMetadata)1 ApiPermission (com.jeesuite.security.model.ApiPermission)1 AppMetadata (com.jeesuite.springweb.model.AppMetadata)1 Pair (com.netflix.util.Pair)1 ApiOperation (io.swagger.annotations.ApiOperation)1 InputStreamReader (java.io.InputStreamReader)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)1