修改短链接、修改日志
This commit is contained in:
parent
719388494b
commit
004e6451ee
@ -14,7 +14,11 @@ import java.util.List;
|
||||
* 上海黄金交易所 - 数据库加密方案
|
||||
*/
|
||||
public class SydApi4Database implements SydApi {
|
||||
static Logger log = LogFactory.getLogger();
|
||||
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
|
||||
private SydApi4j[] hsms = null;
|
||||
private boolean isShortLinkMode = false;
|
||||
|
||||
@ -28,37 +32,36 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int allDealTimeOut) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, allDealTimeOut);
|
||||
}
|
||||
|
||||
if (pcIpList.length!=iPortList.length) {
|
||||
if (pcIpList.length != iPortList.length) {
|
||||
throw new IllegalArgumentException("ip与端口数量不一致");
|
||||
}
|
||||
|
||||
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
||||
int iDealTimeOut = allDealTimeOut / pcIpList.length;
|
||||
boolean connected = false;
|
||||
for (int i = 0; i < pcIpList.length ; i++) {
|
||||
for (int i = 0; i < pcIpList.length; i++) {
|
||||
|
||||
try {
|
||||
|
||||
apis[i] = (SydApi4j) new SydApi4j().connect(pcIpList[i], iPortList[i], null, iConnectTimeOut, iDealTimeOut);
|
||||
connected = true;
|
||||
}
|
||||
catch ( Exception e) {
|
||||
} catch (Exception e) {
|
||||
// 忽略错误
|
||||
log.error("网络连接错误 {} {} - 忽略",pcIpList[i], iPortList[i]);
|
||||
log.error("网络连接错误 {} {} - 忽略", pcIpList[i], iPortList[i]);
|
||||
}
|
||||
|
||||
}
|
||||
if( ! connected ) {
|
||||
if (!connected) {
|
||||
// TODO
|
||||
throw new SydApiException("连接错误",-1);
|
||||
throw new SydApiException("连接错误", -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
hsms = apis;
|
||||
isShortLinkMode = true;
|
||||
return this;
|
||||
@ -67,7 +70,7 @@ public class SydApi4Database implements SydApi {
|
||||
@Override
|
||||
public void SYD_Disconnect_Ex() {
|
||||
if (isShortLinkMode) {
|
||||
if ( null == hsms ){
|
||||
if (null == hsms) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -89,7 +92,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM3_Hash_ShortData方法接收参数:pcData:{}", Arrays.toString(pcData));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -99,13 +103,13 @@ public class SydApi4Database implements SydApi {
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] hash = api.SYD_SM3_LongData(pcData, null, 0);
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}", Arrays.toString(hash));
|
||||
return Util.bytes2HexString(hash);
|
||||
} catch (SydApiException e) {
|
||||
le = e;
|
||||
@ -120,7 +124,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM3_Hash_LongData方法接收参数:pcData:{},iPkgNum:{},pcProcData:{}", Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||
}
|
||||
|
||||
@ -131,17 +136,17 @@ public class SydApi4Database implements SydApi {
|
||||
byte[] procData = null;
|
||||
if (2 == iPkgNum || 3 == iPkgNum) {
|
||||
procData = Util.hexString2Bytes(pcProcData);
|
||||
log.debug("Util.hexString2Bytes方法返回值:{}",Arrays.toString(procData));
|
||||
log.debug("Util.hexString2Bytes方法返回值:{}", Arrays.toString(procData));
|
||||
|
||||
}
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}", Arrays.toString(hash));
|
||||
if (0 == iPkgNum || 3 == iPkgNum) {
|
||||
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
|
||||
} else {
|
||||
@ -160,10 +165,11 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iFlag);
|
||||
}
|
||||
if (iFlag==Consts.ECB_DEC && null==pcData||pcData.length==0){
|
||||
if (iFlag == Consts.ECB_DEC && null == pcData || pcData.length == 0) {
|
||||
throw new SydApiException(19);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -173,7 +179,7 @@ public class SydApi4Database implements SydApi {
|
||||
String keyIndex = String.format("%08d", iKeyIndex);
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -203,12 +209,13 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
||||
}
|
||||
if (iFlag==Consts.ECB_DEC){
|
||||
for (byte[] pcdata:pcData){
|
||||
if (null==pcData||pcdata.length==0) {
|
||||
if (iFlag == Consts.ECB_DEC) {
|
||||
for (byte[] pcdata : pcData) {
|
||||
if (null == pcData || pcdata.length == 0) {
|
||||
throw new SydApiException(19);
|
||||
}
|
||||
}
|
||||
@ -224,7 +231,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -247,10 +254,11 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
||||
}
|
||||
if (iFlag==Consts.ECB_DEC&&null==pcData||pcData.length==0){
|
||||
if (iFlag == Consts.ECB_DEC && null == pcData || pcData.length == 0) {
|
||||
throw new SydApiException(19);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -260,7 +268,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -293,7 +301,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -306,7 +315,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -333,7 +342,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -346,7 +356,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -373,7 +383,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -391,7 +402,7 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -416,6 +427,7 @@ public class SydApi4Database implements SydApi {
|
||||
} catch (SydApiException e) {
|
||||
le = e;
|
||||
if (e.getRetCode() < 0) {
|
||||
log.error("HA 重试");
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
@ -426,7 +438,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
||||
}
|
||||
LongDataReturn<String, String> ret = SYD_SM4Mac_LongData(iKeyIndex, pcData, iPkgNum, pcProcData);
|
||||
@ -442,7 +455,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -450,10 +464,10 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String keyIndex = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex));
|
||||
log.debug("\"SK\" + SYMUtil.genPrivateKeyMark方法返回值:{}",keyIndex);
|
||||
log.debug("\"SK\" + SYMUtil.genPrivateKeyMark方法返回值:{}", keyIndex);
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
if ( null == api ) {
|
||||
if (null == api) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@ -473,7 +487,8 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:{}", iKeyIndex, Arrays.toString(pcData), pcMac);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
@ -485,7 +500,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData);
|
||||
log.debug(this+".SYD_SM4Mac_ShortData方法返回值:{}",mac);
|
||||
log.debug(this + ".SYD_SM4Mac_ShortData方法返回值:{}", mac);
|
||||
return pcMac.equals(mac);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SydApiBuilder {
|
||||
Logger log = LogFactory.getLogger();
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
private SydApiPool pool;
|
||||
public SydApiBuilder(
|
||||
String[] pcIpList,
|
||||
@ -16,6 +18,7 @@ public class SydApiBuilder {
|
||||
int iConnectTimeOut,
|
||||
int iDealTimeOut
|
||||
) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
log.debug("创建链接");
|
||||
log.debug("SydApiBuilder构造方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iDealTimeOut);
|
||||
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.sunyard.sge.database.pool;
|
||||
|
||||
|
||||
import com.sunyard.sge.database.SydApi;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -11,6 +12,10 @@ import java.util.Arrays;
|
||||
* 到加密机的链接信息
|
||||
*/
|
||||
public class HsmLinkInfo {
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
static Logger log = LogFactory.getLogger();
|
||||
private String pcIp;
|
||||
private int iPort;
|
||||
private int iConnectTimeOut;
|
||||
@ -25,7 +30,7 @@ public class HsmLinkInfo {
|
||||
}
|
||||
|
||||
public static HsmLinkInfo[] mutiHsmLinkInfo(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iAllDealTimeOut) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
|
||||
log.debug("mutiHsmLinkInfo方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iAllDealTimeOut);
|
||||
log.debug("链接参数整理");
|
||||
if (null == pcIpList &&
|
||||
|
||||
@ -9,6 +9,9 @@ import org.apache.logging.log4j.Logger;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
|
||||
private HsmLinkInfo[] linkInfos;
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ public class LogFactory {
|
||||
|
||||
// 日志打印方式——输出为文件
|
||||
Appender appender = FileAppender.createAppender(
|
||||
String.format( pcLogPath + getToday() + ".log"),
|
||||
String.format( pcLogPath +"sydapi_"+getToday() + ".log"),
|
||||
"true", "false",
|
||||
logName, null, "true", "true", null, layout, null, null, null, config);
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.sunyard.sge.pool;
|
||||
|
||||
import com.sunyard.sge.database.SydApi;
|
||||
import com.sunyard.sge.database.SydApi4Database;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -12,7 +14,9 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ThreadBasedConnectPool<T> {
|
||||
|
||||
static {
|
||||
SydApi.SYD_SetLogConfig("./logs/", 0);
|
||||
}
|
||||
|
||||
// ThreadLocal
|
||||
private final Map<Thread, ObjectInPool<T>> map = new HashMap<>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user