|
@@ -7,10 +7,10 @@ import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONException;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import com.sundata.common.exception.BusinessException;
|
|
|
import com.sundata.common.util.JsonUtil;
|
|
|
import com.sundata.internalevaluation.calc.calcUnit.interfaces.InterfaceRunning;
|
|
|
-import com.sundata.internalevaluation.calc.model.CalcException;
|
|
|
+import com.sundata.internalevaluation.calc.exception.CalcConfigException;
|
|
|
+import com.sundata.internalevaluation.calc.exception.SendRequestException;
|
|
|
import com.sundata.internalevaluation.calc.model.CalcResult;
|
|
|
import com.sundata.internalevaluation.calc.model.CalcUnit;
|
|
|
import com.sundata.internalevaluation.calc.model.finals.CalcType;
|
|
@@ -139,7 +139,7 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
// 请求类型不为 http或者 https 或者 请求体不为 json
|
|
|
if (!interfaceTypeCode.startsWith("http") || !"json".equals(reqContentTypeCode)) {
|
|
|
// TODO Socket 请求
|
|
|
- throw new BusinessException("目前仅支持http和https的请求和json请求体");
|
|
|
+ throw new CalcConfigException("目前仅支持http和https的请求和json请求体");
|
|
|
}
|
|
|
|
|
|
// 请求参数实体列表
|
|
@@ -224,8 +224,8 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
log.debug("接口-[{}({})]-请求地址-[{}]-响应body报文:{}",getCalcName(),getCalcCode(),url,responseStr);
|
|
|
}catch (Exception e){
|
|
|
String errMsg = StrUtil.format("接口-[{}({})]-请求地址-[{}] - 请求出现异常:{}", getCalcName(), getCalcCode(), url, e.getMessage());
|
|
|
- log.error(errMsg);
|
|
|
- throw new BusinessException(errMsg, e);
|
|
|
+ log.error(errMsg,e);
|
|
|
+ throw new SendRequestException("请求发送失败:["+url+"]", e);
|
|
|
}
|
|
|
|
|
|
// 判断返回值类型
|
|
@@ -235,13 +235,13 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
responseStr = JSONUtil.toJsonPrettyStr(responseStr);
|
|
|
} catch (JSONException e) {
|
|
|
log.error("接口-[{}({})]-请求地址-[{}] - 返回值不是程序能解析的json字符串,请检查!", getCalcName(), getCalcCode(), url);
|
|
|
- throw new CalcException(calculateInstanceNumber, "返回值不是程序能解析的json字符串,请检查!");
|
|
|
+ throw new CalcConfigException("返回值不是程序能解析的json字符串,请检查!",e);
|
|
|
}
|
|
|
}
|
|
|
// TODO 可继续增加其他类型
|
|
|
else
|
|
|
{
|
|
|
- throw new RuntimeException("接口-目前只支持 json 返回报文");
|
|
|
+ throw new CalcConfigException("接口-目前只支持 json 返回报文");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -306,13 +306,18 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- private Object getParamValue(InterfaceParam sysInterfaceParam, Map<String, Object> context) {
|
|
|
+ /**
|
|
|
+ * 获取请求参数的值
|
|
|
+ * @param interfaceParam 请求参数实体
|
|
|
+ * @param context 调用计算单元传入的值
|
|
|
+ * @return 参数结果
|
|
|
+ */
|
|
|
+ private Object getParamValue(InterfaceParam interfaceParam, Map<String, Object> context) {
|
|
|
// 参数获取类型
|
|
|
- String paramRetrievalTypeCode = sysInterfaceParam.getParamRetrievalTypeCode();
|
|
|
+ String paramRetrievalTypeCode = interfaceParam.getParamRetrievalTypeCode();
|
|
|
|
|
|
// 参数获取内容
|
|
|
- String paramRetrievalTypeCont = sysInterfaceParam.getParamRetrievalTypeCont();
|
|
|
+ String paramRetrievalTypeCont = interfaceParam.getParamRetrievalTypeCont();
|
|
|
|
|
|
Object result = null;
|
|
|
|
|
@@ -330,31 +335,36 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
try {
|
|
|
result = InvokeUtil.invokeMethod(paramRetrievalTypeCont);
|
|
|
} catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ String errorMsg = StrUtil.format("接口(参数)-[{}({})]-通过Java获取参数失败,对应方法为:[{}]", getCalcName(), interfaceParam.getParamObjName(), paramRetrievalTypeCont);
|
|
|
+ log.error(errorMsg);
|
|
|
+ throw new CalcConfigException(errorMsg,e);
|
|
|
}
|
|
|
break;
|
|
|
// SQL-Map
|
|
|
case "sqlmap":
|
|
|
String sqlMap = TemplateUtil.execute("interfaceParam-temp-sqlmap-" + getCalcCode(), paramRetrievalTypeCont, context);
|
|
|
- log.warn("sql语句为:{}",sqlMap);
|
|
|
+ log.debug("通过SQL-Map获取接口参数:{}",sqlMap);
|
|
|
result = jdbcTemplate.queryForMap(sqlMap);
|
|
|
break;
|
|
|
// SQL-List
|
|
|
case "sqllist":
|
|
|
String sqlList = TemplateUtil.execute("interfaceParam-temp-sqllist-" + getCalcCode(), paramRetrievalTypeCont, context);
|
|
|
- log.warn("sql语句为:{}",sqlList);
|
|
|
+ log.debug("通过SQL-Map获取接口参数:{}",sqlList);
|
|
|
result = jdbcTemplate.queryForList(sqlList);
|
|
|
break;
|
|
|
// SQL-String
|
|
|
case "sqlstring":
|
|
|
String sqlString = TemplateUtil.execute("interfaceParam-temp-sqlstring-" + getCalcCode(), paramRetrievalTypeCont, context);
|
|
|
- log.warn("sql语句为:{}",sqlString);
|
|
|
+ log.debug("通过SQL-Map获取接口参数:{}",sqlString);
|
|
|
result = jdbcTemplate.queryForObject(sqlString, Object.class);
|
|
|
break;
|
|
|
+ case "callerInput":
|
|
|
+ result = TemplateUtil.execute("interfaceParam-temp-callerInput-"+getCalcCode(),paramRetrievalTypeCont, context);
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
|
|
|
- String paramTypeCode = sysInterfaceParam.getParamTypeCode();
|
|
|
+ String paramTypeCode = interfaceParam.getParamTypeCode();
|
|
|
if ("string".equals(paramTypeCode)) {
|
|
|
if (result instanceof String) {
|
|
|
|
|
@@ -376,55 +386,14 @@ public class InterfaceCalcUnit extends CalcUnit {
|
|
|
} else if (result instanceof Byte) {
|
|
|
result = ((Number) result).byteValue();
|
|
|
} else {
|
|
|
- throw new RuntimeException("数据类型不匹配:计算机过不为'数字'");
|
|
|
+ throw new CalcConfigException("数据类型不匹配:计算机过不为'数字'");
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
- throw new RuntimeException("数据类型不匹配:计算机过不为'数字'");
|
|
|
+ throw new CalcConfigException("数据类型不匹配:计算机过不为'数字'");
|
|
|
}
|
|
|
} else {
|
|
|
- throw new CalcException("返回值类型有无,目前仅有 数字和字符串");
|
|
|
+ throw new CalcConfigException("返回值类型有误,目前仅有 数字和字符串");
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param url
|
|
|
- * @param bodyStr
|
|
|
- * @param allParam
|
|
|
- * @return
|
|
|
- */
|
|
|
-// private String sendRequestBySDKAPI (String url, String bodyStr, HashMap<String,Object> allParam) {
|
|
|
-// Object publicKey = allParam.get("publicKey");
|
|
|
-// if (publicKey == null) {
|
|
|
-// throw new RuntimeException("publicKey 不能为空");
|
|
|
-// }
|
|
|
-// Object systemCode = allParam.get("systemCode");
|
|
|
-// if (systemCode == null) {
|
|
|
-// throw new RuntimeException("systemCode 不能为空");
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 构建发送请求客户端
|
|
|
-// ApiClient apiClient = ApiClient.builder().apiUrl(url)
|
|
|
-// .publicKey(publicKey)
|
|
|
-// .systemCode(systemCode)
|
|
|
-// .build();
|
|
|
-//
|
|
|
-// // 构建json反序列化为MyApiRequest 对象
|
|
|
-// MyApiRequest apiRequest = JSONUtil.toBean(bodyStr,MyApiRequest.class);
|
|
|
-// String jsonPrettyStr = JSONUtil.toJsonPrettyStr(apiRequest);
|
|
|
-// // 相应信息
|
|
|
-// ApiResponse<JSONObject> response = apiRequest.excute(apiClient);
|
|
|
-// String jsonStr = JSONUtil.toJsonStr(response);
|
|
|
-// return jsonStr;
|
|
|
-// }
|
|
|
-//
|
|
|
-//// private static class MyApiRequest extends ApiRequest<HashMap<String,Object>, JSONObject> {
|
|
|
-// public MyApiRequest() {
|
|
|
-// super.setResponseDataClass(JSONObject.class);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
}
|