|
@@ -24,9 +24,9 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.helpers.JsonHttpResponseHolder;
|
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
/**
|
|
|
* face++ 客户端
|
|
@@ -37,7 +37,7 @@ import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
*/
|
|
|
public class FaceppClient {
|
|
|
|
|
|
- protected static ExamCloudLog log = ExamCloudLogFactory.getLog(FaceppClient.class);
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(FaceppClient.class);
|
|
|
|
|
|
private static CloseableHttpClient httpclient;
|
|
|
|
|
@@ -90,10 +90,10 @@ public class FaceppClient {
|
|
|
apiSecret = PropertyHolder.getString("$facepp.apiSecret");
|
|
|
|
|
|
if (StringUtils.isBlank(apiKey)) {
|
|
|
- log.error("'facepp.apiKey' is not configured");
|
|
|
+ LOG.error("'facepp.apiKey' is not configured");
|
|
|
}
|
|
|
if (StringUtils.isBlank(apiSecret)) {
|
|
|
- log.error("'facepp.apiSecret' is not configured");
|
|
|
+ LOG.error("'facepp.apiSecret' is not configured");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -107,8 +107,8 @@ public class FaceppClient {
|
|
|
*/
|
|
|
public JsonHttpResponseHolder compareWithTokenAndImageUrl(String faceToken, String imageUrl) {
|
|
|
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Request]. faceToken=" + faceToken + "; imageUrl=" + imageUrl);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Request]. faceToken=" + faceToken + "; imageUrl=" + imageUrl);
|
|
|
}
|
|
|
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
@@ -140,24 +140,24 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ LOG.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
} else {
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++ FAIL]. 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++]. faceToken=" + faceToken + "; imageUrl=" + imageUrl + "; cost "
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++]. faceToken=" + faceToken + "; imageUrl=" + imageUrl + "; cost "
|
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
@@ -174,8 +174,8 @@ public class FaceppClient {
|
|
|
*/
|
|
|
public JsonHttpResponseHolder compareWithTokenAndBase64(String faceToken, String imageBase64) {
|
|
|
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Request]. faceToken=" + faceToken + "; imageBase64=?");
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Request]. faceToken=" + faceToken + "; imageBase64=?");
|
|
|
}
|
|
|
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
@@ -207,24 +207,24 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ LOG.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
} else {
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++ FAIL]. 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++]. faceToken=" + faceToken + "; imageBase64=?; cost "
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++]. faceToken=" + faceToken + "; imageBase64=?; cost "
|
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
@@ -241,8 +241,8 @@ public class FaceppClient {
|
|
|
*/
|
|
|
public JsonHttpResponseHolder compareWithImageUrl(String imageUrl1, String imageUrl2) {
|
|
|
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Request]. imageUrl1=" + imageUrl1 + "; imageUrl2=" + imageUrl2);
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Request]. imageUrl1=" + imageUrl1 + "; imageUrl2=" + imageUrl2);
|
|
|
}
|
|
|
|
|
|
String url = System.getProperty("facepp.compare.url");
|
|
@@ -274,24 +274,24 @@ public class FaceppClient {
|
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
- log.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ LOG.error("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
} else {
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
- log.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Response]. statusCode=" + statusCode + "; responseEntity="
|
|
|
+ entityStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Face++ FAIL]. 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++]. image_url1=" + imageUrl1 + "; imageUrl2=" + imageUrl2 + "; cost "
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++]. image_url1=" + imageUrl1 + "; imageUrl2=" + imageUrl2 + "; cost "
|
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|
|
@@ -319,8 +319,8 @@ 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
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("[Face++ Request]. faceToken=" + faceToken + "; imageUrl=" + imageUrl
|
|
|
+ "; backupImageUrl=" + backupImageUrl);
|
|
|
}
|
|
|
|
|
@@ -385,17 +385,17 @@ public class FaceppClient {
|
|
|
imageBase64 = Base64.encodeBase64String(byteArray);
|
|
|
|
|
|
} catch (StatusException e) {
|
|
|
- log.error("fail to download image file. url=" + backupImageUrl, e);
|
|
|
+ LOG.error("fail to download image file. url=" + backupImageUrl, e);
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("fail to download image 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("download image file successfully; url=" + backupImageUrl + "; cost "
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
+ LOG.debug("download image file successfully; url=" + backupImageUrl + "; cost "
|
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
|
}
|
|
|
|