commit
This commit is contained in:
parent
527e442bc7
commit
e9d639d3b8
|
@ -0,0 +1,56 @@
|
||||||
|
log4j.rootLogger=INFO,stdout,info,warn,error
|
||||||
|
|
||||||
|
log4j.logger.info=info
|
||||||
|
log4j.logger.warn=warn
|
||||||
|
log4j.logger.error=error
|
||||||
|
|
||||||
|
log4j.logger.org.springframework=warn
|
||||||
|
log4j.logger.org.apache=info,error
|
||||||
|
log4j.logger.org.aspectj.weaver=warn
|
||||||
|
log4j.logger.org.hibernate=off
|
||||||
|
log4j.logger.com.mchange=off
|
||||||
|
log4j.logger.java.sql.Connection=info
|
||||||
|
log4j.logger.java.sql.Statement=info
|
||||||
|
log4j.logger.java.sql.ResultSet=info
|
||||||
|
log4j.logger.java.sql.PreparedStatement=info
|
||||||
|
|
||||||
|
#log4j.logger.httpclient.wire.header=off
|
||||||
|
#log4j.logger.httpclient.wire.content=off
|
||||||
|
#log4j.logger.org.apache.commons.httpclient=off
|
||||||
|
#log4j.logger.org.apache.commons.httpclient.Wire=off
|
||||||
|
|
||||||
|
|
||||||
|
################打印到控制台
|
||||||
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH\:mm\:ss\:SSS}\:%l - \n%p\: %m%n
|
||||||
|
|
||||||
|
################记录系统日志,监控客户端运行情况
|
||||||
|
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.info.File=bootlog/INFO.log
|
||||||
|
log4j.appender.info.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.info.Threshold = INFO
|
||||||
|
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||||
|
log4j.appender.info.DatePattern = '.'yyyy-MM-dd
|
||||||
|
log4j.appender.info.encoding=UTF-8
|
||||||
|
################
|
||||||
|
|
||||||
|
################记录系统告警日志
|
||||||
|
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.warn.File=bootlog/WARN.log
|
||||||
|
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.warn.Threshold = WARN
|
||||||
|
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||||
|
log4j.appender.warn.DatePattern = '.'yyyy-MM-dd
|
||||||
|
log4j.appender.warn.encoding=UTF-8
|
||||||
|
################
|
||||||
|
|
||||||
|
################记录系统错误,监控程序是否出错
|
||||||
|
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
|
||||||
|
log4j.appender.error.File=bootlog/ERROR.log
|
||||||
|
log4j.appender.error.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.error.Threshold = ERROR
|
||||||
|
log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||||
|
log4j.appender.error.DatePattern = '.'yyyy-MM-dd
|
||||||
|
log4j.appender.error.encoding=UTF-8
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -323,6 +323,10 @@
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<!--排除版本管理警告-->
|
<!--排除版本管理警告-->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
spring.application.name = LuckyFrameClient
|
spring.application.name = LuckyFrameClient
|
||||||
server.port = 6633
|
server.port = 6633
|
||||||
spring.servlet.multipart.max-file-size=30MB
|
spring.servlet.multipart.max-file-size=30MB
|
||||||
spring.servlet.multipart.max-request-size=30MB
|
spring.servlet.multipart.max-request-size=30MB
|
||||||
|
client.config.slat=12331312
|
||||||
|
client.config.pass=123
|
|
@ -52,6 +52,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
|
|
||||||
private static final String SERVER_PORT = SysConfig.getConfiguration().getProperty("server.web.port");
|
private static final String SERVER_PORT = SysConfig.getConfiguration().getProperty("server.web.port");
|
||||||
|
|
||||||
|
public static Integer clientId=-1;
|
||||||
|
|
||||||
private volatile int lastLength = 0;
|
private volatile int lastLength = 0;
|
||||||
|
|
||||||
|
@ -200,7 +201,11 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
||||||
re.put("data", result);
|
re.put("data", result);
|
||||||
sendMessage(re.toString());
|
sendMessage(re.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if("loginReturn".equals(json.get("method")))
|
||||||
|
{
|
||||||
|
//ÉèÖÃclient±ê¼Ç
|
||||||
|
clientId=Integer.valueOf(json.get("clientId").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package luckyclient.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.SecretKeyFactory;
|
||||||
|
import javax.crypto.spec.PBEKeySpec;
|
||||||
|
import javax.crypto.spec.PBEParameterSpec;
|
||||||
|
import java.security.Key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fengjian
|
||||||
|
* @date 2020/6/22 22:17
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class EncryptionUtils {
|
||||||
|
|
||||||
|
private static String salt;
|
||||||
|
|
||||||
|
private static String pass;
|
||||||
|
|
||||||
|
@Value("${client.config.slat}")
|
||||||
|
public void setSalt(String salt) {
|
||||||
|
EncryptionUtils.salt = salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${client.config.pass}")
|
||||||
|
public void setPass(String pass) {
|
||||||
|
EncryptionUtils.pass = pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加密
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String encrypt(String value) throws Exception {
|
||||||
|
// 加密
|
||||||
|
PBEKeySpec pbeKeySpec = new PBEKeySpec(pass.toCharArray());
|
||||||
|
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWITHMD5andDES");
|
||||||
|
Key key = factory.generateSecret(pbeKeySpec);
|
||||||
|
PBEParameterSpec pbeParameterSpec = new PBEParameterSpec(salt.getBytes(),100);
|
||||||
|
Cipher cipher = Cipher.getInstance("PBEWITHMD5andDES");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, key, pbeParameterSpec);
|
||||||
|
byte[] result = cipher.doFinal(value.getBytes());
|
||||||
|
System.out.println("jdk PBE encrypt: " + Base64.encodeBase64String(result));
|
||||||
|
return Base64.encodeBase64String(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String decrypt(String value)throws Exception
|
||||||
|
{
|
||||||
|
// 解密
|
||||||
|
PBEKeySpec pbeKeySpec = new PBEKeySpec(pass.toCharArray());
|
||||||
|
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWITHMD5andDES");
|
||||||
|
PBEParameterSpec pbeParameterSpec = new PBEParameterSpec(salt.getBytes(),100);
|
||||||
|
Cipher cipher = Cipher.getInstance("PBEWITHMD5andDES");
|
||||||
|
Key key = factory.generateSecret(pbeKeySpec);
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, key,pbeParameterSpec);
|
||||||
|
byte[] result = cipher.doFinal(Base64.decodeBase64(value));
|
||||||
|
return new String(result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
import luckyclient.utils.proxy.PropertiesProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化Appium配置参数
|
* 初始化Appium配置参数
|
||||||
|
@ -17,16 +18,18 @@ import luckyclient.utils.LogUtil;
|
||||||
public class AppiumConfig {
|
public class AppiumConfig {
|
||||||
private static final Properties SYS_CONFIG = new Properties();
|
private static final Properties SYS_CONFIG = new Properties();
|
||||||
private static final String SYS_CONFIG_FILE = "/appium_config.properties";
|
private static final String SYS_CONFIG_FILE = "/appium_config.properties";
|
||||||
|
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||||
static{
|
static{
|
||||||
try {
|
try {
|
||||||
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||||
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
|
proxy.setWapper(SYS_CONFIG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
|
LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private AppiumConfig(){}
|
private AppiumConfig(){}
|
||||||
public static Properties getConfiguration(){
|
public static Properties getConfiguration(){
|
||||||
return SYS_CONFIG;
|
return proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import luckyclient.utils.LogUtil;
|
import luckyclient.utils.LogUtil;
|
||||||
|
import luckyclient.utils.proxy.PropertiesProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化数据库驱动配置
|
* 初始化数据库驱动配置
|
||||||
|
@ -21,16 +22,18 @@ import luckyclient.utils.LogUtil;
|
||||||
public class DrivenConfig {
|
public class DrivenConfig {
|
||||||
private static final Properties SYS_CONFIG = new Properties();
|
private static final Properties SYS_CONFIG = new Properties();
|
||||||
private static final String SYS_CONFIG_FILE = "/TestDriven/driven_config.properties";
|
private static final String SYS_CONFIG_FILE = "/TestDriven/driven_config.properties";
|
||||||
|
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||||
static{
|
static{
|
||||||
try {
|
try {
|
||||||
InputStream in = new BufferedInputStream(DrivenConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
InputStream in = new BufferedInputStream(DrivenConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||||
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
|
proxy.setWapper(SYS_CONFIG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.APP.error("读取测试驱动driven_config.properties配置文件出现异常,请检查!", e);
|
LogUtil.APP.error("读取测试驱动driven_config.properties配置文件出现异常,请检查!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private DrivenConfig(){}
|
private DrivenConfig(){}
|
||||||
public static Properties getConfiguration(){
|
public static Properties getConfiguration(){
|
||||||
return SYS_CONFIG;
|
return proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package luckyclient.utils.config;
|
package luckyclient.utils.config;
|
||||||
|
|
||||||
|
import luckyclient.utils.proxy.PropertiesProxy;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -14,16 +16,18 @@ import java.util.Properties;
|
||||||
public class SysConfig {
|
public class SysConfig {
|
||||||
private static final Properties SYS_CONFIG = new Properties();
|
private static final Properties SYS_CONFIG = new Properties();
|
||||||
private static final String SYS_CONFIG_FILE = "/sys_config.properties";
|
private static final String SYS_CONFIG_FILE = "/sys_config.properties";
|
||||||
|
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||||
static{
|
static{
|
||||||
try {
|
try {
|
||||||
InputStream in = new BufferedInputStream(SysConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
InputStream in = new BufferedInputStream(SysConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||||
SYS_CONFIG.load(new InputStreamReader(in, "GBK"));
|
SYS_CONFIG.load(new InputStreamReader(in, "GBK"));
|
||||||
|
proxy.setWapper(SYS_CONFIG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private SysConfig(){}
|
private SysConfig(){}
|
||||||
public static Properties getConfiguration(){
|
public static Properties getConfiguration(){
|
||||||
return SYS_CONFIG;
|
return proxy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package luckyclient.utils.proxy;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import luckyclient.netty.ClientHandler;
|
||||||
|
import luckyclient.utils.EncryptionUtils;
|
||||||
|
import luckyclient.utils.httputils.HttpRequest;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fengjian
|
||||||
|
* @date 2020/6/22 21:26
|
||||||
|
*/
|
||||||
|
public class PropertiesProxy extends Properties {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(PropertiesProxy.class);
|
||||||
|
|
||||||
|
private Properties wapper = new Properties();
|
||||||
|
|
||||||
|
public Properties getWapper() {
|
||||||
|
return wapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWapper(Properties wapper) {
|
||||||
|
this.wapper = wapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProperty(String key) {
|
||||||
|
log.info("get config from service");
|
||||||
|
//获取参数
|
||||||
|
//通过接口获取服务端配置
|
||||||
|
try{
|
||||||
|
String result = HttpRequest.loadJSON("/system/clientConfig/config/"+ ClientHandler.clientId+"/"+key);
|
||||||
|
if(StringUtils.isNotEmpty(result))
|
||||||
|
{
|
||||||
|
JSONObject res=JSONObject.parseObject(result);
|
||||||
|
if(res.get("code")!=null&&res.getInteger("code")==200)
|
||||||
|
{
|
||||||
|
String value= EncryptionUtils.decrypt(res.get("value").toString());
|
||||||
|
log.info("get config from server:"+res.toJSONString()+";value="+value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch (Exception e)
|
||||||
|
{
|
||||||
|
log.info("服务器没有配置:"+key);
|
||||||
|
}
|
||||||
|
return wapper.getProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProperty(String key, String defaultValue) {
|
||||||
|
log.debug("get config from service");
|
||||||
|
//获取参数
|
||||||
|
//通过接口获取服务端配置
|
||||||
|
try{
|
||||||
|
String result = HttpRequest.loadJSON("/system/clientConfig/config/"+ ClientHandler.clientId+"/"+key);
|
||||||
|
if(StringUtils.isNotEmpty(result))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}catch (Exception e)
|
||||||
|
{
|
||||||
|
log.debug("服务器没有配置:"+key);
|
||||||
|
}
|
||||||
|
return wapper.getProperty(key, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import cn.hutool.core.util.BooleanUtil;
|
import cn.hutool.core.util.BooleanUtil;
|
||||||
import luckyclient.netty.NettyClient;
|
import luckyclient.netty.NettyClient;
|
||||||
import luckyclient.utils.config.SysConfig;
|
import luckyclient.utils.config.SysConfig;
|
||||||
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =================================================================
|
* =================================================================
|
||||||
|
@ -32,7 +33,7 @@ public class RunService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(RunService.class);
|
private static final Logger log = LoggerFactory.getLogger(RunService.class);
|
||||||
private static final Boolean NETTY_MODEL= BooleanUtil.toBoolean(SysConfig.getConfiguration().getProperty("netty.model"));
|
private static final Boolean NETTY_MODEL= BooleanUtil.toBoolean(SysConfig.getConfiguration().getProperty("netty.model"));
|
||||||
public static String CLIENT_IP = "";
|
public static String CLIENT_IP = "";
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator +"bootlog4j.conf");
|
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator +"bootlog4j.conf");
|
||||||
SpringApplication.run(RunService.class, args);
|
SpringApplication.run(RunService.class, args);
|
||||||
|
@ -53,6 +54,8 @@ public class RunService {
|
||||||
}else{
|
}else{
|
||||||
HttpImpl.checkHostNet();
|
HttpImpl.checkHostNet();
|
||||||
}
|
}
|
||||||
|
Thread.sleep(5000);
|
||||||
|
SysConfig.getConfiguration().getProperty("appid");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue