fix too RejectedExecutionException of ServiceServer.executor

This commit is contained in:
CaiHQ 2022-07-14 22:23:31 +08:00
parent e336865cc1
commit 0aac9d16d9
3 changed files with 26 additions and 5 deletions

View File

@ -53,9 +53,10 @@ public class ComponedContractResult {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
String str = null;
cr2 = cr2 =
new ContractResult( new ContractResult(
ContractResult.Status.Error, new JsonPrimitive("parse str failed:")); ContractResult.Status.Error, new JsonPrimitive("parse str failed:" + obj.toString()));
e.printStackTrace(); e.printStackTrace();
} }
// if (cr2.status == ContractResult.Status.Error) { // 结果不是Success不参与最终结果计算 // if (cr2.status == ContractResult.Status.Error) { // 结果不是Success不参与最终结果计算

View File

@ -25,7 +25,7 @@ public class ServiceServer extends Thread {
public static final ExecutorService executor = public static final ExecutorService executor =
new ThreadPoolExecutor( new ThreadPoolExecutor(
8, 8,
15, Integer.MAX_VALUE,
60, 60,
TimeUnit.SECONDS, TimeUnit.SECONDS,
new SynchronousQueue<>()); new SynchronousQueue<>());

View File

@ -19,8 +19,9 @@ public class SM2UtilTest {
String keyPairStr = String keyPairStr =
"{\"publicKey\":\"0442e39c0b1623e6f95ef896d37f41aa3cd98fbc3aea71250eedba4335c6c3aff51b5fa2352f920d1063b50a30738427c18375df886985a63e0f496293fdad22a8\",\"privateKey\":\"b7e504cf951792554bf4a9874be37cb1279d38939444388e2046ee9603b4f0c4\"}"; "{\"publicKey\":\"0442e39c0b1623e6f95ef896d37f41aa3cd98fbc3aea71250eedba4335c6c3aff51b5fa2352f920d1063b50a30738427c18375df886985a63e0f496293fdad22a8\",\"privateKey\":\"b7e504cf951792554bf4a9874be37cb1279d38939444388e2046ee9603b4f0c4\"}";
SM2KeyPair keyPair = SM2KeyPair.fromJson(keyPairStr); SM2KeyPair keyPair = SM2KeyPair.fromJson(keyPairStr);
@Test @Test
public void verify2(){ public void verify2() {
String toVerify = "GeneralContract|plainTextTransmission|{\"ledger\":\"test\",\"data\":\"上链信息为json格式\"}|04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15"; String toVerify = "GeneralContract|plainTextTransmission|{\"ledger\":\"test\",\"data\":\"上链信息为json格式\"}|04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15";
String sign = "30440220137771d7505abde700c89cfa376f67c564dfdec6ffdb08cb08ff70544be6cb6f0220587296439bedf43f4b0bfec2d7030a8250d369e53af623e50a734e3b6cb780cb"; String sign = "30440220137771d7505abde700c89cfa376f67c564dfdec6ffdb08cb08ff70544be6cb6f0220587296439bedf43f4b0bfec2d7030a8250d369e53af623e50a734e3b6cb780cb";
String pubkey = "04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15"; String pubkey = "04398dfde44290595cd098cd2f904b36367c69f9011719d43fb0955f823cf1386764769bc7c0a5649dcb316d552998a5c106afd268d9db8b6482ce527544a7bd15";
@ -33,13 +34,14 @@ public class SM2UtilTest {
System.out.println(cr.verifySignature()); System.out.println(cr.verifySignature());
} }
@Test @Test
public void base64() { public void base64() {
String gstr = String gstr =
"09146332716e7767327923056946406e49570e5909146332716e7767327923056946406e49570e59"; "09146332716e7767327923056946406e49570e5909146332716e7767327923056946406e49570e59";
byte[] bytes = ByteUtils.fromHexString(gstr); byte[] bytes = ByteUtils.fromHexString(gstr);
// String str = new BASE64Encoder().encode(bytes); // String str = new BASE64Encoder().encode(bytes);
// System.out.println(str); // System.out.println(str);
} }
@Test @Test
@ -128,6 +130,24 @@ public class SM2UtilTest {
} }
@Test
public void dosignTest() throws Exception {
String tosign = "action=startContract&script=contract%20shortc%7B%0A%09export%20function%20main(arg)%7B%0A%09%09return%20arg.length%3B%09%0A%09%7D%0A%7D&pubKey=041a3875bb1a8d6acfc1142c60e3cc7c11831d4878c6dbbf9bb0929716d6cf402492b9629a4ced9198ae2c419f8d3d6ae810a431458d38901e5597636b715584d4";
// keyPair = SM2KeyPair.fromJson("{\"privateKey\":\"94728f3d95f19b3b5b11a31fdb603b5b2e8b377d9520d0680ac4f270cc82ec51\",\"publicKey\":\"041a3875bb1a8d6acfc1142c60e3cc7c11831d4878c6dbbf9bb0929716d6cf402492b9629a4ced9198ae2c419f8d3d6ae810a431458d38901e5597636b715584d4\"}");
keyPair = SM2KeyPair.fromJson("{\"privateKey\":\"589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8\",\"publicKey\":\"04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd\"}");
String signature = ByteUtils.toHexString(
SM2Util.sign(
keyPair.getPrivateKeyParameter(), tosign.getBytes()));
System.out.println(signature);
ECPublicKeyParameters pubKey =
BCECUtil.createECPublicKeyFromStrParameters(
keyPair.getPublicKeyStr(), SM2Util.CURVE, SM2Util.DOMAIN_PARAMS);
boolean verify = SM2Util.verify(
pubKey, tosign.getBytes(), ByteUtils.fromHexString(signature));
System.out.println(verify);
}
// Deprecated // Deprecated
// @Test // @Test
// public void signAtServer() { // public void signAtServer() {