
com.starmcc.qmframework.config.QmFrameConstants Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qm-framework Show documentation
Show all versions of qm-framework Show documentation
springboot based on a series of packaging framework.
QmFramework to implements AOP,
rewrite the requestBody,
global exception catching,version checking,
request body parameter symmetric encryption mechanism,
controller packaging and the toolkit collection.
thank you for using it.
package com.starmcc.qmframework.config;
import com.starmcc.qmframework.exception.QmFrameException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* qmframework配置常量类
*
* @Author qm
* @Date 2019/1/30 19:36
*/
public class QmFrameConstants {
/**
* 定义文件名
*/
private static final String FILE_NAME = "qm-application.properties";
/**
* 获取Properties
*/
private static final Properties PRO = getProperties(FILE_NAME);
/**
* 是否启用AES对称加密传输
*/
public static final boolean AES_START =
getProBoolean("aes.start", false);
/**
* AES秘钥
*/
public static final String AES_KEY =
getProString("aes.key", "20190101000000QmBootFrame");
/**
* 统一使用的编码方式
*/
public static final String AES_ENCODING =
getProString("aes.encoding", "UTF-8");
/**
* 加密次数
*/
public static final int AES_NUMBER =
getProInt("aes.number", 1);
/**
* 请求数据时,根据该key名解析数据(rest风格)
*/
public static final String REQUEST_DATA_KEY =
getProString("body.request.key", "value");
/**
* 返回数据时,使用的最外层key名(rest风格)
*/
public static final String RESPONSE_DATA_KEY =
getProString("body.response.key", "value");
public static final String RESPONSE_MESSAGE_LANG =
getProString("body.response.message.lang", "en");
/**
* 特殊请求不进行解析(包括版本控制和解析json等)
*/
public static final List REQUEST_SPECIAL_URI = getRequestSpecialUri();
/**
* 是否开启版本控制(ture时,每个请求需在header带上version参数,参数值version)
*/
public static final boolean VERSION_START =
getProBoolean("version.start", false);
/**
* 系统目前版本编号
*/
public static final String VERSION_NOW =
getProString("version.now", "0.0.1");
/**
* 系统容忍请求版本编号(默认允许当前版本)
*/
public static final List VERSION_ALLOWS = getVersionAllows();
/**
* 获取特殊请求
*
* @return
*/
private static final List getRequestSpecialUri() {
List specialUriList = new ArrayList<>();
boolean is = true;
int num = 0;
while (is) {
String tempVersion = PRO.getProperty("request.special.uri-[" + num + "]", null);
if (tempVersion != null) {
specialUriList.add(tempVersion);
} else {
is = false;
}
num++;
}
return specialUriList;
}
public static final boolean getProBoolean(String key) {
return Boolean.parseBoolean(PRO.getProperty(key, "false"));
}
public static final boolean getProBoolean(String key, boolean defaultVal) {
return Boolean.parseBoolean(PRO.getProperty(key, String.valueOf(defaultVal)));
}
public static final int getProInt(String key) {
return Integer.parseInt(PRO.getProperty(key, "0"));
}
public static final int getProInt(String key, int defaultVal) {
return Integer.parseInt(PRO.getProperty(key, String.valueOf(defaultVal)));
}
public static final String getProString(String key) {
return PRO.getProperty(key);
}
public static final String getProString(String key, String defaultVal) {
return PRO.getProperty(key, defaultVal);
}
/**
* 获取允许版本号
*
* @return
*/
private static final List getVersionAllows() {
List allows = new ArrayList<>();
boolean is = true;
int num = 0;
while (is) {
String tempVersion = PRO.getProperty("version.allows-[" + num + "]", null);
if (tempVersion != null) {
allows.add(tempVersion);
} else {
is = false;
}
num++;
}
return allows;
}
private static final Properties getProperties(String fileName) {
try {
Properties properties = new Properties();
// 读取properties文件,使用InputStreamReader字符流防止文件中出现中文导致乱码
InputStreamReader inStream = new InputStreamReader(
QmFrameConstants.class.getClassLoader().getResourceAsStream(fileName),
"UTF-8");
properties.load(inStream);
inStream.close();
return properties;
} catch (Exception e) {
throw new QmFrameException("读取" + fileName + "发生了异常!", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy