远程ar调用api异常处理
This commit is contained in:
@@ -48,13 +48,19 @@ public class ARRemoteCloudJob {
|
|||||||
|
|
||||||
String sign = getSign(param, ARConstant.AR_APP_SECRET);
|
String sign = getSign(param, ARConstant.AR_APP_SECRET);
|
||||||
|
|
||||||
String response = arRemoteClient.getToken(
|
String response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.getToken(
|
||||||
new ARGetTokenRequest()
|
new ARGetTokenRequest()
|
||||||
.setApiKey(ARConstant.AR_APP_KEY)
|
.setApiKey(ARConstant.AR_APP_KEY)
|
||||||
.setExpires(ARConstant.EXPIRES_TIME)
|
.setExpires(ARConstant.EXPIRES_TIME)
|
||||||
.setTimestamp(timestamp)
|
.setTimestamp(timestamp)
|
||||||
.setSignature(sign)
|
.setSignature(sign)
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别获取token失败", e);
|
||||||
|
throw new RuntimeException("ar云识别获取token失败");
|
||||||
|
}
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
||||||
@@ -76,7 +82,13 @@ public class ARRemoteCloudJob {
|
|||||||
|
|
||||||
@XxlJob("zyp-ar-cloud-health-check")
|
@XxlJob("zyp-ar-cloud-health-check")
|
||||||
public void arHealthCheck() {
|
public void arHealthCheck() {
|
||||||
ARHealthCheckResponse response = arRemoteClient.arHealthCheck();
|
ARHealthCheckResponse response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.arHealthCheck();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别健康检查失败", e);
|
||||||
|
throw new RuntimeException("ar云识别健康检查失败");
|
||||||
|
}
|
||||||
Boolean result = response.getResult().getMessage().equals("pong");
|
Boolean result = response.getResult().getMessage().equals("pong");
|
||||||
Boolean cacheResult = (Boolean) redisService.get(AR_HEALTH_CHECK);
|
Boolean cacheResult = (Boolean) redisService.get(AR_HEALTH_CHECK);
|
||||||
if (cacheResult == null) {
|
if (cacheResult == null) {
|
||||||
@@ -93,7 +105,6 @@ public class ARRemoteCloudJob {
|
|||||||
redisService.set(AR_HEALTH_CHECK, result);
|
redisService.set(AR_HEALTH_CHECK, result);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!cacheResult.equals(result)) {
|
if (!cacheResult.equals(result)) {
|
||||||
Param paramOne = paramService.getOne(
|
Param paramOne = paramService.getOne(
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
//hutool 生成随机字符串
|
//hutool 生成随机字符串
|
||||||
String nonceStr = RandomUtil.randomString(10);
|
String nonceStr = RandomUtil.randomString(10);
|
||||||
|
String response ;
|
||||||
|
try {
|
||||||
String response = arRemoteClient.createTarget(
|
response= arRemoteClient.createTarget(
|
||||||
token , new ARCreateTargetRequest()
|
token , new ARCreateTargetRequest()
|
||||||
.setImage(image)
|
.setImage(image)
|
||||||
.setActive(ARConstant.AR_IMAGE_ACTIVE)
|
.setActive(ARConstant.AR_IMAGE_ACTIVE)
|
||||||
@@ -67,6 +67,11 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
.setAppKey(ARConstant.AR_APP_KEY)
|
.setAppKey(ARConstant.AR_APP_KEY)
|
||||||
// .setSignature(sign)
|
// .setSignature(sign)
|
||||||
);
|
);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("ar云识别创建目标失败", e);
|
||||||
|
throw new RuntimeException("ar云识别创建目标失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)){
|
if (!jsonObject.get("statusCode").equals(0)){
|
||||||
@@ -85,8 +90,13 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
Assert.notNull(targetInfo, "未找到该图片信息");
|
Assert.notNull(targetInfo, "未找到该图片信息");
|
||||||
|
|
||||||
long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
||||||
|
String result;
|
||||||
String result = arRemoteClient.delTargetInfo(getToken(), targetId , String.valueOf(timeInMillis), ARConstant.AR_APP_KEY, ARConstant.AR_APP_ID );
|
try {
|
||||||
|
result = arRemoteClient.delTargetInfo(getToken(), targetId, String.valueOf(timeInMillis), ARConstant.AR_APP_KEY, ARConstant.AR_APP_ID);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别删除目标失败", e);
|
||||||
|
throw new RuntimeException("ar云识别删除目标失败");
|
||||||
|
}
|
||||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
||||||
@@ -100,7 +110,13 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
private String findTargetInfo(String targetId , String token) {
|
private String findTargetInfo(String targetId , String token) {
|
||||||
long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
long timeInMillis = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
String result = arRemoteClient.findTargetInfo(token, targetId , String.valueOf(timeInMillis), ARConstant.AR_APP_KEY, ARConstant.AR_APP_ID );
|
String result;
|
||||||
|
try {
|
||||||
|
result = arRemoteClient.findTargetInfo(token, targetId, String.valueOf(timeInMillis), ARConstant.AR_APP_KEY, ARConstant.AR_APP_ID);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别查询目标失败", e);
|
||||||
|
throw new RuntimeException("ar云识别查询目标失败");
|
||||||
|
}
|
||||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
String msg = ARCodeEnum.getMsg(jsonObject.getInteger("statusCode"));
|
||||||
@@ -114,13 +130,19 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
private Boolean targetDetection(String image , String token) {
|
private Boolean targetDetection(String image , String token) {
|
||||||
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
String response = arRemoteClient.targetDetection(
|
String response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.targetDetection(
|
||||||
token, new ARDetectionTargetRequest()
|
token, new ARDetectionTargetRequest()
|
||||||
.setImage(image)
|
.setImage(image)
|
||||||
.setTimestamp(timestamp)
|
.setTimestamp(timestamp)
|
||||||
.setAppId(ARConstant.AR_APP_ID)
|
.setAppId(ARConstant.AR_APP_ID)
|
||||||
.setAppKey(ARConstant.AR_APP_KEY)
|
.setAppKey(ARConstant.AR_APP_KEY)
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别目标检测失败", e);
|
||||||
|
throw new RuntimeException("ar云识别目标检测失败");
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
@@ -141,13 +163,19 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
private List<String> targetSimilar(String image ,String token) {
|
private List<String> targetSimilar(String image ,String token) {
|
||||||
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
String response = arRemoteClient.targetSimilar(
|
String response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.targetSimilar(
|
||||||
token, new ARSimilarTargetRequest()
|
token, new ARSimilarTargetRequest()
|
||||||
.setImage(image)
|
.setImage(image)
|
||||||
.setTimestamp(timestamp)
|
.setTimestamp(timestamp)
|
||||||
.setAppId(ARConstant.AR_APP_ID)
|
.setAppId(ARConstant.AR_APP_ID)
|
||||||
.setAppKey(ARConstant.AR_APP_KEY)
|
.setAppKey(ARConstant.AR_APP_KEY)
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别对比相似图片失败", e);
|
||||||
|
throw new RuntimeException("ar云识别对比相似图片失败");
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
@@ -181,7 +209,9 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
|
|
||||||
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
String response = arRemoteClient.updateTarget(
|
String response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.updateTarget(
|
||||||
getToken(), new ARUpdateTargetRequest()
|
getToken(), new ARUpdateTargetRequest()
|
||||||
.setImage(image)
|
.setImage(image)
|
||||||
.setActive(ARConstant.AR_IMAGE_ACTIVE)
|
.setActive(ARConstant.AR_IMAGE_ACTIVE)
|
||||||
@@ -192,6 +222,10 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
.setAppKey(ARConstant.AR_APP_KEY),
|
.setAppKey(ARConstant.AR_APP_KEY),
|
||||||
targetId
|
targetId
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别更新图片失败", e);
|
||||||
|
throw new RuntimeException("ar云识别更新图片失败");
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
@@ -206,7 +240,9 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
public String searchTarget(String image) {
|
public String searchTarget(String image) {
|
||||||
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
Long timestamp = Calendar.getInstance().getTimeInMillis();
|
||||||
|
|
||||||
String response = arRemoteClient.searchTarget(
|
String response;
|
||||||
|
try {
|
||||||
|
response = arRemoteClient.searchTarget(
|
||||||
getToken(), new ARSearchTargetRequest()
|
getToken(), new ARSearchTargetRequest()
|
||||||
.setImage(image)
|
.setImage(image)
|
||||||
.setNotracking("true")
|
.setNotracking("true")
|
||||||
@@ -215,6 +251,10 @@ public class ARImgIdentifyServiceImpl implements ARImgIdentifyService {
|
|||||||
.setAppKey(ARConstant.AR_APP_KEY)
|
.setAppKey(ARConstant.AR_APP_KEY)
|
||||||
|
|
||||||
);
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("ar云识别搜索图片失败", e);
|
||||||
|
throw new RuntimeException("ar云识别搜索图片失败");
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
if (!jsonObject.get("statusCode").equals(0)) {
|
if (!jsonObject.get("statusCode").equals(0)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user