优化配置,Face++宕机、可以给出友情提示
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
# url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
# url: jdbc:mysql://yingdiandian.mysql.rds.aliyuncs.com:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
|
||||||
# username: yingdd
|
# username: yingdd
|
||||||
# password: Yingdd2015
|
# password: Yingdd2015
|
||||||
url: jdbc:mysql://127.0.01:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
url: jdbc:mysql://127.0.01:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 123456
|
||||||
# url: jdbc:mysql://120.27.209.4:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
# url: jdbc:mysql://120.27.209.4:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
|
||||||
# username: root
|
# username: root
|
||||||
# password: hyty1234
|
# password: hyty1234
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
|
url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: hyty1234
|
password: hyty1234
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF8"?>
|
<?xml version="1.0" encoding="UTF8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<jmxConfigurator />
|
<jmxConfigurator />
|
||||||
<property name="LOG_HOME" value="/home/log/svapi"/>
|
<property name="LOG_HOME" value="/home/log/api_logs"/>
|
||||||
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
@@ -10,30 +10,37 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="springLogFile"
|
<appender name="COMMON-DEFAULT"
|
||||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${LOG_HOME}/api-spring.log</file>
|
<file>${LOG_HOME}/common-default.log</file>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<fileNamePattern>${LOG_HOME}/api-spring-%d{yyyy-MM-dd_HH}.%i.log
|
<fileNamePattern>${LOG_HOME}/common-default-%d{yyyy-MM-dd}.log
|
||||||
</fileNamePattern>
|
</fileNamePattern>
|
||||||
<timeBasedFileNamingAndTriggeringPolicy
|
|
||||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
|
||||||
<maxFileSize>10MB</maxFileSize>
|
|
||||||
</timeBasedFileNamingAndTriggeringPolicy>
|
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<logger name= "org.springframework" level="info" additivity="false">
|
<appender name="COMMON-ERROR"
|
||||||
<appender-ref ref="springLogFile" />
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
</logger>
|
<file>${LOG_HOME}/common-error.log</file>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
|
<level>ERROR</level>
|
||||||
|
</filter>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOG_HOME}/common-error-%d{yyyy-MM-dd}.log
|
||||||
|
</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
<!-- root -->
|
<!-- root -->
|
||||||
<root level="info">
|
<root level="info">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
<appender-ref ref="springLogFile" />
|
<appender-ref ref="COMMON-DEFAULT" />
|
||||||
|
<appender-ref ref="COMMON-ERROR" />
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
import org.apache.http.client.methods.*;
|
import org.apache.http.client.methods.*;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
@@ -55,18 +56,24 @@ public class FaceService {
|
|||||||
/**
|
/**
|
||||||
* face++登录
|
* face++登录
|
||||||
*/
|
*/
|
||||||
public boolean login() throws IOException {
|
public boolean login() {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("username", account);
|
param.addProperty("username", account);
|
||||||
param.addProperty("password", pwd);
|
param.addProperty("password", pwd);
|
||||||
CloseableHttpResponse response = post(param, "auth/login");
|
CloseableHttpResponse response = null;
|
||||||
|
try {
|
||||||
|
response = post(param, "auth/login");
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
LoginResponse loginResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), LoginResponse.class);
|
LoginResponse loginResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), LoginResponse.class);
|
||||||
logger.info("登录成功" + ToStringBuilder.reflectionToString(loginResponse));
|
logger.info("登录成功" + ToStringBuilder.reflectionToString(loginResponse));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
logger.error("face++登陆失败!");
|
logger.error("face++登陆失败!");
|
||||||
throw new FaceServiceException("登录失败");
|
throw new FaceServiceException("无法连接人脸服务器");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("login无法连接人脸服务器");
|
||||||
|
throw new FaceServiceException("无法连接人脸服务器");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +84,7 @@ public class FaceService {
|
|||||||
* @param member
|
* @param member
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Integer addSubject(Integer faceId, Member member) throws IOException {
|
public Integer addSubject(Integer faceId, Member member) throws UnsupportedEncodingException {
|
||||||
JsonObject param = new JsonObject();
|
JsonObject param = new JsonObject();
|
||||||
param.addProperty("gender", 1);
|
param.addProperty("gender", 1);
|
||||||
String nickname = member.getNickname();
|
String nickname = member.getNickname();
|
||||||
@@ -92,6 +99,7 @@ public class FaceService {
|
|||||||
JsonArray faceIds = new JsonArray();
|
JsonArray faceIds = new JsonArray();
|
||||||
faceIds.add(faceId);
|
faceIds.add(faceId);
|
||||||
param.add("photo_ids", faceIds);
|
param.add("photo_ids", faceIds);
|
||||||
|
try {
|
||||||
CloseableHttpResponse response = post(param, "subject");
|
CloseableHttpResponse response = post(param, "subject");
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
AddMemberResponse addMemberResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), AddMemberResponse.class);
|
AddMemberResponse addMemberResponse = JsonMapper.nonNullMapper().fromJson(response.getEntity().getContent(), AddMemberResponse.class);
|
||||||
@@ -105,6 +113,10 @@ public class FaceService {
|
|||||||
logger.error("添加用户失败 code:" + response.getStatusLine().getStatusCode());
|
logger.error("添加用户失败 code:" + response.getStatusLine().getStatusCode());
|
||||||
throw new FaceServiceException("添加用户失败");
|
throw new FaceServiceException("添加用户失败");
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("addSubject无法连接人脸服务器");
|
||||||
|
throw new FaceServiceException("无法连接人脸服务器");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(String faceId,String money,String detail) {
|
public void show(String faceId,String money,String detail) {
|
||||||
@@ -122,6 +134,7 @@ public class FaceService {
|
|||||||
try {
|
try {
|
||||||
CloseableHttpResponse response = httpClient.execute(req);
|
CloseableHttpResponse response = httpClient.execute(req);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
logger.error("show发生异常",e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,9 +196,15 @@ public class FaceService {
|
|||||||
HttpPost httpPost = new HttpPost("http://" + faceUrl + "/" + uri);
|
HttpPost httpPost = new HttpPost("http://" + faceUrl + "/" + uri);
|
||||||
httpPost.addHeader("Content-Type", "application/json");
|
httpPost.addHeader("Content-Type", "application/json");
|
||||||
httpPost.addHeader("user-agent", "Koala Admin");
|
httpPost.addHeader("user-agent", "Koala Admin");
|
||||||
if (param != null)
|
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(7000)
|
||||||
|
.setSocketTimeout(7000).setConnectTimeout(1000).build();
|
||||||
|
httpPost.setConfig(requestConfig);
|
||||||
|
if (param != null){
|
||||||
httpPost.setEntity(new StringEntity(param.toString()));
|
httpPost.setEntity(new StringEntity(param.toString()));
|
||||||
|
}
|
||||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
|
logger.info(uri+"返回编码"+response.getStatusLine().getStatusCode());
|
||||||
|
logger.info(uri+"返回结果"+response.toString());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user