Authored by FengRuwei

api自定义url

... ... @@ -85,10 +85,19 @@ public class JavaApiClient {
private CompletionService<JavaApiStatics> completionService;
public static MObjectDetails nullMobject = new MObjectDetails();
@PostConstruct
public void initBean() {
Collections.sort(javaApiHadnlerList);
javaApiHadnlerList.forEach(n -> System.out.println(n.getClass()));
nullMobject.setMoHostIp("0.0.0.0"); //influxdb tag can't null
nullMobject.setMoName("");
nullMobject.setMoId(0);
nullMobject.setMoTags("");
nullMobject.setMoTypeId(0);
nullMobject.setCloudType(0);
}
/**
... ... @@ -164,7 +173,11 @@ public class JavaApiClient {
long startTime = System.currentTimeMillis();
int tastNum = 0;
for (JavaApiInfo javaApiInfo : javaApimap.values()) {
if (javaApiInfo.getApiUrlCustom() == 1) { //自定义url
completionService.submit(new JavaApiTask(restTemplate, javaApiInfo, nullMobject));
tastNum++;
continue;
}
List<MObjectDetails> mObjectInfos = mObjInfoMap.get(javaApiInfo.getServiceType());
if (mObjectInfos == null) {
log.warn("type {} has no service object", javaApiInfo.getServiceType());
... ... @@ -174,6 +187,7 @@ public class JavaApiClient {
completionService.submit(new JavaApiTask(restTemplate, javaApiInfo, mObjectInfo));
tastNum++;
}
}
//wait for all rep end...
... ... @@ -201,12 +215,8 @@ public class JavaApiClient {
* @param rep
*/
public void handleResult(JavaApiStatics rep) {
//先做预处理,主要对返回结果格式为{code:200,message:".."}的响应做处理,对code非200的设置异常标志
//顺序处理,先做预处理,主要对返回结果格式为{code:200,message:".."}的响应做处理,对code非200的设置异常标志
javaApiHadnlerList.forEach(handler -> handler.handler(rep));
// for (IJavaApiHadnler javaApiHadnler : javaApiHadnlerList) {
// javaApiHadnler.handler(rep);
// }
}
... ...
... ... @@ -57,7 +57,6 @@ public class JavaApiTask implements Callable<JavaApiStatics> {
jsonRep = restTemplate.getForObject(url, String.class);
} else {
jsonRep = restTemplate.postForObject(url, req, String.class);
}
} catch (Exception e) {
log.warn("exception {} ", url);
... ... @@ -77,6 +76,9 @@ public class JavaApiTask implements Callable<JavaApiStatics> {
}
private String createReqUrl() {
if(javaApiInfo.getApiUrlCustom()==1&&javaApiInfo.getApiUrl()!=null) {
return javaApiInfo.getApiUrl(); //custom url
}
if (mObjectInfo.getMoHostIp() == null || mObjectInfo.getMoHostIp() == null || javaApiInfo.getApiUrl() == null) {
log.warn("get url failed has null prop. ");
return null;
... ...
... ... @@ -84,10 +84,13 @@ public class MsgJavaApiHandler extends IJavaApiHadnler {
msgBuilder.append("Java API Error ")
.append("最近出错次数:" + num).append(" , ")
.append("NAME:" + javaApiInfo.getApiName()).append(" , ")
// .append("URL:" + javaApiInfo.getApiUrl()).append(" , ")
.append("IP:" + mObjectInfo.getMoHostIp()).append(" , ")
.append("TYPE:" + javaApiInfo.getServiceType()).append(" , ");
if(javaApiInfo.getApiUrlCustom()==1){
msgBuilder.append("URL:" + javaApiInfo.getApiUrl()).append(" . ");
}else{
msgBuilder.append("IP:" + mObjectInfo.getMoHostIp()).append(" .");
}
return msgBuilder.toString();
}
... ...
... ... @@ -24,7 +24,7 @@ public class PreProcessJavaApiHandler extends IJavaApiHadnler {
return;
//无需判断服务异常
if (javaApiStatics.getJavaApiInfo().getApiErrorCheck() == 0)
if (javaApiStatics.getJavaApiInfo().getApiErrorCheck() == null ||javaApiStatics.getJavaApiInfo().getApiErrorCheck()==0)
return;
JSONObject jsonRep = null;
... ...