importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.util.Properties;importorg.apache.commons.lang3.StringUtils;importorg.apache.commons.logging.Log;importorg.apache.commons.logging.LogFactory;public final classAppConfig {private static final Log logger = LogFactory.getLog(AppConfig.class);private static final String FILE_NAME = "xwcg.properties";private static AppConfig sdkConfig = null;/*** 网关请求地址*/
privateString xwcgGatewayUrl;/*** 存管直连地址*/
privateString xwcgServiceUrl;/***存管对账文件下载地址*/
privateString xwcgDownloadUrl;/*** 平台编号*/
privateString platformNo;/*** 证书编号*/
privateString keySerial;/*** 平台私钥*/
privateString privateKey;/*** 平台公钥*/
privateString publicKey;/*** 私钥*/
privateString lmPrivateKey;/*** 公钥*/
privateString lmPublicKey;/*** 连接超时*/
private intconnectionTimeout;/*** 获取数据超时*/
private intreadTimeout;privateAppConfig() {this.loadPropertiesFromSrc();
}public staticAppConfig getConfig() {synchronized (AppConfig.class) {if (null ==sdkConfig) {
sdkConfig= newAppConfig();
}returnsdkConfig;
}
}private voidloadPropertiesFromSrc() {
InputStream in= null;try{
Properties properties= null;
logger.info("从classpath: "+ AppConfig.class.getClassLoader().getResource("").getPath() + " 获取属性文件" +FILE_NAME);
in= AppConfig.class.getClassLoader().getResourceAsStream(FILE_NAME);if (null !=in) {
BufferedReader bf= new BufferedReader(new InputStreamReader(in, "utf-8"));
properties= newProperties();try{
properties.load(bf);
}catch(IOException e) {throwe;
}
}else{
logger.error(FILE_NAME+ "属性文件未能在classpath指定的目录下 "+ AppConfig.class.getClassLoader().getResource("").getPath() + " 找到!");return;
}
loadProperties(properties);
}catch(IOException e) {
e.printStackTrace();
}finally{if (null !=in) {try{
in.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
}/*** 根据传入的properties对象设置配置参数
*
*@parampro*/
private voidloadProperties(Properties pro) {
logger.info("开始从属性文件中加载配置项");
String value= null;
value= pro.getProperty("xwcgGatewayUrl");if (!StringUtils.isEmpty(value)) {this.xwcgGatewayUrl =value.trim();
}
value= pro.getProperty("xwcgServiceUrl");if (!StringUtils.isEmpty(value)) {this.xwcgServiceUrl =value.trim();
}
value= pro.getProperty("xwcgDownloadUrl");if (!StringUtils.isEmpty(value)) {this.xwcgDownloadUrl =value.trim();
}
value= pro.getProperty("platformNo");if (!StringUtils.isEmpty(value)) {this.platformNo =value.trim();
}
value= pro.getProperty("keySerial");if (!StringUtils.isEmpty(value)) {this.keySerial =value.trim();
}
value= pro.getProperty("privateKey");if (!StringUtils.isEmpty(value)) {this.privateKey =value.trim();
}
value= pro.getProperty("publicKey");if (!StringUtils.isEmpty(value)) {this.publicKey =value.trim();
}
value= pro.getProperty("lmPrivateKey");if (!StringUtils.isEmpty(value)) {this.lmPrivateKey =value.trim();
}
value= pro.getProperty("lmPublicKey");if (!StringUtils.isEmpty(value)) {this.lmPublicKey =value.trim();
}
value= pro.getProperty("connectionTimeout");if (!StringUtils.isEmpty(value)) {this.connectionTimeout =Integer.valueOf(value.trim());
}
value= pro.getProperty("readTimeout");if (!StringUtils.isEmpty(value)) {this.readTimeout =Integer.valueOf(value.trim());
}
}publicString getXwcgGatewayUrl() {returnxwcgGatewayUrl;
}public voidsetXwcgGatewayUrl(String xwcgGatewayUrl) {this.xwcgGatewayUrl =xwcgGatewayUrl;
}publicString getXwcgServiceUrl() {returnxwcgServiceUrl;
}public voidsetXwcgServiceUrl(String xwcgServiceUrl) {this.xwcgServiceUrl =xwcgServiceUrl;
}publicString getXwcgDownloadUrl() {returnxwcgDownloadUrl;
}public voidsetXwcgDownloadUrl(String xwcgDownloadUrl) {this.xwcgDownloadUrl =xwcgDownloadUrl;
}publicString getPlatformNo() {returnplatformNo;
}public voidsetPlatformNo(String platformNo) {this.platformNo =platformNo;
}publicString getKeySerial() {returnkeySerial;
}public voidsetKeySerial(String keySerial) {this.keySerial =keySerial;
}publicString getPrivateKey() {returnprivateKey;
}public voidsetPrivateKey(String privateKey) {this.privateKey =privateKey;
}public intgetConnectionTimeout() {returnconnectionTimeout;
}public void setConnectionTimeout(intconnectionTimeout) {this.connectionTimeout =connectionTimeout;
}public intgetReadTimeout() {returnreadTimeout;
}public void setReadTimeout(intreadTimeout) {this.readTimeout =readTimeout;
}publicString getPublicKey() {returnpublicKey;
}public voidsetPublicKey(String publicKey) {this.publicKey =publicKey;
}publicString getLmPrivateKey() {returnlmPrivateKey;
}public voidsetLmPrivateKey(String lmPrivateKey) {this.lmPrivateKey =lmPrivateKey;
}publicString getLmPublicKey() {returnlmPublicKey;
}public voidsetLmPublicKey(String lmPublicKey) {this.lmPublicKey =lmPublicKey;
}
}