fix bug
This commit is contained in:
parent
6949bd4b21
commit
6ad20cd905
@ -14,11 +14,10 @@ import java.util.List;
|
|||||||
* 上海黄金交易所 - 数据库加密方案
|
* 上海黄金交易所 - 数据库加密方案
|
||||||
*/
|
*/
|
||||||
public class SydApi4Database implements SydApi {
|
public class SydApi4Database implements SydApi {
|
||||||
Logger log = LogFactory.getLogger();
|
|
||||||
private SydApi4j[] hsms = null;
|
private SydApi4j[] hsms = null;
|
||||||
private boolean isShortLinkMode = false;
|
private boolean isShortLinkMode = false;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public SydApi4Database() {
|
public SydApi4Database() {
|
||||||
isShortLinkMode = true;
|
isShortLinkMode = true;
|
||||||
}
|
}
|
||||||
@ -29,21 +28,31 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
public SydApi SYD_Short_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, iDealTimeOut);
|
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, iDealTimeOut);
|
||||||
}
|
}
|
||||||
if (iPortList==null||iPortList.length==0){
|
|
||||||
throw new SydApiException("没有ip地址",-1);
|
if (pcIpList.length!=iPortList.length) {
|
||||||
}
|
throw new IllegalArgumentException("ip与端口数量不一致");
|
||||||
if (iPortList.length!=iPortList.length) {
|
|
||||||
throw new SydApiException("ip与端口号数量不一致",-1);
|
|
||||||
}
|
|
||||||
SydApi4j api = null;
|
|
||||||
for (int i = 0; i < pcIpList.length ; i++) {
|
|
||||||
api = (SydApi4j) new SydApi4j().connect(pcIpList[i], iPortList[i], null, iConnectTimeOut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hsms = new SydApi4j[]{api};
|
SydApi4j[] apis = new SydApi4j[pcIpList.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < pcIpList.length ; i++) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
apis[i] = (SydApi4j) new SydApi4j().connect(pcIpList[i], iPortList[i], null, iConnectTimeOut);
|
||||||
|
|
||||||
|
}catch ( Exception e) {
|
||||||
|
// 忽略错误
|
||||||
|
log.error("网络连接错误 {} {} - 忽略",pcIpList[i], iPortList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
hsms = apis;
|
||||||
isShortLinkMode = true;
|
isShortLinkMode = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -54,25 +63,24 @@ public class SydApi4Database implements SydApi {
|
|||||||
if ( null == hsms ){
|
if ( null == hsms ){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SydApi4j api = null;
|
|
||||||
for (int i = 0; i < hsms.length; i++) {
|
for (int i = 0; i < hsms.length; i++) {
|
||||||
api = hsms[i];
|
SydApi4j api = hsms[i];
|
||||||
if (null != api) {
|
if (null != api) {
|
||||||
try {
|
try {
|
||||||
api.disconnect();
|
api.disconnect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api = null;
|
|
||||||
}
|
}
|
||||||
// 配合链接池,不再需要释放。
|
// 配合链接池,不再需要释放。
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM3_Hash_ShortData方法接收参数:pcData:{}", Arrays.toString(pcData));
|
log.debug("SYD_SM3_Hash_ShortData方法接收参数:pcData:{}", Arrays.toString(pcData));
|
||||||
}
|
}
|
||||||
@ -99,6 +107,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM3_Hash_LongData方法接收参数:pcData:{},iPkgNum:{},pcProcData:{}", Arrays.toString(pcData), iPkgNum, pcProcData);
|
log.debug("SYD_SM3_Hash_LongData方法接收参数:pcData:{},iPkgNum:{},pcProcData:{}", Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||||
}
|
}
|
||||||
@ -136,6 +145,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iFlag);
|
log.debug("SYD_SM4_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iFlag);
|
||||||
}
|
}
|
||||||
@ -177,6 +187,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
||||||
}
|
}
|
||||||
@ -218,6 +229,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
||||||
}
|
}
|
||||||
@ -261,6 +273,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
||||||
}
|
}
|
||||||
@ -298,6 +311,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
||||||
}
|
}
|
||||||
@ -335,6 +349,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData);
|
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||||
}
|
}
|
||||||
@ -385,6 +400,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
||||||
}
|
}
|
||||||
@ -401,6 +417,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData));
|
log.debug("SYD_SM4Mac_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData));
|
||||||
}
|
}
|
||||||
@ -429,6 +446,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
if (LogFactory.iLogLevel==3) {
|
if (LogFactory.iLogLevel==3) {
|
||||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:{}", iKeyIndex, Arrays.toString(pcData), pcMac);
|
log.debug("SYD_SM4Mac_ShortData方法接收参数:{}", iKeyIndex, Arrays.toString(pcData), pcMac);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class SydApiBuilder {
|
|||||||
SydApi api = null;
|
SydApi api = null;
|
||||||
try {
|
try {
|
||||||
api = new SydApi4Database();
|
api = new SydApi4Database();
|
||||||
api.SYD_Connect_Ex( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
api.SYD_Short_Connect_Ex( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ public class SydApiBuilder {
|
|||||||
|
|
||||||
}catch ( Exception e) {
|
}catch ( Exception e) {
|
||||||
// 忽略
|
// 忽略
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -2,7 +2,9 @@ package com.sunyard.sge.database.pool;
|
|||||||
|
|
||||||
import com.sunyard.sge.database.SydApi;
|
import com.sunyard.sge.database.SydApi;
|
||||||
import com.sunyard.sge.database.SydApi4Database;
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
|
import com.sunyard.sge.log.LogFactory;
|
||||||
import com.sunyard.sge.pool.ThreadBasedConnectPool;
|
import com.sunyard.sge.pool.ThreadBasedConnectPool;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import racal.sunyard.main.SydApi4j;
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
||||||
@ -33,7 +35,9 @@ public class SydApiPool extends ThreadBasedConnectPool<SydApi> {
|
|||||||
);
|
);
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
// 忽略单个错误
|
// 忽略单个错误
|
||||||
|
log.error("网络连接错误 {} {} - 忽略",info.getPcIp(),info.getiPort());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
src/test/java/sample/ShortLinkSample.java
Normal file
25
src/test/java/sample/ShortLinkSample.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package sample;
|
||||||
|
|
||||||
|
import com.sunyard.sge.database.SydApi;
|
||||||
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
|
|
||||||
|
public class ShortLinkSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// 路径要以 / 或 \\ 结尾表示目录
|
||||||
|
SydApi.SYD_SetLogConfig("./logs/",3);
|
||||||
|
|
||||||
|
String[] pcipList = {"127.0.0.1", "192.168.0.200" };
|
||||||
|
int[] iportList ={8080,8889};
|
||||||
|
SydApi api = new SydApi4Database();
|
||||||
|
try {
|
||||||
|
api.SYD_Short_Connect_Ex(pcipList,iportList,10,10);
|
||||||
|
} finally {
|
||||||
|
if ( null != api ) {
|
||||||
|
api.SYD_Disconnect_Ex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
|
import com.sunyard.sge.database.Consts;
|
||||||
import com.sunyard.sge.database.SydApi;
|
import com.sunyard.sge.database.SydApi;
|
||||||
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
import com.sunyard.sge.database.SydApiBuilder;
|
import com.sunyard.sge.database.SydApiBuilder;
|
||||||
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
||||||
import com.sunyard.sge.database.pool.SydApiPool;
|
import com.sunyard.sge.database.pool.SydApiPool;
|
||||||
|
import com.sunyard.sge.log.LogFactory;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -23,6 +27,21 @@ public class FuncTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void syd_Short_Connect_Ex(){
|
||||||
|
String[] pcipList = {"127.0.0.1", "192.168.0.200" };
|
||||||
|
int[] iportList ={8080,8889};
|
||||||
|
SydApi api = new SydApi4Database();
|
||||||
|
try {
|
||||||
|
api.SYD_Short_Connect_Ex(pcipList,iportList,10,10);
|
||||||
|
} finally {
|
||||||
|
if ( null != api ) {
|
||||||
|
api.SYD_Disconnect_Ex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sm3(){
|
public void sm3(){
|
||||||
SydApiBuilder builder = new SydApiBuilder(
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
@ -35,4 +54,23 @@ public class FuncTest {
|
|||||||
api = builder.build();
|
api = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void origin() throws Exception {
|
||||||
|
SydApiBuilder builder = new SydApiBuilder(new String[]{"192.168.0.200"}, new int[]{8889}, 10, 15);
|
||||||
|
SydApi.SYD_SetLogConfig("./logs/",3);
|
||||||
|
Logger log = LogFactory.getLogger();
|
||||||
|
final SydApi api = builder.build();
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
int tmp = i;
|
||||||
|
new Thread(() -> {
|
||||||
|
for (int j = 0; j < 20; j++) {
|
||||||
|
byte[] bytes = api.SYD_SM4_ShortData(0, (tmp + "t" + j).getBytes(), Consts.ECB_ENC);
|
||||||
|
byte[] result = api.SYD_SM4_ShortData(0, bytes, Consts.ECB_DEC);
|
||||||
|
System.out.println(Thread.currentThread().getName() + "," + new String(result));
|
||||||
|
}
|
||||||
|
}, i + "t").start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,5 +14,6 @@ public class LogTest {
|
|||||||
log.error("error");
|
log.error("error");
|
||||||
log.info("info");
|
log.info("info");
|
||||||
log.debug("debug");
|
log.debug("debug");
|
||||||
|
System.out.println(new byte[0].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class PrefTest
|
|||||||
final SydApi api = new SydApi4Database();
|
final SydApi api = new SydApi4Database();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
api.SYD_Connect_Ex(
|
api.SYD_Short_Connect_Ex(
|
||||||
new String[]{ "192.168.0.200" },
|
new String[]{ "192.168.0.200" },
|
||||||
new int[]{ 8889 },
|
new int[]{ 8889 },
|
||||||
10,
|
10,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user