|
@@ -302,7 +302,7 @@ public class BaiduClient {
|
|
return responseHolder;
|
|
return responseHolder;
|
|
}
|
|
}
|
|
|
|
|
|
- if (222204 == errCode || 222013 == errCode) {
|
|
|
|
|
|
+ if (retry(errCode)) {
|
|
responseHolder = verifyFaceLiveness(backupImageUrl);
|
|
responseHolder = verifyFaceLiveness(backupImageUrl);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -313,43 +313,50 @@ public class BaiduClient {
|
|
return responseHolder;
|
|
return responseHolder;
|
|
}
|
|
}
|
|
|
|
|
|
- HttpGet get = new HttpGet(backupImageUrl);
|
|
|
|
- get.setConfig(BaiduClient.requestConfig);
|
|
|
|
- CloseableHttpResponse response = null;
|
|
|
|
- String imageBase64 = null;
|
|
|
|
- long s = System.currentTimeMillis();
|
|
|
|
- try {
|
|
|
|
- response = httpclient.execute(get);
|
|
|
|
|
|
+ if (retry(errCode)) {
|
|
|
|
+ HttpGet get = new HttpGet(backupImageUrl);
|
|
|
|
+ get.setConfig(BaiduClient.requestConfig);
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ String imageBase64 = null;
|
|
|
|
+ long s = System.currentTimeMillis();
|
|
|
|
+ try {
|
|
|
|
+ response = httpclient.execute(get);
|
|
|
|
+
|
|
|
|
+ if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {
|
|
|
|
+ throw new StatusException("901",
|
|
|
|
+ "fail to download file. url=" + backupImageUrl);
|
|
|
|
+ }
|
|
|
|
|
|
- if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {
|
|
|
|
- throw new StatusException("901", "fail to download file. url=" + backupImageUrl);
|
|
|
|
- }
|
|
|
|
|
|
+ byte[] byteArray = EntityUtils.toByteArray(response.getEntity());
|
|
|
|
+ if (100 > byteArray.length) {
|
|
|
|
+ throw new StatusException("902", "invalid image size. url=" + backupImageUrl);
|
|
|
|
+ }
|
|
|
|
|
|
- byte[] byteArray = EntityUtils.toByteArray(response.getEntity());
|
|
|
|
- if (100 > byteArray.length) {
|
|
|
|
- throw new StatusException("902", "invalid image size. url=" + backupImageUrl);
|
|
|
|
- }
|
|
|
|
|
|
+ imageBase64 = Base64.encodeBase64String(byteArray);
|
|
|
|
|
|
- imageBase64 = Base64.encodeBase64String(byteArray);
|
|
|
|
|
|
+ } catch (StatusException e) {
|
|
|
|
+ log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
|
+ throw e;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
|
+ throw new StatusException("903", "fail to download file. url=" + backupImageUrl, e);
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(response);
|
|
|
|
+ }
|
|
|
|
|
|
- } catch (StatusException e) {
|
|
|
|
- log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
|
- throw e;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("fail to download file. url=" + backupImageUrl, e);
|
|
|
|
- throw new StatusException("903", "fail to download file. url=" + backupImageUrl, e);
|
|
|
|
- } finally {
|
|
|
|
- IOUtils.closeQuietly(response);
|
|
|
|
- }
|
|
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
|
+ log.debug("[Face++]. verifyFaceLiveness(String,String); download image; url="
|
|
|
|
+ + backupImageUrl + "; cost " + (System.currentTimeMillis() - s) + " ms.");
|
|
|
|
+ }
|
|
|
|
|
|
- if (log.isDebugEnabled()) {
|
|
|
|
- log.debug("[Face++]. verifyFaceLiveness(String,String); download image; url="
|
|
|
|
- + backupImageUrl + "; cost " + (System.currentTimeMillis() - s) + " ms.");
|
|
|
|
|
|
+ responseHolder = verifyFaceLivenessUseBase64(imageBase64);
|
|
}
|
|
}
|
|
|
|
|
|
- responseHolder = verifyFaceLivenessUseBase64(imageBase64);
|
|
|
|
-
|
|
|
|
return responseHolder;
|
|
return responseHolder;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private boolean retry(long errCode) {
|
|
|
|
+ return 222204 == errCode || 222013 == errCode;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|