|
@@ -108,8 +108,7 @@ public class FaceppClient {
|
|
|
public JsonHttpResponseHolder compareWithTokenAndImageUrl(String faceToken, String imageUrl) {
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithTokenAndImageUrl(String,String); faceToken=" + faceToken
|
|
|
- + "; imageUrl=" + imageUrl);
|
|
|
+ log.debug("[Face++ Request]. faceToken=" + faceToken + "; imageUrl=" + imageUrl);
|
|
|
}
|
|
|
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
@@ -141,28 +140,25 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++]. compareWithTokenAndImageUrl(String,String); statusCode="
|
|
|
- + statusCode + "; responseEntity=" + entityStr);
|
|
|
+ log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
} else {
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithTokenAndImageUrl(String,String); statusCode="
|
|
|
- + statusCode + "; responseEntity=" + entityStr);
|
|
|
+ log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++]. compareWithTokenAndImageUrl(String,String); faceToken=" + faceToken
|
|
|
- + "; imageUrl=" + imageUrl + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.", e);
|
|
|
+ log.error("[Face++ FAIL]. cost " + (System.currentTimeMillis() - s) + " ms.", e);
|
|
|
throw new ExamCloudRuntimeException(e);
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(response);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithTokenAndImageUrl(String,String); faceToken=" + faceToken
|
|
|
- + "; imageUrl=" + imageUrl + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.");
|
|
|
+ log.debug("[Face++ OK]. faceToken=" + faceToken + "; imageUrl=" + imageUrl + "; cost "
|
|
|
+ + (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
|
return responseHolder;
|
|
@@ -189,6 +185,11 @@ public class FaceppClient {
|
|
|
public JsonHttpResponseHolder compareWithTokenAndImageUrl(String faceToken, String imageUrl,
|
|
|
String backupImageUrl) throws StatusException {
|
|
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("[Face++ Request]. faceToken=" + faceToken + "; imageUrl=" + imageUrl
|
|
|
+ + "; backupImageUrl=" + backupImageUrl);
|
|
|
+ }
|
|
|
+
|
|
|
JsonHttpResponseHolder responseHolder = null;
|
|
|
|
|
|
boolean exceptionWhenUsingImageUrl = false;
|
|
@@ -239,7 +240,7 @@ public class FaceppClient {
|
|
|
|
|
|
if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {
|
|
|
throw new StatusException("801",
|
|
|
- "fail to download file. url=" + backupImageUrl);
|
|
|
+ "fail to download image file. url=" + backupImageUrl);
|
|
|
}
|
|
|
|
|
|
byte[] byteArray = EntityUtils.toByteArray(response.getEntity());
|
|
@@ -250,20 +251,18 @@ public class FaceppClient {
|
|
|
imageBase64 = Base64.encodeBase64String(byteArray);
|
|
|
|
|
|
} catch (StatusException e) {
|
|
|
- log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
+ log.error("fail to download image file. url=" + backupImageUrl, e);
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
+ log.error("fail to download image file. url=" + backupImageUrl, e);
|
|
|
throw new StatusException("803", "fail to download file. url=" + backupImageUrl, e);
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(response);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug(
|
|
|
- "[Face++]. compareWithTokenAndImageUrl(String,String,String); download image; url="
|
|
|
- + backupImageUrl + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.");
|
|
|
+ log.debug("download image file successfully; url=" + backupImageUrl + "; cost "
|
|
|
+ + (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
|
responseHolder = compareWithTokenAndBase64(faceToken, imageBase64);
|
|
@@ -272,6 +271,13 @@ public class FaceppClient {
|
|
|
return responseHolder;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否重试
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param errMsg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private boolean retry(String errMsg) {
|
|
|
if (null != errMsg) {
|
|
|
if (errMsg.startsWith("INVALID_IMAGE_URL")
|
|
@@ -292,6 +298,10 @@ public class FaceppClient {
|
|
|
*/
|
|
|
public JsonHttpResponseHolder compareWithTokenAndBase64(String faceToken, String imageBase64) {
|
|
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("[Face++ Request]. faceToken=" + faceToken + "; imageBase64=?");
|
|
|
+ }
|
|
|
+
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
|
if (StringUtils.isBlank(url)) {
|
|
|
url = compareUrl;
|
|
@@ -321,28 +331,25 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++]. compareWithTokenAndBase64(String,String); statusCode="
|
|
|
- + statusCode + "; responseEntity=" + entityStr);
|
|
|
+ log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
} else {
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithTokenAndBase64(String,String); statusCode="
|
|
|
- + statusCode + "; responseEntity=" + entityStr);
|
|
|
+ log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++]. compareWithTokenAndBase64(String,String); faceToken=" + faceToken
|
|
|
- + "; imageBase64=" + imageBase64 + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.", e);
|
|
|
+ log.error("[Face++ FAIL]. cost " + (System.currentTimeMillis() - s) + " ms.", e);
|
|
|
throw new ExamCloudRuntimeException(e);
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(response);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithTokenAndBase64(String,String); faceToken=" + faceToken
|
|
|
- + "; imageBase64=" + imageBase64 + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.");
|
|
|
+ log.debug("[Face++ OK]. faceToken=" + faceToken + "; imageBase64=?; cost "
|
|
|
+ + (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
|
return responseHolder;
|
|
@@ -358,6 +365,10 @@ public class FaceppClient {
|
|
|
*/
|
|
|
public JsonHttpResponseHolder compareWithImageUrl(String imageUrl1, String imageUrl2) {
|
|
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
+ log.debug("[Face++ Request]. imageUrl1=" + imageUrl1 + "; imageUrl2=" + imageUrl2);
|
|
|
+ }
|
|
|
+
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
|
if (StringUtils.isBlank(url)) {
|
|
|
url = compareUrl;
|
|
@@ -387,28 +398,25 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++]. compareWithImageUrl(String,String); statusCode=" + statusCode
|
|
|
- + "; responseEntity=" + entityStr);
|
|
|
+ log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
} else {
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithImageUrl(String,String); statusCode="
|
|
|
- + statusCode + "; responseEntity=" + entityStr);
|
|
|
+ log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ + entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++]. compareWithImageUrl(String,String); image_url1=" + imageUrl1
|
|
|
- + "; imageUrl2=" + imageUrl2 + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.", e);
|
|
|
+ log.error("[Face++ FAIL]. cost " + (System.currentTimeMillis() - s) + " ms.", e);
|
|
|
throw new ExamCloudRuntimeException(e);
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(response);
|
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++]. compareWithImageUrl(String,String); image_url1=" + imageUrl1
|
|
|
- + "; imageUrl2=" + imageUrl2 + "; cost " + (System.currentTimeMillis() - s)
|
|
|
- + " ms.");
|
|
|
+ log.debug("[Face++ OK]. image_url1=" + imageUrl1 + "; imageUrl2=" + imageUrl2
|
|
|
+ + "; cost " + (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
|
return responseHolder;
|