Skip to content
Permalink
Browse files
fix dubbo api docs (#676)
fix #675
  • Loading branch information
KeRan213539 committed Jan 14, 2021
1 parent 8fc5927 commit 272b598b6b39bc9bf751336f0adb8286d4a73c6c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
@@ -112,8 +112,8 @@ public String callDubboService(CallDubboServiceRequest dubboCfg, @RequestBody Li
if(paramValue instanceof Map){
Map<?, ?> tempMap = (Map<?, ?>) paramValue;
if(!tempMap.isEmpty()) {
this.emptyString2Null(tempMap);
paramValues[i] = tempMap.values().stream().findFirst().orElse(null);
Object tempParamValue = tempMap.values().stream().findFirst().orElse(null);
paramValues[i] = this.emptyString2Null(tempParamValue);
}
} else {
paramValues[i] = emptyString2Null(paramValue);
@@ -131,7 +131,7 @@ public String callDubboService(CallDubboServiceRequest dubboCfg, @RequestBody Li
paramValues = new Object[0];
}
CompletableFuture<Object> future = ApiDocsDubboGenericUtil.invoke(dubboCfg.getRegistryCenterUrl(), dubboCfg.getInterfaceClassName(),
dubboCfg.getMethodName(), dubboCfg.isAsync(), paramTypes, paramValues);
dubboCfg.getMethodName(), dubboCfg.isAsync(), dubboCfg.getVersion(), paramTypes, paramValues);
try {
Object objResult = future.get();
return JSON.toJSONString(objResult, CLASS_NAME_PRE_FILTER);
@@ -36,6 +36,17 @@ public class CallDubboServiceRequest {
@ApiParam(value = "Whether to call asynchronously, false by default")
private boolean async = false;

@ApiParam(value = "The version of API")
private String version;

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getRegistryCenterUrl() {
return registryCenterUrl;
}
@@ -111,12 +111,14 @@ private static void removeRegistryConfig(String address) {
* @param: address address Address of Registration Center
* @param: interfaceName Interface full package path
*/
private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName) {
ReferenceConfig<GenericService> referenceConfig = referenceCache.get(address + "/" + interfaceName);
private static ReferenceConfig<GenericService> getReferenceConfig(String address, String interfaceName, String version) {
final String key = buildCacheKey(address, interfaceName, version);
ReferenceConfig<GenericService> referenceConfig = referenceCache.get(key);
if (null == referenceConfig) {
referenceConfig = new ReferenceConfig<>();
referenceConfig.setRetries(retries);
referenceConfig.setTimeout(timeout);
referenceConfig.setVersion(version);
referenceConfig.setApplication(application);
if (address.startsWith("dubbo")) {
referenceConfig.setUrl(address);
@@ -126,7 +128,7 @@ private static ReferenceConfig<GenericService> getReferenceConfig(String address
referenceConfig.setInterface(interfaceName);
// Declared as a generic interface
referenceConfig.setGeneric(true);
referenceCache.put(address + "/" + interfaceName, referenceConfig);
referenceCache.put(key, referenceConfig);
}
return referenceConfig;
}
@@ -137,9 +139,13 @@ private static ReferenceConfig<GenericService> getReferenceConfig(String address
* @param interfaceName
* @return void
*/
private static void removeReferenceConfig(String address, String interfaceName) {
private static void removeReferenceConfig(String address, String interfaceName, String version) {
removeRegistryConfig(address);
referenceCache.remove(address + "/" + interfaceName);
referenceCache.remove(buildCacheKey(address, interfaceName, version));
}

private static String buildCacheKey(String address, String interfaceName, String version) {
return address + "/" + interfaceName + "/" + version;
}

/**
@@ -155,10 +161,10 @@ private static void removeReferenceConfig(String address, String interfaceName)
* @param: paramValues
*/
public static CompletableFuture<Object> invoke(String address, String interfaceName,
String methodName, boolean async, String[] paramTypes,
String methodName, boolean async, String version, String[] paramTypes,
Object[] paramValues) {
CompletableFuture future = null;
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName);
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
if (null != reference) {
GenericService genericService = reference.get();
if (null != genericService) {
@@ -170,7 +176,7 @@ public static CompletableFuture<Object> invoke(String address, String interfaceN
}
future.exceptionally(ex -> {
if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
removeReferenceConfig(address, interfaceName);
removeReferenceConfig(address, interfaceName, version);
}
return ex;
});
@@ -190,9 +196,9 @@ public static CompletableFuture<Object> invoke(String address, String interfaceN
* @param: paramValues
*/
public static Object invokeSync(String address, String interfaceName,
String methodName, String[] paramTypes,
String methodName, String version, String[] paramTypes,
Object[] paramValues) {
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName);
ReferenceConfig<GenericService> reference = getReferenceConfig(address, interfaceName, version);
if (null != reference) {
GenericService genericService = reference.get();
try {
@@ -201,7 +207,7 @@ public static Object invokeSync(String address, String interfaceName,
}
} catch (Exception ex) {
if (StringUtils.contains(ex.toString(), "Failed to invoke remote method")) {
removeReferenceConfig(address, interfaceName);
removeReferenceConfig(address, interfaceName, version);
} else {
throw ex;
}
@@ -401,7 +401,8 @@ export default {
async: this.formItemAsync,
interfaceClassName: this.formItemInterfaceClassName,
methodName: this.formItemMethodName,
registryCenterUrl: this.formItemRegistryCenterUrl
registryCenterUrl: this.formItemRegistryCenterUrl,
version: this.apiInfoData.apiVersion || ''
},
headers: {
'Content-Type': 'application/json; charset=UTF-8'
@@ -178,11 +178,10 @@ export default {
},
buildDefaultValue () {
var defaultValue = this.formItemInfo.get('defaultValue')
if (defaultValue) {
this.formValues.set(this.buildItemId(), defaultValue)
} else {
if (!defaultValue) {
defaultValue = ''
}
this.formValues.set(this.buildItemId(), defaultValue)
return defaultValue
},
buildSelectDefaultValue () {
@@ -192,6 +191,8 @@ export default {
if (defaultValue) {
this.selectDefaultValue = defaultValue
this.formValues.set(this.buildItemId(), defaultValue[0])
} else {
this.formValues.set(this.buildItemId(), '')
}
}
return this.selectDefaultValue
@@ -170,7 +170,7 @@ export default {
missingInterfaceInfo: 'Missing interface information',
getApiInfoErr: 'Exception in obtaining interface information',
api404Err: 'Interface name is incorrect, interface parameters and response information are not found',
apiRespDecShowLabel: 'Api Info',
apiRespDecShowLabel: 'Response Description',
apiNameShowLabel: 'Api Name',
apiPathShowLabel: 'Api Path',
apiMethodParamInfoLabel: 'Api method parameters',
@@ -170,12 +170,12 @@ export default {
missingInterfaceInfo: '缺少接口信息',
getApiInfoErr: '获取接口信息异常',
api404Err: '接口名称不正确,没有查找到接口参数和响应信息',
apiRespDecShowLabel: '接口说明',
apiRespDecShowLabel: '响应说明',
apiNameShowLabel: '接口名称',
apiPathShowLabel: '接口位置',
apiMethodParamInfoLabel: '接口参数',
apiVersionShowLabel: '接口版本',
apiDescriptionShowLabel: '接口描述',
apiDescriptionShowLabel: '接口说明',
isAsyncFormLabel: '是否异步调用(此参数不可修改,根据接口定义的是否异步显示)',
apiModuleFormLabel: '接口模块(此参数不可修改)',
apiFunctionNameFormLabel: '接口方法名(此参数不可修改)',

0 comments on commit 272b598

Please sign in to comment.