diff --git a/Changelog.md b/Changelog.md index 8362fb84f..a74f7e69f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,18 @@ +### v1.3.2(2020-06-17) + +**Fix** +- 移除Fastjson,替换为Jackson 2.11.0; web3sdk升级为2.4.1 +- 升级依赖包:spring: 5.1.15; log4j: 2.13.3; slf4j: 1.7.30; netty-all: 4.1.44+; guava: 28.2; + +**兼容性** +- 支持FISCO-BCOS v2.4.0 及以上版本 +- WeBASE-Web v1.3.1+ +- WeBASE-Front v1.3.1+ +- WeBASE-Sign v1.3.1+ +- WeBASE-Transaction v1.3.0+ + +详细了解,请阅读[**技术文档**](https://webasedoc.readthedocs.io/zh_CN/latest/)。 + ### v1.3.1(2020-06-01) **Add** diff --git a/build.gradle b/build.gradle index 9695a898a..e425c2e8a 100644 --- a/build.gradle +++ b/build.gradle @@ -17,20 +17,28 @@ repositories { maven {url "http://maven.aliyun.com/nexus/content/groups/public/"} maven { url 'https://dl.bintray.com/ethereum/maven/' } + maven { url "https://oss.sonatype.org/content/repositories/snapshots" } + mavenLocal() mavenCentral() } -def springboot_version="2.1.2.RELEASE" +def springboot_version="2.1.15.RELEASE" List springboot = [ "org.springframework.boot:spring-boot-starter-web:$springboot_version", - "org.springframework.boot:spring-boot-starter-log4j2:$springboot_version", "org.springframework.boot:spring-boot-starter-security:$springboot_version", "org.springframework.boot:spring-boot-starter-mail:$springboot_version", "org.springframework.boot:spring-boot-starter-thymeleaf:$springboot_version" // "org.springframework.boot:spring-boot-starter-aop:$springboot_version" ] +// cover old version +def spring_version="5.1.15.RELEASE" +List spring =[ + "org.springframework:spring-jdbc:$spring_version", + "org.springframework:spring-tx:$spring_version" +] + List jaxb = [ "javax.xml.bind:jaxb-api:2.3.0", "com.sun.xml.bind:jaxb-impl:2.3.0", @@ -38,36 +46,47 @@ List jaxb = [ "javax.activation:activation:1.1.1" ] -List web3jsdk = [ - "org.fisco-bcos:web3sdk:2.4.0" +List web3sdk = [ + "org.fisco-bcos:web3sdk:2.4.1" ] List lombok = [ - "org.projectlombok:lombok:1.18.2" ] +def jackson_version = "2.11.0" List jackson = [ - "com.fasterxml.jackson.core:jackson-databind:2.10.0", - "com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.0", - "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.0", - "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.0" + "com.fasterxml.jackson.core:jackson-databind:$jackson_version", + "com.fasterxml.jackson.core:jackson-annotations:$jackson_version", + "com.fasterxml.jackson.core:jackson-core:$jackson_version", + "com.fasterxml.jackson.module:jackson-module-parameter-names:$jackson_version", + "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jackson_version", + "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version", ] List test = [ "org.springframework.boot:spring-boot-starter-test:$springboot_version" ] +def log4j_version="2.13.3" +List log4j = [ + "org.apache.logging.log4j:log4j-api:$log4j_version", + "org.apache.logging.log4j:log4j-core:$log4j_version", + "org.apache.logging.log4j:log4j-slf4j-impl:$log4j_version", + "org.apache.logging.log4j:log4j-web:$log4j_version" +] dependencies { - compile springboot,jaxb,web3jsdk,jackson + compile springboot,spring,jaxb,web3sdk,jackson,log4j compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0" compile "org.apache.commons:commons-lang3:3.8.1" - compile "com.alibaba:fastjson:1.2.70" compile "mysql:mysql-connector-java:8.0.13" compile "com.zaxxer:HikariCP:3.2.0" compile "com.github.sgroschupf:zkclient:0.1" compile 'org.bouncycastle:bcprov-jdk15on:1.54' + // cover old version + compile 'com.google.guava:guava:28.2-jre' + compile 'org.slf4j:jcl-over-slf4j:1.7.30' annotationProcessor 'org.projectlombok:lombok:1.18.6' compileOnly lombok diff --git a/release_note.txt b/release_note.txt new file mode 100644 index 000000000..d8f3ee793 --- /dev/null +++ b/release_note.txt @@ -0,0 +1 @@ +V1.3.2 diff --git a/src/main/java/com/webank/webase/node/mgr/abi/AbiController.java b/src/main/java/com/webank/webase/node/mgr/abi/AbiController.java index bd2d3eeef..edd71b960 100644 --- a/src/main/java/com/webank/webase/node/mgr/abi/AbiController.java +++ b/src/main/java/com/webank/webase/node/mgr/abi/AbiController.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.abi; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.abi.entity.AbiInfo; import com.webank.webase.node.mgr.abi.entity.ReqAbiListParam; import com.webank.webase.node.mgr.abi.entity.ReqImportAbi; @@ -26,6 +26,7 @@ import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.enums.SqlSortType; import com.webank.webase.node.mgr.base.properties.ConstantProperties; +import com.webank.webase.node.mgr.base.tools.JsonTools; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -88,7 +89,7 @@ public Object saveAbi(@Valid @RequestBody ReqImportAbi param, BindingResult resu checkBindResult(result); Instant startTime = Instant.now(); log.info("start saveAbi. startTime:{} ReqImportAbi:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); abiService.saveAbi(param); log.info("end saveAbi. useTime:{}", Duration.between(startTime, Instant.now()).toMillis()); @@ -105,7 +106,7 @@ public Object updateAbi(@RequestBody ReqImportAbi param, BindingResult result) { checkBindResult(result); Instant startTime = Instant.now(); log.info("start updateAbi. startTime:{} ReqImportAbi:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); if(param.getAbiId() == null) { return new BaseResponse(ConstantCode.PARAM_FAIL_ABI_ID_EMPTY); } diff --git a/src/main/java/com/webank/webase/node/mgr/abi/AbiService.java b/src/main/java/com/webank/webase/node/mgr/abi/AbiService.java index 730160207..677bce3aa 100644 --- a/src/main/java/com/webank/webase/node/mgr/abi/AbiService.java +++ b/src/main/java/com/webank/webase/node/mgr/abi/AbiService.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.abi; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.abi.entity.AbiInfo; import com.webank.webase.node.mgr.abi.entity.ReqAbiListParam; import com.webank.webase.node.mgr.abi.entity.ReqImportAbi; @@ -66,7 +66,7 @@ public void insertAbiInfo(ReqImportAbi param) { String contractAddress = param.getContractAddress(); String contractAbiStr; try { - contractAbiStr = JSON.toJSONString(param.getContractAbi()); + contractAbiStr = JsonTools.toJSONString(param.getContractAbi()); } catch (Exception e) { log.warn("abi parse string error:{}", param.getContractAbi()); throw new NodeMgrException(ConstantCode.PARAM_FAIL_ABI_INVALID); @@ -95,7 +95,7 @@ public void updateAbiInfo(ReqImportAbi param) { BeanUtils.copyProperties(param, updateAbi); String contractAbiStr; try { - contractAbiStr = JSON.toJSONString(param.getContractAbi()); + contractAbiStr = JsonTools.toJSONString(param.getContractAbi()); } catch (Exception e) { log.warn("abi parse string error:{}", param.getContractAbi()); throw new NodeMgrException(ConstantCode.PARAM_FAIL_ABI_INVALID); diff --git a/src/main/java/com/webank/webase/node/mgr/account/AccountController.java b/src/main/java/com/webank/webase/node/mgr/account/AccountController.java index 6b1213664..1b1dfe9c6 100644 --- a/src/main/java/com/webank/webase/node/mgr/account/AccountController.java +++ b/src/main/java/com/webank/webase/node/mgr/account/AccountController.java @@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.account.entity.AccountInfo; import com.webank.webase.node.mgr.account.entity.AccountListParam; import com.webank.webase.node.mgr.account.entity.ImageToken; @@ -82,7 +82,7 @@ public BaseResponse getPictureCheckCode() throws Exception { tokenData.setToken(token); tokenData.setBase64Image(base64Image); baseResponse.setData(tokenData); - log.info("end getPictureCheckCode. baseResponse:{}", JSON.toJSONString(baseResponse)); + log.info("end getPictureCheckCode. baseResponse:{}", JsonTools.toJSONString(baseResponse)); return baseResponse; } catch (Exception e) { log.error("fail getPictureCheckCode", e); @@ -102,7 +102,7 @@ public BaseResponse addAccountInfo(@RequestBody @Valid AccountInfo info, Binding BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start addAccountInfo. startTime:{} accountInfo:{}", startTime.toEpochMilli(), - JSON.toJSONString(info)); + JsonTools.toJSONString(info)); // add account row accountService.addAccountRow(info); @@ -113,7 +113,7 @@ public BaseResponse addAccountInfo(@RequestBody @Valid AccountInfo info, Binding baseResponse.setData(tbAccount); log.info("end addAccountInfo useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -128,7 +128,7 @@ public BaseResponse updateAccountInfo(@RequestBody @Valid AccountInfo info, Http BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start updateAccountInfo startTime:{} accountInfo:{}", startTime.toEpochMilli(), - JSON.toJSONString(info)); + JsonTools.toJSONString(info)); // current String currentAccount = getCurrentAccount(request); @@ -143,7 +143,7 @@ public BaseResponse updateAccountInfo(@RequestBody @Valid AccountInfo info, Http log.info("end updateAccountInfo useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -173,7 +173,7 @@ public BasePageResponse queryAccountList(@PathVariable("pageNumber") Integer pag } log.info("end queryAccountList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -191,7 +191,7 @@ public BaseResponse deleteAccount(@PathVariable("account") String account) accountService.deleteAccountRow(account); log.info("end deleteAccount. useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -205,7 +205,7 @@ public BaseResponse updatePassword(@RequestBody @Valid PasswordInfo info, HttpSe BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start updatePassword startTime:{} passwordInfo:{}", startTime.toEpochMilli(), - JSON.toJSONString(info)); + JsonTools.toJSONString(info)); String targetAccount = getCurrentAccount(request); @@ -214,7 +214,7 @@ public BaseResponse updatePassword(@RequestBody @Valid PasswordInfo info, HttpSe .updatePassword(targetAccount, info.getOldAccountPwd(), info.getNewAccountPwd()); log.info("end updatePassword useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } diff --git a/src/main/java/com/webank/webase/node/mgr/account/AccountService.java b/src/main/java/com/webank/webase/node/mgr/account/AccountService.java index c3f20af57..a97ea34f2 100644 --- a/src/main/java/com/webank/webase/node/mgr/account/AccountService.java +++ b/src/main/java/com/webank/webase/node/mgr/account/AccountService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.account; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.account.entity.AccountInfo; import com.webank.webase.node.mgr.account.entity.AccountListParam; import com.webank.webase.node.mgr.account.entity.LoginInfo; @@ -51,7 +51,7 @@ public class AccountService { * login. */ public TbAccountInfo login(LoginInfo loginInfo) throws NodeMgrException { - log.info("start login. loginInfo:{}", JSON.toJSONString(loginInfo)); + log.info("start login. loginInfo:{}", JsonTools.toJSONString(loginInfo)); String accountStr = loginInfo.getAccount(); String passwordStr = loginInfo.getAccountPwd(); @@ -81,7 +81,7 @@ public TbAccountInfo login(LoginInfo loginInfo) throws NodeMgrException { * add account row. */ public void addAccountRow(AccountInfo accountInfo) throws NodeMgrException { - log.debug("start addAccountRow. AccountInfo:{} ", JSON.toJSONString(accountInfo)); + log.debug("start addAccountRow. AccountInfo:{} ", JsonTools.toJSONString(accountInfo)); String accountStr = accountInfo.getAccount(); Integer roleId = accountInfo.getRoleId(); @@ -108,7 +108,7 @@ public void addAccountRow(AccountInfo accountInfo) throws NodeMgrException { public void updateAccountRow(String currentAccount, AccountInfo accountInfo) throws NodeMgrException { log.debug("start updateAccountRow. currentAccount:{} AccountInfo:{} ", currentAccount, - JSON.toJSONString(accountInfo)); + JsonTools.toJSONString(accountInfo)); String accountStr = accountInfo.getAccount(); // check account @@ -183,7 +183,7 @@ public void updatePassword(String targetAccount, String oldAccountPwd, String ne public TbAccountInfo queryByAccount(String accountStr) { log.debug("start queryByAccount. accountStr:{} ", accountStr); TbAccountInfo accountRow = accountMapper.queryByAccount(accountStr); - log.debug("end queryByAccount. accountRow:{} ", JSON.toJSONString(accountRow)); + log.debug("end queryByAccount. accountRow:{} ", JsonTools.toJSONString(accountRow)); return accountRow; } @@ -202,9 +202,9 @@ public int countOfAccount(String account) { * query account list. */ public List listOfAccount(AccountListParam param) { - log.debug("start listOfAccount. param:{} ", JSON.toJSONString(param)); + log.debug("start listOfAccount. param:{} ", JsonTools.toJSONString(param)); List list = accountMapper.listOfAccount(param); - log.debug("end listOfAccount. list:{} ", JSON.toJSONString(list)); + log.debug("end listOfAccount. list:{} ", JsonTools.toJSONString(list)); return list; } diff --git a/src/main/java/com/webank/webase/node/mgr/alert/log/AlertLogController.java b/src/main/java/com/webank/webase/node/mgr/alert/log/AlertLogController.java index b0e70aa80..fb7864675 100644 --- a/src/main/java/com/webank/webase/node/mgr/alert/log/AlertLogController.java +++ b/src/main/java/com/webank/webase/node/mgr/alert/log/AlertLogController.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.alert.log; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.alert.log.entity.AlertLog; import com.webank.webase.node.mgr.alert.log.entity.ReqLogListParam; import com.webank.webase.node.mgr.alert.log.entity.ReqLogParam; @@ -78,7 +78,7 @@ public Object listAlertLog(@PathVariable("pageNumber") Integer pageNumber, public Object updateAlertLog(@RequestBody ReqLogParam param) { Instant startTime = Instant.now(); log.info("start updateAlertLog. startTime:{} ReqAlertLogParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); if(param.getStatus() == null || param.getLogId() == null) { return new BaseResponse(ConstantCode.ALERT_LOG_PARAM_EMPTY); } @@ -111,7 +111,7 @@ public Object getAlertLogById(@PathVariable("logId") Integer logId) { // public Object saveAlertLog(@RequestBody ReqLogParam param) { // Instant startTime = Instant.now(); // log.info("start saveAlertLog. startTime:{} ReqAlertLogParam:{}", -// startTime.toEpochMilli(), JSON.toJSONString(param)); +// startTime.toEpochMilli(), JsonTools.toJSONString(param)); // if(StringUtils.isEmpty(param.getAlertContent()) || // StringUtils.isEmpty(param.getAlertLevel()) || // StringUtils.isEmpty(param.getAlertType())) { diff --git a/src/main/java/com/webank/webase/node/mgr/alert/mail/MailService.java b/src/main/java/com/webank/webase/node/mgr/alert/mail/MailService.java index 5f9395e67..a8c5281b5 100644 --- a/src/main/java/com/webank/webase/node/mgr/alert/mail/MailService.java +++ b/src/main/java/com/webank/webase/node/mgr/alert/mail/MailService.java @@ -16,8 +16,10 @@ package com.webank.webase.node.mgr.alert.mail; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.exception.NodeMgrException; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.account.AccountMapper; +import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.account.entity.AccountListParam; import com.webank.webase.node.mgr.account.entity.TbAccountInfo; import com.webank.webase.node.mgr.alert.log.AlertLogService; @@ -321,7 +323,10 @@ public void handleAllUserEmail(TbAlertRule alertRule, String emailTitle, String }else { List userList = new ArrayList<>(); try { - userList = (List) JSON.parse(alertRule.getUserList()); + userList = JsonTools.toJavaObjectList(alertRule.getUserList(), String.class); + if (userList == null) { + log.error("parse json error"); + } }catch (Exception e) { log.error("handleAllUserEmail parse error: e:{}, getUserList{}", e, alertRule.getUserList()); diff --git a/src/main/java/com/webank/webase/node/mgr/alert/mail/server/config/MailServerConfigController.java b/src/main/java/com/webank/webase/node/mgr/alert/mail/server/config/MailServerConfigController.java index 587af27c1..263469ee7 100644 --- a/src/main/java/com/webank/webase/node/mgr/alert/mail/server/config/MailServerConfigController.java +++ b/src/main/java/com/webank/webase/node/mgr/alert/mail/server/config/MailServerConfigController.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.alert.mail.server.config; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.alert.mail.server.config.entity.ReqMailServerConfigParam; import com.webank.webase.node.mgr.alert.mail.server.config.entity.TbMailServerConfig; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -83,7 +83,7 @@ public Object listServerConfig() { public Object updateMailServerConfig(@RequestBody ReqMailServerConfigParam param) { Instant startTime = Instant.now(); log.info("start updateMailServerConfig. startTime:{} ReqMailServerConfigParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); if(param.getServerId() == null) { log.debug("updateMailServerConfig, error:{} ", ConstantCode.MAIL_SERVER_CONFIG_PARAM_EMPTY); @@ -112,7 +112,7 @@ public Object updateMailServerConfig(@RequestBody ReqMailServerConfigParam param // public Object saveMailServerConfig(@RequestBody ReqMailServerConfigParam param) { // Instant startTime = Instant.now(); // log.info("start saveMailServerConfig. startTime:{} ReqMailServerConfigParam:{}", -// startTime.toEpochMilli(), JSON.toJSONString(param)); +// startTime.toEpochMilli(), JsonTools.toJSONString(param)); // try{ // mailServerConfigService.saveMailServerConfig(param); // log.info("end saveMailServerConfig. useTime:{}", diff --git a/src/main/java/com/webank/webase/node/mgr/alert/rule/AlertRuleController.java b/src/main/java/com/webank/webase/node/mgr/alert/rule/AlertRuleController.java index 267d5f228..48c35758d 100644 --- a/src/main/java/com/webank/webase/node/mgr/alert/rule/AlertRuleController.java +++ b/src/main/java/com/webank/webase/node/mgr/alert/rule/AlertRuleController.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.alert.rule; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.alert.rule.entity.ReqAlertRuleParam; import com.webank.webase.node.mgr.alert.rule.entity.TbAlertRule; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -55,7 +55,7 @@ public Object getAlertRuleByRuleId(@PathVariable("ruleId") Integer ruleId) { TbAlertRule res = alertRuleService.queryByRuleId(ruleId); log.info("end getAlertRuleByRuleId useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return new BaseResponse(ConstantCode.SUCCESS, res); } @@ -79,7 +79,7 @@ public Object listAlertRules() { // public Object saveAlertRule(@RequestBody @Valid AlertRuleParam param) { // Instant startTime = Instant.now(); // log.info("start saveAlertRule. startTime:{} AlertRuleParam:{}", -// startTime.toEpochMilli(), JSON.toJSONString(param)); +// startTime.toEpochMilli(), JsonTools.toJSONString(param)); // // check param // // 保证参数,用catch方式 // if(param.getUserList().isEmpty()) { @@ -96,7 +96,7 @@ public Object listAlertRules() { public Object updateAlertRule(@RequestBody ReqAlertRuleParam param) { Instant startTime = Instant.now(); log.info("start updateAlertRule. startTime:{} AlertRuleParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); if(param.getRuleId() == null) { return new BaseResponse(ConstantCode.ALERT_RULE_PARAM_EMPTY); } @@ -119,7 +119,7 @@ public Object updateAlertRule(@RequestBody ReqAlertRuleParam param) { public Object toggleAlertRule(@RequestBody ReqAlertRuleParam param) { Instant startTime = Instant.now(); log.info("start toggleAlertRule. startTime:{} AlertRuleParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(param)); + startTime.toEpochMilli(), JsonTools.toJSONString(param)); if(param.getRuleId() == null || param.getEnable() == null) { return new BaseResponse(ConstantCode.ALERT_RULE_PARAM_EMPTY); } diff --git a/src/main/java/com/webank/webase/node/mgr/alert/task/NodeStatusMonitorTask.java b/src/main/java/com/webank/webase/node/mgr/alert/task/NodeStatusMonitorTask.java index c8b9c152a..b4e212d55 100644 --- a/src/main/java/com/webank/webase/node/mgr/alert/task/NodeStatusMonitorTask.java +++ b/src/main/java/com/webank/webase/node/mgr/alert/task/NodeStatusMonitorTask.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.alert.task; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.alert.mail.MailService; import com.webank.webase.node.mgr.alert.rule.AlertRuleService; import com.webank.webase.node.mgr.alert.rule.entity.TbAlertRule; @@ -111,10 +111,10 @@ public void checkNodeStatusByGroup(int groupId) { }); if(!abnormalNodeIdList.isEmpty()) { log.warn("start node abnormal mail alert nodeIds:{} in groupId:{}", - JSON.toJSONString(abnormalNodeIdList), groupId); + JsonTools.toJSONString(abnormalNodeIdList), groupId); List alertContentList = new ArrayList<>(); - alertContentList.add("群组group " + groupId + "的共识/观察节点nodeId:" + JSON.toJSONString(abnormalNodeIdList)); - alertContentList.add("group " + groupId + "'s sealer/observer nodes nodeId: " + JSON.toJSONString(abnormalNodeIdList)); + alertContentList.add("群组group " + groupId + "的共识/观察节点nodeId:" + JsonTools.toJSONString(abnormalNodeIdList)); + alertContentList.add("group " + groupId + "'s sealer/observer nodes nodeId: " + JsonTools.toJSONString(abnormalNodeIdList)); // send node alert mail alertMailService.sendMailByRule(AlertRuleType.NODE_ALERT.getValue(), alertContentList); } diff --git a/src/main/java/com/webank/webase/node/mgr/base/code/ConstantCode.java b/src/main/java/com/webank/webase/node/mgr/base/code/ConstantCode.java index a627e6cd5..504d6aed5 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/code/ConstantCode.java +++ b/src/main/java/com/webank/webase/node/mgr/base/code/ConstantCode.java @@ -162,7 +162,8 @@ public class ConstantCode { public static final RetCode CONTRACT_ADDRESS_NULL = RetCode.mark(202100, "contractAddress is null"); public static final RetCode USER_NOT_EXIST = RetCode.mark(202110, "User's signUserId not exist"); - + /* Json parse error */ + public static final RetCode FAIL_PARSE_JSON = RetCode.mark(202111, "Fail to parse json"); /* dynamic group manage */ public static final RetCode GROUP_ID_EXISTS = RetCode.mark(202300, "group id already exists"); diff --git a/src/main/java/com/webank/webase/node/mgr/base/config/SecurityConfig.java b/src/main/java/com/webank/webase/node/mgr/base/config/SecurityConfig.java index 457244181..b5a2738e7 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/config/SecurityConfig.java +++ b/src/main/java/com/webank/webase/node/mgr/base/config/SecurityConfig.java @@ -40,6 +40,8 @@ import com.webank.webase.node.mgr.security.JsonLogoutSuccessHandler; import com.webank.webase.node.mgr.security.LoginFailHandler; import com.webank.webase.node.mgr.security.customizeAuth.TokenAuthenticationProvider; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; /** * security config. @@ -76,7 +78,7 @@ protected void configure(HttpSecurity http) throws Exception { .failureHandler(loginfailHandler) // if login fail .and().authorizeRequests() .antMatchers("/account/login", "/account/pictureCheckCode", - "/login","/user/privateKey/**", "/encrypt") + "/login","/user/privateKey/**", "/encrypt") .permitAll() .anyRequest().authenticated().and().csrf() .disable() // close csrf @@ -87,6 +89,7 @@ protected void configure(HttpSecurity http) throws Exception { .permitAll(); } + @Override public void configure(WebSecurity web) throws Exception { super.configure(web); diff --git a/src/main/java/com/webank/webase/node/mgr/base/controller/BaseController.java b/src/main/java/com/webank/webase/node/mgr/base/controller/BaseController.java index bb191fa62..4f69b41d8 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/controller/BaseController.java +++ b/src/main/java/com/webank/webase/node/mgr/base/controller/BaseController.java @@ -18,7 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.BindingResult; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.ParamException; @@ -33,8 +33,8 @@ public class BaseController { protected void checkBindResult(BindingResult result) { if (result.hasErrors()) { String errFieldStr = result.getAllErrors().stream() - .map(obj -> JSON.parseObject(JSON.toJSONString(obj))) - .map(err -> err.getString("field")) + .map(obj -> JsonTools.stringToJsonNode(JsonTools.toJSONString(obj))) + .map(err -> err.get("field").asText()) .collect(Collectors.joining(",")); StringUtils.removeEnd(errFieldStr, ","); String message = "these fields can not be empty:" + errFieldStr; diff --git a/src/main/java/com/webank/webase/node/mgr/base/exception/ExceptionsHandler.java b/src/main/java/com/webank/webase/node/mgr/base/exception/ExceptionsHandler.java index 25dfb34a5..25f26f65b 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/exception/ExceptionsHandler.java +++ b/src/main/java/com/webank/webase/node/mgr/base/exception/ExceptionsHandler.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.base.exception; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.code.RetCode; import com.webank.webase.node.mgr.base.entity.BaseResponse; @@ -46,7 +46,7 @@ public BaseResponse myExceptionHandler(NodeMgrException nodeMgrException) { .orElse(ConstantCode.SYSTEM_EXCEPTION); BaseResponse bre = new BaseResponse(retCode); - log.warn("business exception return:{}", JSON.toJSONString(bre)); + log.warn("business exception return:{}", JsonTools.toJSONString(bre)); return bre; } @@ -62,7 +62,7 @@ public BaseResponse paramExceptionHandler(ParamException paramException) { .orElse(ConstantCode.SYSTEM_EXCEPTION); BaseResponse bre = new BaseResponse(retCode); - log.warn("param exception return:{}", JSON.toJSONString(bre)); + log.warn("param exception return:{}", JsonTools.toJSONString(bre)); return bre; } @@ -77,7 +77,7 @@ public BaseResponse typeMismatchExceptionHandler(TypeMismatchException ex) { RetCode retCode = new RetCode(ConstantCode.PARAM_EXCEPTION.getCode(), ex.getMessage()); BaseResponse bre = new BaseResponse(retCode); - log.warn("typeMismatchException return:{}", JSON.toJSONString(bre)); + log.warn("typeMismatchException return:{}", JsonTools.toJSONString(bre)); return bre; } @@ -92,7 +92,7 @@ public BaseResponse accessDeniedExceptionHandler(AccessDeniedException exception throws Exception { log.warn("catch accessDenied exception", exception); BaseResponse bre = new BaseResponse(ConstantCode.ACCESS_DENIED); - log.warn("accessDenied exception return:{}", JSON.toJSONString(bre)); + log.warn("accessDenied exception return:{}", JsonTools.toJSONString(bre)); return bre; } @@ -109,7 +109,7 @@ public BaseResponse exceptionHandler(RuntimeException exc) { // v1.3.1 增加异常细节 retCode.setMessage(exc.getMessage()); BaseResponse bre = new BaseResponse(retCode); - log.warn("system RuntimeException return:{}", JSON.toJSONString(bre)); + log.warn("system RuntimeException return:{}", JsonTools.toJSONString(bre)); return bre; } } \ No newline at end of file diff --git a/src/main/java/com/webank/webase/node/mgr/base/exception/NodeMgrException.java b/src/main/java/com/webank/webase/node/mgr/base/exception/NodeMgrException.java index 58c7329a4..7c5f748ba 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/exception/NodeMgrException.java +++ b/src/main/java/com/webank/webase/node/mgr/base/exception/NodeMgrException.java @@ -16,7 +16,7 @@ package com.webank.webase.node.mgr.base.exception; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.RetCode; /** @@ -40,7 +40,7 @@ public NodeMgrException(RetCode retCode) { */ public NodeMgrException(RetCode retCode, Throwable cause) { super(retCode.getMessage(), cause); - retCode.setMessage(JSON.toJSONString(cause.getMessage())); + retCode.setMessage(JsonTools.toJSONString(cause.getMessage())); this.retCode = retCode; } diff --git a/src/main/java/com/webank/webase/node/mgr/base/filter/FrontFilter.java b/src/main/java/com/webank/webase/node/mgr/base/filter/FrontFilter.java index f38a2e30a..eb8f3b68a 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/filter/FrontFilter.java +++ b/src/main/java/com/webank/webase/node/mgr/base/filter/FrontFilter.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.base.filter; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.code.RetCode; import com.webank.webase.node.mgr.base.properties.ConstantProperties; @@ -54,7 +54,7 @@ public class FrontFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { ignorePath = getIgnorePath(); - log.info("ignorePath:{}", JSON.toJSONString(ignorePath)); + log.info("ignorePath:{}", JsonTools.toJSONString(ignorePath)); } @Override diff --git a/src/main/java/com/webank/webase/node/mgr/base/tools/AlertRuleTools.java b/src/main/java/com/webank/webase/node/mgr/base/tools/AlertRuleTools.java index faaa4e3c5..a77741ec0 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/tools/AlertRuleTools.java +++ b/src/main/java/com/webank/webase/node/mgr/base/tools/AlertRuleTools.java @@ -16,7 +16,8 @@ package com.webank.webase.node.mgr.base.tools; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.exception.NodeMgrException; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.alert.rule.entity.ReqAlertRuleParam; import com.webank.webase.node.mgr.alert.rule.entity.TbAlertRule; import lombok.extern.log4j.Log4j2; @@ -26,6 +27,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; +import org.fisco.bcos.web3j.tx.txdecode.ConstantCode; @Log4j2 public class AlertRuleTools { @@ -79,7 +81,10 @@ public static String processMailContent(String alertContent, String contentTarge List contentParamList = new ArrayList<>(); log.debug("processMailContent contentTargetParams:{}", contentTargetParams); try{ - contentParamList = (List) JSON.parse(contentTargetParams); + contentParamList = JsonTools.toJavaObjectList(contentTargetParams, String.class); + if (contentParamList == null) { + log.error("parse json error"); + } } catch (Exception e) { log.error("processMailContent parse contentParam to List error contentParams:{}, exception:{}", contentTargetParams, e); @@ -108,7 +113,10 @@ public static String processMailContent(String alertContent, String contentTarge List contentParamList = new ArrayList<>(); log.debug("processMailContent contentTargetParams:{}", contentTargetParams); try{ - contentParamList = (List) JSON.parse(contentTargetParams); + contentParamList = JsonTools.toJavaObjectList(contentTargetParams, String.class); + if (contentParamList == null) { + log.error("parse json error"); + } } catch (Exception e) { log.error("processMailContent parse contentParam to List error contentParams:{}, exception:{}", contentTargetParams, e); diff --git a/src/main/java/com/webank/webase/node/mgr/base/tools/JsonTools.java b/src/main/java/com/webank/webase/node/mgr/base/tools/JsonTools.java new file mode 100644 index 000000000..621ac983b --- /dev/null +++ b/src/main/java/com/webank/webase/node/mgr/base/tools/JsonTools.java @@ -0,0 +1,246 @@ +package com.webank.webase.node.mgr.base.tools; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParser.Feature; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import java.io.IOException; +import java.text.SimpleDateFormat; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +/** + * Jackson Util + * edit by marsli from hujkay + */ +@Slf4j +public class JsonTools { + private static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss"; + /** + * 设置一些通用的属性 + */ + private static final ThreadLocal OBJECT_MAPPER = ThreadLocal.withInitial(() -> { + ObjectMapper objectMapper = new ObjectMapper(); + // 如果存在未知属性,则忽略不报错 + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + // 允许key没有双引号 + objectMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + // 允许key有单引号 + objectMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true); + // 属性值为null的不参与序列化 + // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.setSerializationInclusion(Include.ALWAYS); + // timestamp + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + // date format + objectMapper.setDateFormat(new SimpleDateFormat(STANDARD_FORMAT)); + return objectMapper; + }); + + public static String toJSONString(Object obj) { + return obj != null ? toJSONString(obj, () -> "") : ""; + } + + public static String toJSONString(Object obj, Supplier defaultSupplier) { + try { + return obj != null ? OBJECT_MAPPER.get().writeValueAsString(obj) : defaultSupplier.get(); + } catch (Throwable e) { + log.error(String.format("toJSONString %s", obj != null ? obj.toString() : "null"), e); + } + return defaultSupplier.get(); + } + + public static T toJavaObject(String value, Class tClass) { + return StringUtils.isNotBlank(value) ? toJavaObject(value, tClass, () -> null) : null; + } + + public static T toJavaObject(Object obj, Class tClass) { + return obj != null ? toJavaObject(toJSONString(obj), tClass, () -> null) : null; + } + + public static T toJavaObject(String value, Class tClass, Supplier defaultSupplier) { + try { + if (StringUtils.isBlank(value)) { + return defaultSupplier.get(); + } + return OBJECT_MAPPER.get().readValue(value, tClass); + } catch (Throwable e) { + log.error(String.format("toJavaObject exception: \n %s\n %s", value, tClass), e); + } + return defaultSupplier.get(); + } + + public static List toJavaObjectList(String value, Class tClass) { + return StringUtils.isNotBlank(value) ? toJavaObjectList(value, tClass, () -> null) : null; + } + + public static List toJavaObjectList(Object obj, Class tClass) { + return obj != null ? toJavaObjectList(toJSONString(obj), tClass, () -> null) : null; + } + + public static List toJavaObjectList(String value, Class tClass, Supplier> defaultSupplier) { + try { + if (StringUtils.isBlank(value)) { + return defaultSupplier.get(); + } + JavaType javaType = OBJECT_MAPPER.get().getTypeFactory().constructParametricType(List.class, tClass); + return OBJECT_MAPPER.get().readValue(value, javaType); + } catch (Throwable e) { + log.error(String.format("toJavaObjectList exception \n%s\n%s", value, tClass), e); + } + return defaultSupplier.get(); + } + + // 简单地直接用json复制或者转换(Cloneable) + public static T jsonCopy(Object obj, Class tClass) { + return obj != null ? toJavaObject(toJSONString(obj), tClass) : null; + } + + public static Map toMap(String value) { + return StringUtils.isNotBlank(value) ? toMap(value, () -> null) : null; + } + + public static Map toMap(Object value) { + return value != null ? toMap(value, () -> null) : null; + } + + public static Map toMap(Object value, Supplier> defaultSupplier) { + if (value == null) { + return defaultSupplier.get(); + } + try { + if (value instanceof Map) { + return (Map) value; + } + } catch (Exception e) { + log.error("fail to convert" + toJSONString(value), e); + } + return toMap(toJSONString(value), defaultSupplier); + } + + public static Map toMap(String value, Supplier> defaultSupplier) { + if (StringUtils.isBlank(value)) { + return defaultSupplier.get(); + } + try { + return toJavaObject(value, LinkedHashMap.class); + } catch (Exception e) { + log.error(String.format("toMap exception\n%s", value), e); + } + return defaultSupplier.get(); + } + + + public static List toList(String value) { + return StringUtils.isNotBlank(value) ? toList(value, () -> null) : null; + } + + public static List toList(Object value) { + return value != null ? toList(value, () -> null) : null; + } + + public static List toList(String value, Supplier> defaultSuppler) { + if (StringUtils.isBlank(value)) { + return defaultSuppler.get(); + } + try { + return toJavaObject(value, List.class); + } catch (Exception e) { + log.error("toList exception\n" + value, e); + } + return defaultSuppler.get(); + } + + public static List toList(Object value, Supplier> defaultSuppler) { + if (value == null) { + return defaultSuppler.get(); + } + if (value instanceof List) { + return (List) value; + } + return toList(toJSONString(value), defaultSuppler); + } + + /* author: clk */ + + public static boolean isJson(String str) { + try { + OBJECT_MAPPER.get().readTree(str); + return true; + } catch (IOException e) { + return false; + } + } + + public static JsonNode stringToJsonNode(String str) { + try { + return OBJECT_MAPPER.get().readTree(str); + } catch (IOException e) { + log.error("Parse String to JsonNode error : {}", e.getMessage()); + return null; + } + } + + public static String objToString(T obj) { + if (obj == null) { + return null; + } + try { + return obj instanceof String ? (String) obj + : OBJECT_MAPPER.get().writerWithDefaultPrettyPrinter().writeValueAsString(obj); + } catch (JsonProcessingException e) { + log.error("Parse Object to String error : {}", e.getMessage()); + return null; + } + } + + @SuppressWarnings("unchecked") + public static T stringToObj(String str, Class clazz) { + if (StringUtils.isEmpty(str) || clazz == null) { + return null; + } + try { + return clazz.equals(String.class) ? (T) str : OBJECT_MAPPER.get().readValue(str, clazz); + } catch (Exception e) { + log.error("Parse String to Object error : {}", e.getMessage()); + return null; + } + } + + @SuppressWarnings("unchecked") + public static T stringToObj(String str, TypeReference typeReference) { + if (StringUtils.isEmpty(str) || typeReference == null) { + return null; + } + try { + return (T) (typeReference.getType().equals(String.class) ? str + : OBJECT_MAPPER.get().readValue(str, typeReference)); + } catch (IOException e) { + log.error("Parse String to Object error", e); + return null; + } + } + + public static T stringToObj(String str, Class collectionClazz, + Class... elementClazzes) { + JavaType javaType = OBJECT_MAPPER.get().getTypeFactory() + .constructParametricType(collectionClazz, elementClazzes); + try { + return OBJECT_MAPPER.get().readValue(str, javaType); + } catch (IOException e) { + log.error("Parse String to Object error : {}" + e.getMessage()); + return null; + } + } +} diff --git a/src/main/java/com/webank/webase/node/mgr/base/tools/NodeMgrTools.java b/src/main/java/com/webank/webase/node/mgr/base/tools/NodeMgrTools.java index e5a4d843c..826628530 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/tools/NodeMgrTools.java +++ b/src/main/java/com/webank/webase/node/mgr/base/tools/NodeMgrTools.java @@ -13,8 +13,7 @@ */ package com.webank.webase.node.mgr.base.tools; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.code.RetCode; import com.webank.webase.node.mgr.base.entity.BaseResponse; @@ -155,26 +154,17 @@ public static T object2JavaBean(Object obj, Class clazz) { log.warn("object2JavaBean. obj or clazz null"); return null; } - String jsonStr = JSON.toJSONString(obj); + String jsonStr = JsonTools.toJSONString(obj); - return JSON.parseObject(jsonStr, clazz); + return JsonTools.toJavaObject(jsonStr, clazz); } - public static JSONObject Object2JSONObject(Object obj) { - if (obj == null) { - log.warn("obj is null"); - return null; - } - String objJson = JSON.toJSONString(obj); - return JSONObject.parseObject(objJson); - } - /** * encode list by sha. */ public static String shaList(List values) { - log.info("shaList start. values:{}", JSON.toJSONString(values)); + log.info("shaList start. values:{}", JsonTools.toJSONString(values)); // list按字段排序,并转换成字符串 String list2SortString = list2SortString(values); // SHA加密字符串 @@ -364,7 +354,7 @@ public static void responseRetCodeException(HttpServletResponse response, RetCod /* baseResponse.setMessage(ex.getMessage()); response.setContentType("application/json;charset=UTF-8");*/ try { - response.getWriter().write(JSON.toJSONString(baseResponse)); + response.getWriter().write(JsonTools.toJSONString(baseResponse)); } catch (IOException e) { log.error("fail responseRetCodeException",e); } @@ -415,20 +405,6 @@ public static boolean isWithinPeriod(LocalDateTime lastTime, String validLength) } } - /** - * is json. - */ - public static boolean isJSON(String str) { - boolean result; - try { - JSON.parse(str); - result = true; - } catch (Exception e) { - result = false; - } - return result; - } - /** * response string. */ @@ -439,12 +415,12 @@ public static void responseString(HttpServletResponse response, String str) { } RetCode retCode; - if (isJSON(str) && (retCode = JSONObject.parseObject(str, RetCode.class)) != null) { + if (JsonTools.isJson(str) && (retCode = JsonTools.toJavaObject(str, RetCode.class)) != null) { baseResponse = new BaseResponse(retCode); } try { - response.getWriter().write(JSON.toJSONString(baseResponse)); + response.getWriter().write(JsonTools.toJSONString(baseResponse)); } catch (IOException e) { log.error("fail responseRetCodeException", e); } diff --git a/src/main/java/com/webank/webase/node/mgr/base/tools/Web3Tools.java b/src/main/java/com/webank/webase/node/mgr/base/tools/Web3Tools.java index a69a945b0..782b97023 100644 --- a/src/main/java/com/webank/webase/node/mgr/base/tools/Web3Tools.java +++ b/src/main/java/com/webank/webase/node/mgr/base/tools/Web3Tools.java @@ -17,17 +17,17 @@ -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; +import com.webank.webase.node.mgr.base.exception.NodeMgrException; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.StringUtils; import org.fisco.bcos.web3j.crypto.Hash; import org.fisco.bcos.web3j.crypto.Keys; -import org.fisco.bcos.web3j.crypto.gm.sm3.SM3Digest; import org.fisco.bcos.web3j.protocol.ObjectMapperFactory; import org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition; +import com.webank.webase.node.mgr.base.code.ConstantCode; import org.fisco.bcos.web3j.tx.txdecode.ConstantProperties; import org.fisco.bcos.web3j.utils.Numeric; -import org.fisco.bcos.web3j.utils.Strings; import java.io.IOException; import java.util.Arrays; @@ -116,10 +116,15 @@ public static byte[] getMethodIdBytes(AbiDefinition abiDefinition) { * @return */ public static AbiDefinition getAbiDefinition(String funName, String contractAbi) { - JSONArray abiArr = JSONArray.parseArray(contractAbi); + if (StringUtils.isBlank(contractAbi)) { + throw new NodeMgrException(ConstantCode.CONTRACT_ABI_EMPTY); + } + List abiList = JsonTools.toJavaObjectList(contractAbi, AbiDefinition.class); + if (abiList == null) { + throw new NodeMgrException(ConstantCode.FAIL_PARSE_JSON); + } AbiDefinition result = null; - for (Object object : abiArr) { - AbiDefinition abiDefinition = JSON.parseObject(object.toString(), AbiDefinition.class); + for (AbiDefinition abiDefinition : abiList) { if (ConstantProperties.TYPE_FUNCTION.equals(abiDefinition.getType()) && funName.equals(abiDefinition.getName())) { result = abiDefinition; diff --git a/src/main/java/com/webank/webase/node/mgr/block/BlockController.java b/src/main/java/com/webank/webase/node/mgr/block/BlockController.java index c8b10a8e9..5578e8406 100644 --- a/src/main/java/com/webank/webase/node/mgr/block/BlockController.java +++ b/src/main/java/com/webank/webase/node/mgr/block/BlockController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.block; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -102,7 +102,7 @@ public BasePageResponse queryBlockList(@PathVariable("groupId") Integer groupId, } log.info("end queryBlockList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pageResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pageResponse)); return pageResponse; } @@ -121,7 +121,7 @@ public BaseResponse getBlockByNumber(@PathVariable("groupId") Integer groupId, Object blockInfo = blockService.getBlockFromFrontByNumber(groupId, blockNumber); baseResponse.setData(blockInfo); log.info("end getBlockByNumber useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/block/BlockService.java b/src/main/java/com/webank/webase/node/mgr/block/BlockService.java index 0f8bbaec0..5ab40b4fa 100644 --- a/src/main/java/com/webank/webase/node/mgr/block/BlockService.java +++ b/src/main/java/com/webank/webase/node/mgr/block/BlockService.java @@ -23,7 +23,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.TableName; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -183,7 +183,7 @@ public void saveBLockInfo(BlockInfo blockInfo, Integer groupId) throws NodeMgrEx */ @Transactional public void addBlockInfo(TbBlock tbBlock, int groupId) throws NodeMgrException { - log.debug("start addBlockInfo tbBlock:{}", JSON.toJSONString(tbBlock)); + log.debug("start addBlockInfo tbBlock:{}", JsonTools.toJSONString(tbBlock)); String tableName = TableName.BLOCK.getTableName(groupId); //check newBLock == dbMaxBLock +1 BigInteger dbMaxBLock = blockmapper.getLatestBlockNumber(tableName); @@ -204,7 +204,7 @@ public void addBlockInfo(TbBlock tbBlock, int groupId) throws NodeMgrException { public List queryBlockList(int groupId, BlockListParam queryParam) throws NodeMgrException { log.debug("start queryBlockList groupId:{},queryParam:{}", groupId, - JSON.toJSONString(queryParam)); + JsonTools.toJSONString(queryParam)); List listOfBlock = blockmapper .getList(TableName.BLOCK.getTableName(groupId), queryParam); diff --git a/src/main/java/com/webank/webase/node/mgr/cert/CertController.java b/src/main/java/com/webank/webase/node/mgr/cert/CertController.java index d3c54cb64..83df4f123 100644 --- a/src/main/java/com/webank/webase/node/mgr/cert/CertController.java +++ b/src/main/java/com/webank/webase/node/mgr/cert/CertController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.cert; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; @@ -71,7 +71,7 @@ public Object getCertByFingerPrint(@RequestParam(required = true)String fingerPr return new BaseResponse(ConstantCode.CERT_ERROR, e.getMessage()); } log.info("end getCertByFingerPrint useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(tbCert)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(tbCert)); return new BaseResponse(ConstantCode.SUCCESS, tbCert); } @@ -88,7 +88,7 @@ public Object addCert(@RequestBody @Valid CertHandle certHandle, BindingResult result) throws NodeMgrException { Instant startTime = Instant.now(); log.info("start addCert. startTime:{} certHandle:{}", - startTime.toEpochMilli(), JSON.toJSONString(certHandle)); + startTime.toEpochMilli(), JsonTools.toJSONString(certHandle)); checkBindResult(result); int count = 0; String content = certHandle.getContent(); @@ -113,7 +113,7 @@ public Object removeCert(@RequestBody @Valid CertHandle certHandle, BindingResult result) throws NodeMgrException { Instant startTime = Instant.now(); log.info("start removeCert. startTime:{} certHandle:{}", - startTime.toEpochMilli(), JSON.toJSONString(certHandle)); + startTime.toEpochMilli(), JsonTools.toJSONString(certHandle)); checkBindResult(result); int count = 0; String fingerPrint = certHandle.getFingerPrint(); diff --git a/src/main/java/com/webank/webase/node/mgr/chain/ChainController.java b/src/main/java/com/webank/webase/node/mgr/chain/ChainController.java index 61901f164..03fcb90a4 100644 --- a/src/main/java/com/webank/webase/node/mgr/chain/ChainController.java +++ b/src/main/java/com/webank/webase/node/mgr/chain/ChainController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.chain; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -61,7 +61,7 @@ public BaseResponse getChainMoinntorInfo(@PathVariable("frontId") Integer frontI response.setData(rspObj); log.info("end getChainInfo. endTime:{} response:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } diff --git a/src/main/java/com/webank/webase/node/mgr/chain/ChainService.java b/src/main/java/com/webank/webase/node/mgr/chain/ChainService.java index b7fd3eccc..9b6775645 100644 --- a/src/main/java/com/webank/webase/node/mgr/chain/ChainService.java +++ b/src/main/java/com/webank/webase/node/mgr/chain/ChainService.java @@ -15,7 +15,7 @@ import static com.webank.webase.node.mgr.frontinterface.FrontRestTools.URI_CHAIN; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.properties.ConstantProperties; @@ -75,7 +75,7 @@ public Object getChainMonitorInfo(Integer frontId, LocalDateTime beginDate, log.info("getChainMonitorInfo request url:{}", url); Object rspObj = genericRestTemplate.getForObject(url, Object.class); - log.debug("end getChainMonitorInfo. rspObj:{}", JSON.toJSONString(rspObj)); + log.debug("end getChainMonitorInfo. rspObj:{}", JsonTools.toJSONString(rspObj)); return rspObj; } } diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java index 90e0d368c..319ca80cb 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.contract; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; @@ -66,7 +66,7 @@ public BaseResponse saveContract(@RequestBody @Valid Contract contract, BindingR BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start saveContract startTime:{} contract:{}", startTime.toEpochMilli(), - JSON.toJSONString(contract)); + JsonTools.toJSONString(contract)); // add contract row TbContract tbContract = contractService.saveContract(contract); @@ -74,7 +74,7 @@ public BaseResponse saveContract(@RequestBody @Valid Contract contract, BindingR baseResponse.setData(tbContract); log.info("end saveContract useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -96,7 +96,7 @@ public BaseResponse deleteContract(@PathVariable("groupId") Integer groupId, contractService.deleteContract(contractId, groupId); log.info("end deleteContract useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -110,7 +110,7 @@ public BasePageResponse queryContractList(@RequestBody QueryContractParam inputP BasePageResponse pagesponse = new BasePageResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start contractList. startTime:{} inputParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(inputParam)); + startTime.toEpochMilli(), JsonTools.toJSONString(inputParam)); //param ContractParam queryParam = new ContractParam(); @@ -130,7 +130,7 @@ public BasePageResponse queryContractList(@RequestBody QueryContractParam inputP } log.info("end contractList. useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -150,7 +150,7 @@ public BaseResponse queryContract(@PathVariable("contractId") Integer contractId baseResponse.setData(contractRow); log.info("end queryContract useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -165,13 +165,13 @@ public BaseResponse deployContract(@RequestBody @Valid DeployInputParam deployIn BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start queryContract startTime:{} deployInputParam:{}", startTime.toEpochMilli(), - JSON.toJSONString(deployInputParam)); + JsonTools.toJSONString(deployInputParam)); TbContract tbContract = contractService.deployContract(deployInputParam); baseResponse.setData(tbContract); log.info("end deployContract useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -190,12 +190,12 @@ public BaseResponse sendTransaction(@RequestBody @Valid TransactionInputParam pa } Instant startTime = Instant.now(); log.info("start sendTransaction startTime:{} param:{}", startTime.toEpochMilli(), - JSON.toJSONString(param)); + JsonTools.toJSONString(param)); BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Object transRsp = contractService.sendTransaction(param); baseResponse.setData(transRsp); log.info("end sendTransaction useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -210,14 +210,14 @@ public BaseResponse getByPartOfByecodebin(@RequestBody @Valid QueryByBinParam qu checkBindResult(result); Instant startTime = Instant.now(); log.info("start getByPartOfByecodebin startTime:{} groupId:{} queryParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(queryParam)); + startTime.toEpochMilli(), JsonTools.toJSONString(queryParam)); BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); ContractParam param = new ContractParam(); BeanUtils.copyProperties(queryParam, param); TbContract tbContract = contractService.queryContract(param); baseResponse.setData(tbContract); log.info("end getByPartOfByecodebin useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java index 2e3aa6e2e..b7a47a29c 100644 --- a/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java +++ b/src/main/java/com/webank/webase/node/mgr/contract/ContractService.java @@ -13,8 +13,7 @@ */ package com.webank.webase.node.mgr.contract; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.abi.AbiService; import com.webank.webase.node.mgr.abi.entity.AbiInfo; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -77,7 +76,7 @@ public class ContractService { * add new contract data. */ public TbContract saveContract(Contract contract) throws NodeMgrException { - log.debug("start addContractInfo Contract:{}", JSON.toJSONString(contract)); + log.debug("start addContractInfo Contract:{}", JsonTools.toJSONString(contract)); TbContract tbContract; if (contract.getContractId() == null) { tbContract = newContract(contract);//new @@ -143,12 +142,12 @@ public void deleteContract(Integer contractId, int groupId) throws NodeMgrExcept * query contract list. */ public List qureyContractList(ContractParam param) throws NodeMgrException { - log.debug("start qureyContractList ContractListParam:{}", JSON.toJSONString(param)); + log.debug("start qureyContractList ContractListParam:{}", JsonTools.toJSONString(param)); // query contract list List listOfContract = contractMapper.listOfContract(param); - log.debug("end qureyContractList listOfContract:{}", JSON.toJSONString(listOfContract)); + log.debug("end qureyContractList listOfContract:{}", JsonTools.toJSONString(listOfContract)); return listOfContract; } @@ -157,7 +156,7 @@ public List qureyContractList(ContractParam param) throws NodeMgrExc * query count of contract. */ public int countOfContract(ContractParam param) throws NodeMgrException { - log.debug("start countOfContract ContractListParam:{}", JSON.toJSONString(param)); + log.debug("start countOfContract ContractListParam:{}", JsonTools.toJSONString(param)); try { return contractMapper.countOfContract(param); } catch (RuntimeException ex) { @@ -174,7 +173,7 @@ public TbContract queryByContractId(Integer contractId) throws NodeMgrException try { TbContract contractRow = contractMapper.queryByContractId(contractId); log.debug("start queryContract contractId:{} contractRow:{}", contractId, - JSON.toJSONString(contractRow)); + JsonTools.toJSONString(contractRow)); return contractRow; } catch (RuntimeException ex) { log.error("fail countOfContract", ex); @@ -194,7 +193,7 @@ public List queryContractByBin(Integer groupId, String contractBin) return null; } List contractRow = contractMapper.queryContractByBin(groupId, contractBin); - log.debug("start queryContractByBin:{}", contractBin, JSON.toJSONString(contractRow)); + log.debug("start queryContractByBin:{}", contractBin, JsonTools.toJSONString(contractRow)); return contractRow; } catch (RuntimeException ex) { log.error("fail queryContractByBin", ex); @@ -206,7 +205,7 @@ public List queryContractByBin(Integer groupId, String contractBin) * deploy contract. */ public TbContract deployContract(DeployInputParam inputParam) throws NodeMgrException { - log.info("start deployContract. inputParam:{}", JSON.toJSONString(inputParam)); + log.info("start deployContract. inputParam:{}", JsonTools.toJSONString(inputParam)); int groupId = inputParam.getGroupId(); // check deploy permission @@ -219,7 +218,7 @@ public TbContract deployContract(DeployInputParam inputParam) throws NodeMgrExce verifyContractNameNotExist(inputParam.getGroupId(), inputParam.getContractPath(), inputParam.getContractName(), inputParam.getContractId()); - JSONArray abiArray = JSONArray.parseArray(inputParam.getContractAbi()); + List abiArray = JsonTools.toJavaObjectList(inputParam.getContractAbi(), AbiDefinition.class); if (abiArray == null || abiArray.isEmpty()) { log.info("fail deployContract. abi is empty"); throw new NodeMgrException(ConstantCode.CONTRACT_ABI_EMPTY); @@ -234,7 +233,7 @@ public TbContract deployContract(DeployInputParam inputParam) throws NodeMgrExce params.put("signUserId", signUserId); params.put("contractName", contractName); // params.put("version", version); - params.put("abiInfo", JSONArray.parseArray(inputParam.getContractAbi())); + params.put("abiInfo", abiArray); params.put("bytecodeBin", inputParam.getBytecodeBin()); params.put("funcParam", inputParam.getConstructorParams()); @@ -264,10 +263,10 @@ public TbContract deployContract(DeployInputParam inputParam) throws NodeMgrExce * query contract info. */ public TbContract queryContract(ContractParam queryParam) { - log.debug("start queryContract. queryParam:{}", JSON.toJSONString(queryParam)); + log.debug("start queryContract. queryParam:{}", JsonTools.toJSONString(queryParam)); TbContract tbContract = contractMapper.queryContract(queryParam); - log.debug("end queryContract. queryParam:{} tbContract:{}", JSON.toJSONString(queryParam), - JSON.toJSONString(tbContract)); + log.debug("end queryContract. queryParam:{} tbContract:{}", JsonTools.toJSONString(queryParam), + JsonTools.toJSONString(tbContract)); return tbContract; } @@ -276,7 +275,7 @@ public TbContract queryContract(ContractParam queryParam) { * send transaction. */ public Object sendTransaction(TransactionInputParam param) throws NodeMgrException { - log.debug("start sendTransaction. param:{}", JSON.toJSONString(param)); + log.debug("start sendTransaction. param:{}", JsonTools.toJSONString(param)); if (Objects.isNull(param)) { log.info("fail sendTransaction. request param is null"); @@ -314,7 +313,7 @@ public Object sendTransaction(TransactionInputParam param) throws NodeMgrExcepti Object frontRsp = frontRestTools .postForEntity(param.getGroupId(), FrontRestTools.URI_SEND_TRANSACTION_WITH_SIGN, transParam, Object.class); - log.debug("end sendTransaction. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end sendTransaction. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -424,7 +423,7 @@ public void sendAbi(int groupId, int contractId, String address) { param.setGroupId(groupId); param.setContractName(contract.getContractName()); param.setAddress(address); - param.setAbiInfo(JSONArray.parseArray(abiInfo, AbiDefinition.class)); + param.setAbiInfo(JsonTools.toJavaObjectList(abiInfo, AbiDefinition.class)); param.setContractBin(contract.getContractBin()); frontInterface.sendAbi(groupId, param); @@ -452,7 +451,7 @@ private void checkDeployPermission(int groupId, String userAddress) { return; } else { List listData = (List) response.getData(); - deployUserList = JSON.parseArray(JSON.toJSONString(listData), PermissionInfo.class); + deployUserList = JsonTools.toJavaObjectList(JsonTools.toJSONString(listData), PermissionInfo.class); } // check user in the list diff --git a/src/main/java/com/webank/webase/node/mgr/front/FrontController.java b/src/main/java/com/webank/webase/node/mgr/front/FrontController.java index afe94784a..890aed9a2 100644 --- a/src/main/java/com/webank/webase/node/mgr/front/FrontController.java +++ b/src/main/java/com/webank/webase/node/mgr/front/FrontController.java @@ -14,7 +14,7 @@ package com.webank.webase.node.mgr.front; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; @@ -61,12 +61,12 @@ public BaseResponse newFront(@RequestBody @Valid FrontInfo frontInfo, BindingRes checkBindResult(result); Instant startTime = Instant.now(); log.info("start newFront startTime:{} frontInfo:{}", - startTime.toEpochMilli(), JSON.toJSONString(frontInfo)); + startTime.toEpochMilli(), JsonTools.toJSONString(frontInfo)); BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); TbFront tbFront = frontService.newFront(frontInfo); baseResponse.setData(tbFront); log.info("end newFront useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -98,7 +98,7 @@ public BasePageResponse queryFrontList( } log.info("end queryFrontList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -116,7 +116,7 @@ public BaseResponse removeFront(@PathVariable("frontId") Integer frontId) { frontService.removeFront(frontId); log.info("end removeFront useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/front/FrontService.java b/src/main/java/com/webank/webase/node/mgr/front/FrontService.java index 4df8f5494..52e506684 100644 --- a/src/main/java/com/webank/webase/node/mgr/front/FrontService.java +++ b/src/main/java/com/webank/webase/node/mgr/front/FrontService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.front; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.DataStatus; import com.webank.webase.node.mgr.base.enums.GroupType; @@ -124,7 +124,7 @@ public TbFront newFront(FrontInfo frontInfo) { //save front info frontMapper.add(tbFront); if (tbFront.getFrontId() == null || tbFront.getFrontId() == 0) { - log.warn("fail newFront, after save, tbFront:{}", JSON.toJSONString(tbFront)); + log.warn("fail newFront, after save, tbFront:{}", JsonTools.toJSONString(tbFront)); throw new NodeMgrException(ConstantCode.SAVE_FRONT_FAIL); } for (String groupId : groupIdList) { @@ -305,7 +305,7 @@ public void updateFrontWithInternal(Integer frontId, Integer status) { Duration duration = Duration.between(modifyTime, LocalDateTime.now()); Long subTime = duration.toMillis(); if (subTime < CHECK_FRONT_STATUS_WAIT_MIN_MILLIS && createTime.isBefore(modifyTime)) { - log.info("updateFrontWithInternal jump. subTime:{}, minInternal:{}", + log.debug("updateFrontWithInternal jump. subTime:{}, minInternal:{}", subTime, CHECK_FRONT_STATUS_WAIT_MIN_MILLIS); return; } diff --git a/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontInterfaceService.java b/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontInterfaceService.java index 11cc8c3a2..9788edc52 100644 --- a/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontInterfaceService.java +++ b/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontInterfaceService.java @@ -13,6 +13,7 @@ */ package com.webank.webase.node.mgr.frontinterface; +import com.fasterxml.jackson.databind.JsonNode; import java.math.BigInteger; import java.util.*; @@ -33,8 +34,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.properties.ConstantProperties; import com.webank.webase.node.mgr.block.entity.BlockInfo; @@ -45,7 +45,7 @@ import com.webank.webase.node.mgr.frontinterface.entity.SyncStatus; import com.webank.webase.node.mgr.monitor.ChainTransInfo; import com.webank.webase.node.mgr.node.entity.PeerInfo; -import com.webank.webase.node.mgr.transaction.entity.TransReceipt; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; import com.webank.webase.node.mgr.transaction.entity.TransactionInfo; import lombok.extern.log4j.Log4j2; @@ -83,13 +83,19 @@ private T requestSpecificFront(int groupId, String frontIp, Integer frontPor ResponseEntity response = genericRestTemplate.exchange(url, method, entity, clazz); return response.getBody(); } catch (HttpStatusCodeException ex) { - JSONObject error = JSONObject.parseObject(ex.getResponseBodyAsString()); - log.error("http request fail. error:{}", JSON.toJSONString(error)); - if (error.containsKey("code") && error.containsKey("errorMessage")) { - throw new NodeMgrException(error.getInteger("code"), - error.getString("errorMessage")); + JsonNode error = JsonTools.stringToJsonNode(ex.getResponseBodyAsString()); + log.error("http request fail. error:{}", JsonTools.toJSONString(error)); + if (error == null) { + log.error("deserialize http response error"); + throw new NodeMgrException(ConstantCode.REQUEST_FRONT_FAIL, ex); + } + try { + int code = error.get("code").intValue(); + String errorMessage = error.get("errorMessage").asText(); + throw new NodeMgrException(code, errorMessage); + } catch (NullPointerException e) { + throw new NodeMgrException(ConstantCode.REQUEST_FRONT_FAIL, ex); } - throw new NodeMgrException(ConstantCode.REQUEST_FRONT_FAIL, ex); } } @@ -111,11 +117,11 @@ private T getFromSpecificFront(int groupId, String frontIp, Integer frontPor * send contract abi */ public void sendAbi(int groupId, PostAbiInfo param) { - log.debug("start sendAbi groupId:{} param:{}", groupId, JSON.toJSONString(param)); + log.debug("start sendAbi groupId:{} param:{}", groupId, JsonTools.toJSONString(param)); frontRestTools.postForEntity(groupId, FrontRestTools.URI_CONTRACT_SENDABI, param, Object.class); - log.debug("end sendAbi groupId:{} param:{}", groupId, JSON.toJSONString(param)); + log.debug("end sendAbi groupId:{} param:{}", groupId, JsonTools.toJSONString(param)); } @@ -208,10 +214,10 @@ public String getContractCode(Integer groupId, String address, BigInteger blockN /** * get transaction receipt. */ - public TransReceipt getTransReceipt(Integer groupId, String transHash) throws NodeMgrException { + public TransactionReceipt getTransReceipt(Integer groupId, String transHash) throws NodeMgrException { log.debug("start getTransReceipt groupId:{} transaction:{}", groupId, transHash); String uri = String.format(FrontRestTools.FRONT_TRANS_RECEIPT_BY_HASH_URI, transHash); - TransReceipt transReceipt = frontRestTools.getForEntity(groupId, uri, TransReceipt.class); + TransactionReceipt transReceipt = frontRestTools.getForEntity(groupId, uri, TransactionReceipt.class); log.debug("end getTransReceipt"); return transReceipt; } @@ -257,7 +263,7 @@ public BlockInfo getblockByHash(Integer groupId, String pkHash) throws NodeMgrEx log.debug("start getblockByHash. groupId:{} pkHash:{}", groupId, pkHash); String uri = String.format(FrontRestTools.URI_BLOCK_BY_HASH, pkHash); BlockInfo blockInfo = frontRestTools.getForEntity(groupId, uri, BlockInfo.class); - log.debug("end getblockByHash. blockInfo:{}", JSON.toJSONString(blockInfo)); + log.debug("end getblockByHash. blockInfo:{}", JsonTools.toJSONString(blockInfo)); return blockInfo; } @@ -273,7 +279,7 @@ public ChainTransInfo getTransInfoByHash(Integer groupId, String hash) throws No } ChainTransInfo chainTransInfo = new ChainTransInfo(trans.getFrom(), trans.getTo(), trans.getInput(), trans.getBlockNumber()); - log.debug("end getTransInfoByHash:{}", JSON.toJSONString(chainTransInfo)); + log.debug("end getTransInfoByHash:{}", JsonTools.toJSONString(chainTransInfo)); return chainTransInfo; } @@ -283,7 +289,7 @@ public ChainTransInfo getTransInfoByHash(Integer groupId, String hash) throws No public String getAddressByHash(Integer groupId, String transHash) throws NodeMgrException { log.debug("start getAddressByHash. groupId:{} transHash:{}", groupId, transHash); - TransReceipt transReceipt = getTransReceipt(groupId, transHash); + TransactionReceipt transReceipt = getTransReceipt(groupId, transHash); String contractAddress = transReceipt.getContractAddress(); log.debug("end getAddressByHash. contractAddress{}", contractAddress); return contractAddress; @@ -325,7 +331,7 @@ public List getTransByBlockNumber(Integer groupId, BigInteger b return null; } List transInBLock = blockInfo.getTransactions(); - log.debug("end getTransByBlockNumber. transInBLock:{}", JSON.toJSONString(transInBLock)); + log.debug("end getTransByBlockNumber. transInBLock:{}", JsonTools.toJSONString(transInBLock)); return transInBLock; } @@ -335,7 +341,7 @@ public List getTransByBlockNumber(Integer groupId, BigInteger b public List getGroupPeers(Integer groupId) { log.debug("start getGroupPeers. groupId:{}", groupId); List groupPeers = frontRestTools.getForEntity(groupId, FrontRestTools.URI_GROUP_PEERS, List.class); - log.debug("end getGroupPeers. groupPeers:{}", JSON.toJSONString(groupPeers)); + log.debug("end getGroupPeers. groupPeers:{}", JsonTools.toJSONString(groupPeers)); return groupPeers; } @@ -346,7 +352,7 @@ public List getObserverList(Integer groupId) { log.debug("start getObserverList. groupId:{}", groupId); List observers = frontRestTools.getForEntity(groupId, FrontRestTools.URI_GET_OBSERVER_LIST, List.class); - log.info("end getObserverList. observers:{}", JSON.toJSONString(observers)); + log.info("end getObserverList. observers:{}", JsonTools.toJSONString(observers)); return observers; } @@ -377,7 +383,7 @@ public SyncStatus getSyncStatus(Integer groupId) { log.debug("start getSyncStatus. groupId:{}", groupId); SyncStatus ststus = frontRestTools.getForEntity(groupId, FrontRestTools.URI_CSYNC_STATUS, SyncStatus.class); - log.debug("end getSyncStatus. ststus:{}", JSON.toJSONString(ststus)); + log.debug("end getSyncStatus. ststus:{}", JsonTools.toJSONString(ststus)); return ststus; } @@ -399,7 +405,7 @@ public List getSealerList(Integer groupId) { log.debug("start getSealerList. groupId:{}", groupId); List getSealerList = frontRestTools.getForEntity(groupId, FrontRestTools.URI_GET_SEALER_LIST, List.class); - log.debug("end getSealerList. getSealerList:{}", JSON.toJSONString(getSealerList)); + log.debug("end getSealerList. getSealerList:{}", JsonTools.toJSONString(getSealerList)); return getSealerList; } @@ -449,7 +455,7 @@ public String getClientVersion(String frontIp, Integer frontPort, */ public GroupHandleResult generateGroup(String frontIp, Integer frontPort, GenerateGroupInfo param) { - log.debug("start generateGroup frontIp:{} frontPort:{} param:{}", frontIp, frontPort, JSON.toJSONString(param)); + log.debug("start generateGroup frontIp:{} frontPort:{} param:{}", frontIp, frontPort, JsonTools.toJSONString(param)); Integer groupId = Integer.MAX_VALUE; GroupHandleResult groupHandleResult = requestSpecificFront(groupId, frontIp, frontPort, @@ -511,7 +517,7 @@ public List getNewBlockEventInfo(String frontIp, Integer fron return new ArrayList<>(); } List data = (List) response.getData(); - List resList = JSON.parseArray(JSON.toJSONString(data), NewBlockEventInfo.class); + List resList = JsonTools.toJavaObjectList(JsonTools.toJSONString(data), NewBlockEventInfo.class); resList.forEach(info -> info.setFrontInfo(frontIp)); return resList; } @@ -527,7 +533,7 @@ public List getContractEventInfo(String frontIp, Integer fron return new ArrayList<>(); } List data = (List) response.getData(); - List resList = JSON.parseArray(JSON.toJSONString(data), ContractEventInfo.class); + List resList = JsonTools.toJavaObjectList(JsonTools.toJSONString(data), ContractEventInfo.class); resList.forEach(info -> info.setFrontInfo(frontIp)); return resList; } @@ -535,7 +541,7 @@ public List getContractEventInfo(String frontIp, Integer fron public List getKeyStoreList(Integer groupId, String frontIp, Integer frontPort) { List data = getFromSpecificFront(groupId, frontIp, frontPort, FrontRestTools.URI_KEY_PAIR_LOCAL_KEYSTORE, List.class); - List resList = JSON.parseArray(JSON.toJSONString(data), KeyPair.class); + List resList = JsonTools.toJavaObjectList(JsonTools.toJSONString(data), KeyPair.class); return resList; } diff --git a/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontRestTools.java b/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontRestTools.java index fd1bc6ac2..c5f0c7bb6 100644 --- a/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontRestTools.java +++ b/src/main/java/com/webank/webase/node/mgr/frontinterface/FrontRestTools.java @@ -14,8 +14,8 @@ package com.webank.webase.node.mgr.frontinterface; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.DataStatus; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -195,7 +195,7 @@ private void setFailCount(String url, String methodType) { failInfo.setLatestTime(Instant.now()); failInfo.setFailCount(failInfo.getFailCount() + 1); failRequestMap.put(key, failInfo); - log.info("the latest failInfo:{}", JSON.toJSONString(failRequestMap)); + log.info("the latest failInfo:{}", JsonTools.toJSONString(failRequestMap)); } @@ -211,7 +211,7 @@ private String buildKey(String url, String methodType) { * delete key of map. */ private static void deleteKeyOfMap(Map map, String rkey) { - log.info("start deleteKeyOfMap. rkey:{} map:{}", rkey, JSON.toJSONString(map)); + log.info("start deleteKeyOfMap. rkey:{} map:{}", rkey, JsonTools.toJSONString(map)); Iterator iter = map.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); @@ -220,7 +220,7 @@ private static void deleteKeyOfMap(Map map, String rkey) { iter.remove(); } } - log.info("end deleteKeyOfMap. rkey:{} map:{}", rkey, JSON.toJSONString(map)); + log.info("end deleteKeyOfMap. rkey:{} map:{}", rkey, JsonTools.toJSONString(map)); } @@ -229,11 +229,11 @@ private static void deleteKeyOfMap(Map map, String rkey) { */ private FrontUrlInfo buildFrontUrl(ArrayList list, String uri, HttpMethod httpMethod) { Collections.shuffle(list);//random one - log.info("====================map list:{}",JSON.toJSONString(list)); + log.info("====================map list:{}",JsonTools.toJSONString(list)); Iterator iterator = list.iterator(); while (iterator.hasNext()) { FrontGroup frontGroup = iterator.next(); - log.info("============frontGroup:{}",JSON.toJSONString(frontGroup)); + log.info("============frontGroup:{}",JsonTools.toJSONString(frontGroup)); FrontUrlInfo frontUrlInfo = new FrontUrlInfo(); frontUrlInfo.setFrontId(frontGroup.getFrontId()); @@ -263,7 +263,7 @@ public static HttpEntity buildHttpEntity(Object param) { headers.setContentType(MediaType.APPLICATION_JSON_UTF8); String paramStr = null; if (Objects.nonNull(param)) { - paramStr = JSON.toJSONString(param); + paramStr = JsonTools.toJSONString(param); } HttpEntity requestEntity = new HttpEntity(paramStr, headers); return requestEntity; @@ -349,14 +349,16 @@ private T restTemplateExchange(int groupId, String uri, HttpMethod method, log.info("continue next front", ex); continue; } catch (HttpStatusCodeException ex) { - JSONObject error = JSONObject.parseObject(ex.getResponseBodyAsString()); - log.error("http request fail. error:{}", JSON.toJSONString(error)); - if (error.containsKey("code") && error.containsKey("errorMessage")) { - throw new NodeMgrException(error.getInteger("code"), - error.getString("errorMessage"), ex); + JsonNode error = JsonTools.stringToJsonNode(ex.getResponseBodyAsString()); + log.error("http request fail. error:{}", JsonTools.toJSONString(error)); + try { + int code = error.get("code").intValue(); + String errorMessage = error.get("errorMessage").asText(); + frontService.updateFrontWithInternal(frontUrlInfo.getFrontId(), DataStatus.INVALID.getValue()); + throw new NodeMgrException(code, errorMessage); + } catch (NullPointerException e) { + throw new NodeMgrException(ConstantCode.REQUEST_FRONT_FAIL); } - frontService.updateFrontWithInternal(frontUrlInfo.getFrontId(), DataStatus.INVALID.getValue()); - throw new NodeMgrException(ConstantCode.REQUEST_FRONT_FAIL.getCode(), error.getString("message")); } } return null; diff --git a/src/main/java/com/webank/webase/node/mgr/group/GroupController.java b/src/main/java/com/webank/webase/node/mgr/group/GroupController.java index f363aa089..14c4ab205 100644 --- a/src/main/java/com/webank/webase/node/mgr/group/GroupController.java +++ b/src/main/java/com/webank/webase/node/mgr/group/GroupController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.group; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; @@ -86,7 +86,7 @@ public BaseResponse getGroupGeneral(@PathVariable("groupId") Integer groupId) baseResponse.setData(groupGeneral); log.info("end getGroupGeneral useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -112,7 +112,7 @@ public BasePageResponse getAllGroup() throws NodeMgrException { log.info("end getAllGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(pagesponse)); + JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -149,7 +149,7 @@ public BasePageResponse getAllGroupIncludeInvalidGroup(@PathVariable(value = "pa log.info("end getAllGroupIncludeInvalidGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(pagesponse)); + JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -175,7 +175,7 @@ public BaseResponse getAllGroupOfStatus(@PathVariable("groupStatus") Integer gro log.info("end getAllGroupOfStatus useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(response)); + JsonTools.toJSONString(response)); return response; } @@ -194,7 +194,7 @@ public BaseResponse getTransDaily(@PathVariable("groupId") Integer groupId) thro log.info("end getAllGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(pagesponse)); + JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -254,7 +254,7 @@ public Object operateGroup(@PathVariable("nodeId") String nodeId, @RequestBody @ Object groupHandleResult = groupService.operateGroup(nodeId, groupId, type); log.info("end operateGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(groupHandleResult)); + JsonTools.toJSONString(groupHandleResult)); return groupHandleResult; } @@ -274,7 +274,7 @@ public BaseResponse getGroupStatusList(@Valid @RequestBody ReqGroupStatus reqGro baseResponse.setData(resList); log.info("end getGroupStatusMap useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -294,7 +294,7 @@ public BaseResponse batchStartGroup(@RequestBody @Valid ReqBatchStartGroup req, baseResponse.setData(operateResultList); log.info("end batchStartGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -309,7 +309,7 @@ public BaseResponse updateGroup() throws NodeMgrException { groupService.resetGroupList(); log.info("end updateGroup useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -324,7 +324,7 @@ public BaseResponse deleteGroupData(@PathVariable("groupId") Integer groupId) { groupService.removeAllDataByGroupId(groupId); log.warn("end deleteGroupData useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(baseResponse)); + JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/group/GroupService.java b/src/main/java/com/webank/webase/node/mgr/group/GroupService.java index efae386b6..a2dbd7784 100644 --- a/src/main/java/com/webank/webase/node/mgr/group/GroupService.java +++ b/src/main/java/com/webank/webase/node/mgr/group/GroupService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.group; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.enums.GroupStatus; @@ -117,7 +117,7 @@ public List getGroupList(Integer groupStatus) throws NodeMgrException { try { List groupList = groupMapper.getList(groupStatus); - log.debug("end getGroupList groupList:{}", JSON.toJSONString(groupList)); + log.debug("end getGroupList groupList:{}", JsonTools.toJSONString(groupList)); return groupList; } catch (RuntimeException ex) { log.error("fail getGroupList", ex); @@ -166,7 +166,7 @@ public List queryLatestStatisticalTrans() throws Node List listStatisticalTrans = groupMapper .queryLatestStatisticalTrans(); log.debug("end queryLatestStatisticalTrans listStatisticalTrans:{}", - JSON.toJSONString(listStatisticalTrans)); + JsonTools.toJSONString(listStatisticalTrans)); return listStatisticalTrans; } catch (RuntimeException ex) { log.error("fail queryLatestStatisticalTrans", ex); @@ -377,7 +377,7 @@ private void checkAndUpdateGroupStatus(Set allGroupOnChain) { } } catch (Exception ex) { - log.info("fail check group. localGroup:{}", JSON.toJSONString(localGroup)); + log.info("fail check group. localGroup:{}", JsonTools.toJSONString(localGroup)); continue; } @@ -834,7 +834,7 @@ public TbGroup saveGroup(int groupId, int nodeCount, String description, int gro new TbGroup(groupId, groupName, nodeCount, description, groupType, groupStatus); tbGroup.setGroupTimestamp(timestamp.toString(10)); - tbGroup.setNodeIdList(JSON.toJSONString(nodeIdList)); + tbGroup.setNodeIdList(JsonTools.toJSONString(nodeIdList)); groupMapper.save(tbGroup); // create table by group id tableService.newTableByGroupId(groupId); diff --git a/src/main/java/com/webank/webase/node/mgr/method/MethodController.java b/src/main/java/com/webank/webase/node/mgr/method/MethodController.java index ffd2f73cc..cfa1c64b6 100644 --- a/src/main/java/com/webank/webase/node/mgr/method/MethodController.java +++ b/src/main/java/com/webank/webase/node/mgr/method/MethodController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.method; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -54,12 +54,12 @@ public BaseResponse addMethod(@RequestBody @Valid NewMethodInputParam newMethodI BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start addMethod. startTime:{} newMethodInputParam:{}", - startTime.toEpochMilli(), JSON.toJSONString(newMethodInputParam)); + startTime.toEpochMilli(), JsonTools.toJSONString(newMethodInputParam)); methodService.saveMethod(newMethodInputParam); log.info("end addMethod. useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -78,7 +78,7 @@ public BaseResponse getBymethodId(@PathVariable("groupId") Integer groupId, baseResponse.setData(tbMethod); log.info("end addMethodInfo. useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorController.java b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorController.java index 35599a3d7..3a8515582 100644 --- a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorController.java +++ b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.monitor; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -54,7 +54,7 @@ public BaseResponse monitorUserList(@PathVariable("groupId") Integer groupId) response.setData(listOfUser); log.info("end monitorUserList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } @@ -74,7 +74,7 @@ public BaseResponse monitorInterfaceList(@PathVariable("groupId") Integer groupI response.setData(listOfInterface); log.info("end monitorInterfaceList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } @@ -99,7 +99,7 @@ public BaseResponse monitorTransList(@PathVariable("groupId") Integer groupId, .qureyMonitorTransList(groupId, userName, startDate, endDate, interfaceName); log.info("end monitorTransList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } @@ -129,7 +129,7 @@ public BasePageResponse unusualUserList(@PathVariable("groupId") Integer groupId } log.info("end unusualUserList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -159,7 +159,7 @@ public BasePageResponse unusualContractList(@PathVariable("groupId") Integer gro } log.info("end unusualContractList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorService.java b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorService.java index 5a5f96337..42813e564 100644 --- a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorService.java +++ b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorService.java @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.enums.MonitorUserType; @@ -211,7 +211,7 @@ public List qureyMonitorUserList(Integer groupId) throws NodeMgrExcep .monitorUserList(TableName.MONITOR.getTableName(groupId)); log.debug("end qureyMonitorUserList monitorUserList:{}", - JSON.toJSONString(monitorUserList)); + JsonTools.toJSONString(monitorUserList)); return monitorUserList; } @@ -225,7 +225,7 @@ public List qureyMonitorInterfaceList(Integer groupId, String userNam .monitorInterfaceList(TableName.MONITOR.getTableName(groupId), userName); log.debug("end qureyMonitorInterfaceList monitorInterfaceList:{}", - JSON.toJSONString(monitorInterfaceList)); + JsonTools.toJSONString(monitorInterfaceList)); return monitorInterfaceList; } @@ -282,7 +282,7 @@ public List qureyUnusualUserList(Integer groupId, String userNa List listOfUnusualUser = monitorMapper.listOfUnusualUser(param); log.debug("end qureyUnusualUserList listOfUnusualUser:{}", - JSON.toJSONString(listOfUnusualUser)); + JsonTools.toJSONString(listOfUnusualUser)); return listOfUnusualUser; } @@ -318,7 +318,7 @@ public List qureyUnusualContractList(Integer groupId, .listOfUnusualContract(param); log.debug("end qureyUnusualContractList listOfUnusualContract:{}", - JSON.toJSONString(listOfUnusualContract)); + JsonTools.toJSONString(listOfUnusualContract)); return listOfUnusualContract; } diff --git a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorTransactionService.java b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorTransactionService.java index 03c6f08fd..5dbfaa722 100644 --- a/src/main/java/com/webank/webase/node/mgr/monitor/MonitorTransactionService.java +++ b/src/main/java/com/webank/webase/node/mgr/monitor/MonitorTransactionService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.monitor; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.enums.TableName; import com.webank.webase.node.mgr.transaction.TransHashService; import lombok.extern.log4j.Log4j2; @@ -36,7 +36,7 @@ public class MonitorTransactionService { public void dataAddAndUpdate(int groupId, TbMonitor tbMonitor) { TbMonitor dbInfo = this.queryTbMonitor(groupId, tbMonitor); if (dbInfo == null) { - log.info("====== data is not exist, add tbMonitor:{}", JSON.toJSONString(tbMonitor)); + log.info("====== data is not exist, add tbMonitor:{}", JsonTools.toJSONString(tbMonitor)); this.addRow(groupId, tbMonitor); } else { String[] txHashsArr = dbInfo.getTransHashs().split(","); diff --git a/src/main/java/com/webank/webase/node/mgr/node/NodeController.java b/src/main/java/com/webank/webase/node/mgr/node/NodeController.java index 491740cb0..06e672df0 100644 --- a/src/main/java/com/webank/webase/node/mgr/node/NodeController.java +++ b/src/main/java/com/webank/webase/node/mgr/node/NodeController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.node; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -82,7 +82,7 @@ public BasePageResponse queryNodeList(@PathVariable("groupId") Integer groupId, } log.info("end queryNodeList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -108,7 +108,7 @@ public BaseResponse getNodeInfo(@PathVariable("groupId") Integer groupId) baseResponse.setData(tbNode); log.info("end addNodeInfo useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -126,7 +126,7 @@ public BaseResponse getNodeIdList(@PathVariable("groupId") Integer groupId) { baseResponse.setData(res); log.info("end getNodeIdList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } diff --git a/src/main/java/com/webank/webase/node/mgr/node/NodeService.java b/src/main/java/com/webank/webase/node/mgr/node/NodeService.java index 729edd14d..46781c791 100644 --- a/src/main/java/com/webank/webase/node/mgr/node/NodeService.java +++ b/src/main/java/com/webank/webase/node/mgr/node/NodeService.java @@ -13,8 +13,7 @@ */ package com.webank.webase.node.mgr.node; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.DataStatus; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -86,11 +85,11 @@ public void addNodeInfo(Integer groupId, PeerInfo peerInfo) throws NodeMgrExcept * query count of node. */ public Integer countOfNode(NodeParam queryParam) throws NodeMgrException { - log.debug("start countOfNode queryParam:{}", JSON.toJSONString(queryParam)); + log.debug("start countOfNode queryParam:{}", JsonTools.toJSONString(queryParam)); try { Integer nodeCount = nodeMapper.getCount(queryParam); log.debug("end countOfNode nodeCount:{} queryParam:{}", nodeCount, - JSON.toJSONString(queryParam)); + JsonTools.toJSONString(queryParam)); return nodeCount; } catch (RuntimeException ex) { log.error("fail countOfNode . queryParam:{}", queryParam, ex); @@ -103,12 +102,12 @@ public Integer countOfNode(NodeParam queryParam) throws NodeMgrException { * query node list by page. */ public List qureyNodeList(NodeParam queryParam) throws NodeMgrException { - log.debug("start qureyNodeList queryParam:{}", JSON.toJSONString(queryParam)); + log.debug("start qureyNodeList queryParam:{}", JsonTools.toJSONString(queryParam)); // query node list List listOfNode = nodeMapper.getList(queryParam); - log.debug("end qureyNodeList listOfNode:{}", JSON.toJSONString(listOfNode)); + log.debug("end qureyNodeList listOfNode:{}", JsonTools.toJSONString(listOfNode)); return listOfNode; } @@ -135,7 +134,7 @@ public TbNode queryByNodeId(String nodeId) throws NodeMgrException { log.debug("start queryNode nodeId:{}", nodeId); try { TbNode nodeRow = nodeMapper.queryByNodeId(nodeId); - log.debug("end queryNode nodeId:{} TbNode:{}", nodeId, JSON.toJSONString(nodeRow)); + log.debug("end queryNode nodeId:{} TbNode:{}", nodeId, JsonTools.toJSONString(nodeRow)); return nodeRow; } catch (RuntimeException ex) { log.error("fail queryNode . nodeId:{}", nodeId, ex); @@ -148,7 +147,7 @@ public TbNode queryByNodeId(String nodeId) throws NodeMgrException { * update node info. */ public void updateNode(TbNode tbNode) throws NodeMgrException { - log.debug("start updateNodeInfo param:{}", JSON.toJSONString(tbNode)); + log.debug("start updateNodeInfo param:{}", JsonTools.toJSONString(tbNode)); Integer affectRow = 0; try { @@ -169,7 +168,7 @@ public void updateNode(TbNode tbNode) throws NodeMgrException { * query node info. */ public TbNode queryNodeInfo(NodeParam nodeParam) { - log.debug("start queryNodeInfo nodeParam:{}", JSON.toJSONString(nodeParam)); + log.debug("start queryNodeInfo nodeParam:{}", JsonTools.toJSONString(nodeParam)); TbNode tbNode = nodeMapper.queryNodeInfo(nodeParam); log.debug("end queryNodeInfo result:{}", tbNode); return tbNode; @@ -303,19 +302,24 @@ private List getPeerOfConsensusStatus(int groupId) { log.debug("getPeerOfConsensusStatus is null: {}", consensusStatusJson); return null; } - JSONArray jsonArr = JSONArray.parseArray(consensusStatusJson); - List dataIsList = jsonArr.stream().filter(jsonObj -> jsonObj instanceof List) - .map(arr -> { - try { - Object obj = JSONArray.parseArray(JSON.toJSONString(arr)).get(0); - NodeMgrTools.object2JavaBean(obj, PeerOfConsensusStatus.class); - } catch (Exception e) { - return null; + List jsonArr = JsonTools.toJavaObject(consensusStatusJson, List.class); + if (jsonArr == null) { + log.error("getPeerOfConsensusStatus error"); + throw new NodeMgrException(ConstantCode.FAIL_PARSE_JSON); + } + List dataIsList = new ArrayList<>(); + for (int i = 0; i < jsonArr.size(); i++ ) { + if (jsonArr.get(i) instanceof List) { + List tempList = JsonTools.toJavaObjectList( + JsonTools.toJSONString(jsonArr.get(i)), PeerOfConsensusStatus.class); + if (tempList != null) { + dataIsList.addAll(tempList); + } else { + throw new NodeMgrException(ConstantCode.FAIL_PARSE_JSON); } - return arr; - }).collect(Collectors.toList()); - return JSONArray - .parseArray(JSON.toJSONString(dataIsList.get(0)), PeerOfConsensusStatus.class); + } + } + return dataIsList; } /** diff --git a/src/main/java/com/webank/webase/node/mgr/performance/PerformanceController.java b/src/main/java/com/webank/webase/node/mgr/performance/PerformanceController.java index f00d3fac4..6be5c10af 100644 --- a/src/main/java/com/webank/webase/node/mgr/performance/PerformanceController.java +++ b/src/main/java/com/webank/webase/node/mgr/performance/PerformanceController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.performance; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -69,7 +69,7 @@ public BaseResponse getPerformanceRatio(@PathVariable("frontId") Integer frontId gap); response.setData(rspObj); log.info("end getPerformanceRatio. useTime:{} response:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } @@ -87,7 +87,7 @@ public BaseResponse getPerformanceConfig(@PathVariable("frontId") Integer frontI Object frontRsp = performanceService.getPerformanceConfig(frontId); response.setData(frontRsp); log.info("end getPerformanceConfig. useTime:{} response:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(response)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(response)); return response; } } diff --git a/src/main/java/com/webank/webase/node/mgr/performance/PerformanceService.java b/src/main/java/com/webank/webase/node/mgr/performance/PerformanceService.java index 4bd89786f..0e45a6c3b 100644 --- a/src/main/java/com/webank/webase/node/mgr/performance/PerformanceService.java +++ b/src/main/java/com/webank/webase/node/mgr/performance/PerformanceService.java @@ -18,7 +18,7 @@ import static com.webank.webase.node.mgr.frontinterface.FrontRestTools.FRONT_PERFORMANCE_CONFIG; import static com.webank.webase.node.mgr.frontinterface.FrontRestTools.FRONT_PERFORMANCE_RATIO; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.properties.ConstantProperties; @@ -76,7 +76,7 @@ public Object getPerformanceRatio(Integer frontId, LocalDateTime beginDate, log.info("getPerformanceRatio request url:{}", url); Object rspObj = genericRestTemplate.getForObject(url, Object.class); - log.debug("end getPerformanceRatio. rspObj:{}", JSON.toJSONString(rspObj)); + log.debug("end getPerformanceRatio. rspObj:{}", JsonTools.toJSONString(rspObj)); return rspObj; } @@ -99,7 +99,7 @@ public Object getPerformanceConfig(int frontId) { log.info("getPerformanceConfig request url:{}", url); Object rspObj = genericRestTemplate.getForObject(url, Object.class); - log.debug("end getPerformanceConfig. frontRsp:{}", JSON.toJSONString(rspObj)); + log.debug("end getPerformanceConfig. frontRsp:{}", JsonTools.toJSONString(rspObj)); return rspObj; } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledController.java b/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledController.java index c035542ff..7558316f5 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledController.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.properties.ConstantProperties; @@ -58,7 +58,7 @@ public Object listCns( Object result = precompiledService.listCnsService(groupId, contractNameAndVersion, pageSize, pageNumber); log.info("end listCns useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(result)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(result)); return result; } @@ -77,7 +77,7 @@ public Object getNodeList( Object result = precompiledService.getNodeListService(groupId, pageSize, pageNumber); log.info("end getNodeList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(result)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(result)); return result; } @@ -88,12 +88,12 @@ public Object nodeManage(@RequestBody @Valid ConsensusHandle consensusHandle, checkBindResult(result); Instant startTime = Instant.now(); log.info("start nodeManage startTime:{} consensusHandle:{}", startTime.toEpochMilli(), - JSON.toJSONString(consensusHandle)); + JsonTools.toJSONString(consensusHandle)); Object res = precompiledService.nodeManageService(consensusHandle); log.info("end nodeManage useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } @@ -108,12 +108,12 @@ public Object crud(@RequestBody @Valid CrudHandle crudHandle, checkBindResult(result); Instant startTime = Instant.now(); log.info("start crud startTime:{} crudHandle:{}", startTime.toEpochMilli(), - JSON.toJSONString(crudHandle)); + JsonTools.toJSONString(crudHandle)); Object res = precompiledService.crudService(crudHandle); log.info("end crud useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledService.java b/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledService.java index 8200a7d17..1307f4fec 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledService.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/PrecompiledService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.tools.HttpRequestTools; @@ -63,7 +63,7 @@ public Object listCnsService(int groupId, String contractNameAndVersion, int pag Object frontRsp = frontRestTools.getForEntity(groupId, uri, Object.class); - log.debug("end listCnsService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end listCnsService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -80,7 +80,7 @@ public Object getNodeListService(int groupId, int pageSize, int pageNumber) { uri = HttpRequestTools.getQueryUri(FrontRestTools.URI_CONSENSUS_LIST, map); Object frontRsp = null; frontRsp = frontRestTools.getForEntity(groupId, uri, Object.class); - log.debug("end getNodeListService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end getNodeListService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -90,7 +90,7 @@ public Object getNodeListService(int groupId, int pageSize, int pageNumber) { */ public Object nodeManageService(ConsensusHandle consensusHandle) { - log.debug("start nodeManageService. consensusHandle:{}", JSON.toJSONString(consensusHandle)); + log.debug("start nodeManageService. consensusHandle:{}", JsonTools.toJSONString(consensusHandle)); if (Objects.isNull(consensusHandle)) { log.error("fail nodeManageService. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -101,7 +101,7 @@ public Object nodeManageService(ConsensusHandle consensusHandle) { Object frontRsp = frontRestTools.postForEntity( groupId, FrontRestTools.URI_CONSENSUS, consensusHandle, Object.class); - log.debug("end nodeManageService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end nodeManageService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -110,7 +110,7 @@ public Object nodeManageService(ConsensusHandle consensusHandle) { */ public Object crudService(CrudHandle crudHandle) { - log.debug("start crudService. crudHandle:{}", JSON.toJSONString(crudHandle)); + log.debug("start crudService. crudHandle:{}", JsonTools.toJSONString(crudHandle)); if (Objects.isNull(crudHandle)) { log.error("fail crudService. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -121,7 +121,7 @@ public Object crudService(CrudHandle crudHandle) { Object frontRsp = frontRestTools.postForEntity( groupId, FrontRestTools.URI_CRUD, crudHandle, Object.class); - log.debug("end crudService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end crudService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageController.java b/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageController.java index bfbb7b8e1..9f2fc040c 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageController.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled.permission; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; @@ -69,7 +69,7 @@ public Object listPermissionMgrState( List2Page list2Page = new List2Page(resultList, pageSize, pageNumber); List finalList = list2Page.getPagedList(); log.info("end listPermissionMgrState useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(finalList)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(finalList)); return new BasePageResponse(ConstantCode.SUCCESS, finalList, totalCount); } @@ -91,7 +91,7 @@ public Object listPermissionManager( Object result = permissionManageService.listPermissionPaged(groupId, permissionType, tableName, pageSize, pageNumber); log.info("end listPermissionManager useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(result)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(result)); return result; } @@ -112,7 +112,7 @@ public Object listFullPermissionManager( Object result = permissionManageService.listPermissionFull(groupId, permissionType, tableName); log.info("end listFullPermissionManager useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(result)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(result)); return result; } @@ -127,11 +127,11 @@ public Object updatePermission(@RequestBody @Valid PermissionParam permissionPar checkBindResult(result); Instant startTime = Instant.now(); log.info("start updatePermission startTime:{} permissionParam:{}", startTime.toEpochMilli(), - JSON.toJSONString(permissionParam)); + JsonTools.toJSONString(permissionParam)); Object res = permissionManageService.updatePermissionState(permissionParam); log.info("end updatePermission useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } @@ -143,12 +143,12 @@ public Object grantPermission(@RequestBody @Valid PermissionParam permissionPara checkBindResult(result); Instant startTime = Instant.now(); log.info("start grantPermission startTime:{} permissionParam:{}", startTime.toEpochMilli(), - JSON.toJSONString(permissionParam)); + JsonTools.toJSONString(permissionParam)); Object res = permissionManageService.grantPermission(permissionParam); log.info("end grantPermission useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } @@ -163,12 +163,12 @@ public Object revokePermission(@RequestBody @Valid PermissionParam permissionPar checkBindResult(result); Instant startTime = Instant.now(); log.info("start revokePermission startTime:{} permissionParam:{}", startTime.toEpochMilli(), - JSON.toJSONString(permissionParam)); + JsonTools.toJSONString(permissionParam)); Object res = permissionManageService.revokePermission(permissionParam); log.info("end revokePermission useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageService.java b/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageService.java index e85973420..0151a99e2 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageService.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/permission/PermissionManageService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled.permission; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -68,7 +68,7 @@ public Map listPermissionState(int groupId) { resultMap.put(address, emptyState); } } - log.debug("end listPermissionState. frontRsp:{}", JSON.toJSONString(resultMap)); + log.debug("end listPermissionState. frontRsp:{}", JsonTools.toJSONString(resultMap)); return resultMap; } @@ -91,7 +91,7 @@ public Map listPermissionStateFull(int groupId) { map.put("groupId", String.valueOf(groupId)); uri = HttpRequestTools.getQueryUri(FrontRestTools.URI_PERMISSION_SORTED_FULL_LIST, map); Map frontRsp = (Map) frontRestTools.getForEntity(groupId, uri, Object.class); - log.debug("end listPermissionStateFull. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end listPermissionStateFull. frontRsp:{}", JsonTools.toJSONString(frontRsp)); Map result = (Map) frontRsp.get("data"); return result; } @@ -115,7 +115,7 @@ public Object listPermissionPaged(int groupId, String permissionType, String tab } Object frontRsp = frontRestTools.getForEntity(groupId, uri, Object.class); - log.debug("end listPermissionPaged. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end listPermissionPaged. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -135,7 +135,7 @@ public BasePageResponse listPermissionFull(int groupId, String permissionType, S uri = HttpRequestTools.getQueryUri(FrontRestTools.URI_PERMISSION_FULL_LIST, map); } BasePageResponse frontRsp = frontRestTools.getForEntity(groupId, uri, BasePageResponse.class); - log.debug("end listPermissionFull. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end listPermissionFull. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -143,7 +143,7 @@ public BasePageResponse listPermissionFull(int groupId, String permissionType, S * repost permission grant */ public Object updatePermissionState(PermissionParam permissionParam) { - log.debug("start updatePermissionState. permissionParam:{}", JSON.toJSONString(permissionParam)); + log.debug("start updatePermissionState. permissionParam:{}", JsonTools.toJSONString(permissionParam)); if (Objects.isNull(permissionParam)) { log.error("fail updatePermissionState. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -154,12 +154,12 @@ public Object updatePermissionState(PermissionParam permissionParam) { Object frontRsp = frontRestTools.postForEntity( groupId, FrontRestTools.URI_PERMISSION_SORTED_LIST, permissionParam, Object.class); - log.debug("end updatePermissionState. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end updatePermissionState. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } public Object grantPermission(PermissionParam permissionParam) { - log.debug("start grantPermission. permissionParam:{}", JSON.toJSONString(permissionParam)); + log.debug("start grantPermission. permissionParam:{}", JsonTools.toJSONString(permissionParam)); if (Objects.isNull(permissionParam)) { log.error("fail grantPermission. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -170,12 +170,12 @@ public Object grantPermission(PermissionParam permissionParam) { Object frontRsp = frontRestTools.postForEntity( groupId, FrontRestTools.URI_PERMISSION, permissionParam, Object.class); - log.debug("end grantPermission. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end grantPermission. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } public Object revokePermission(PermissionParam permissionParam) { - log.debug("start revokePermission. permissionParam:{}", JSON.toJSONString(permissionParam)); + log.debug("start revokePermission. permissionParam:{}", JsonTools.toJSONString(permissionParam)); if (Objects.isNull(permissionParam)) { log.error("fail revokePermission. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -186,7 +186,7 @@ public Object revokePermission(PermissionParam permissionParam) { Object frontRsp = frontRestTools.deleteForEntity( groupId, FrontRestTools.URI_PERMISSION, permissionParam, Object.class); - log.debug("end revokePermission. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end revokePermission. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigController.java b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigController.java index 6ef90e858..a4ffb6646 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigController.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled.sysconf; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.properties.ConstantProperties; @@ -57,7 +57,7 @@ public Object getSysConfigList( Object result = precompiledSysConfigService.getSysConfigListService(groupId, pageSize, pageNumber); log.info("end getSysConfigList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(result)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(result)); return result; } @@ -71,12 +71,12 @@ public Object setSysConfigByKeyService(@RequestBody @Valid SysConfigParam sysCon checkBindResult(result); Instant startTime = Instant.now(); log.info("start setSysConfigByKeyService startTime:{} sysConfigParam:{}", startTime.toEpochMilli(), - JSON.toJSONString(sysConfigParam)); + JsonTools.toJSONString(sysConfigParam)); Object res = precompiledSysConfigService.setSysConfigByKeyService(sysConfigParam); log.info("end setSysConfigByKeyService useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(res)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(res)); return res; } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigService.java b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigService.java index db3bdd911..7783f9e9f 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigService.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/PrecompiledSysConfigService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.precompiled.sysconf; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.tools.HttpRequestTools; @@ -56,7 +56,7 @@ public Object getSysConfigListService(int groupId, int pageSize, int pageNumber) String uri = HttpRequestTools.getQueryUri(FrontRestTools.URI_SYS_CONFIG_LIST, map); Object frontRsp = frontRestTools.getForEntity(groupId, uri, Object.class); - log.debug("end getSysConfigListService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end getSysConfigListService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } @@ -66,7 +66,7 @@ public Object getSysConfigListService(int groupId, int pageSize, int pageNumber) */ public Object setSysConfigByKeyService(SysConfigParam sysConfigParam) { - log.debug("start setSysConfigByKeyService. sysConfigParam:{}", JSON.toJSONString(sysConfigParam)); + log.debug("start setSysConfigByKeyService. sysConfigParam:{}", JsonTools.toJSONString(sysConfigParam)); if (Objects.isNull(sysConfigParam)) { log.error("fail setSysConfigByKeyService. request param is null"); throw new NodeMgrException(ConstantCode.INVALID_PARAM_INFO); @@ -77,7 +77,7 @@ public Object setSysConfigByKeyService(SysConfigParam sysConfigParam) { Object frontRsp = frontRestTools.postForEntity( groupId, FrontRestTools.URI_SYS_CONFIG, sysConfigParam, Object.class); - log.debug("end setSysConfigByKeyService. frontRsp:{}", JSON.toJSONString(frontRsp)); + log.debug("end setSysConfigByKeyService. frontRsp:{}", JsonTools.toJSONString(frontRsp)); return frontRsp; } diff --git a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/SysConfigParam.java b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/SysConfigParam.java index badf7da97..c0f7e0aed 100644 --- a/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/SysConfigParam.java +++ b/src/main/java/com/webank/webase/node/mgr/precompiled/sysconf/SysConfigParam.java @@ -20,7 +20,7 @@ @Data public class SysConfigParam { - private Long id; +// private Long id; private int groupId; private String fromAddress; private String signUserId; diff --git a/src/main/java/com/webank/webase/node/mgr/role/RoleController.java b/src/main/java/com/webank/webase/node/mgr/role/RoleController.java index 16aec6c55..f733e4ebb 100644 --- a/src/main/java/com/webank/webase/node/mgr/role/RoleController.java +++ b/src/main/java/com/webank/webase/node/mgr/role/RoleController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.role; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -75,7 +75,7 @@ public BasePageResponse queryRoleList( log.info("end queryRoleList useTime:{} result:{}", Duration.between(startTime, Instant.now()).toMillis(), - JSON.toJSONString(pagesponse)); + JsonTools.toJSONString(pagesponse)); return pagesponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/role/RoleService.java b/src/main/java/com/webank/webase/node/mgr/role/RoleService.java index f703ecb2a..0a0759d0f 100644 --- a/src/main/java/com/webank/webase/node/mgr/role/RoleService.java +++ b/src/main/java/com/webank/webase/node/mgr/role/RoleService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.role; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import java.util.List; @@ -37,7 +37,7 @@ public class RoleService { * query role count. */ public int countOfRole(RoleListParam param) { - log.debug("start countOfRole. param:{} ", JSON.toJSONString(param)); + log.debug("start countOfRole. param:{} ", JsonTools.toJSONString(param)); Integer roleCount = roleMapper.countOfRole(param); int count = roleCount == null ? 0 : roleCount.intValue(); log.debug("end countOfRole. count:{} ", count); @@ -48,9 +48,9 @@ public int countOfRole(RoleListParam param) { * query role . */ public List listOfRole(RoleListParam param) { - log.debug("start listOfRole. param:{} ", JSON.toJSONString(param)); + log.debug("start listOfRole. param:{} ", JsonTools.toJSONString(param)); List list = roleMapper.listOfRole(param); - log.debug("end listOfRole. list:{} ", JSON.toJSONString(list)); + log.debug("end listOfRole. list:{} ", JsonTools.toJSONString(list)); return list; } @@ -60,7 +60,7 @@ public List listOfRole(RoleListParam param) { public TbRole queryRoleById(Integer roleId) { log.debug("start queryRoleById. roleId:{} ", roleId); TbRole roleInfo = roleMapper.queryRoleById(roleId); - log.debug("end queryRoleById. roleInfo:{} ", JSON.toJSONString(roleInfo)); + log.debug("end queryRoleById. roleInfo:{} ", JsonTools.toJSONString(roleInfo)); return roleInfo; } diff --git a/src/main/java/com/webank/webase/node/mgr/security/AccountDetailsService.java b/src/main/java/com/webank/webase/node/mgr/security/AccountDetailsService.java index 58ec69400..70c91a59d 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/AccountDetailsService.java +++ b/src/main/java/com/webank/webase/node/mgr/security/AccountDetailsService.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.security; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.account.AccountService; import com.webank.webase.node.mgr.account.entity.TbAccountInfo; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -46,10 +46,10 @@ public UserDetails loadUserByUsername(String account) throws UsernameNotFoundExc try { accountRow = accountService.queryByAccount(account); } catch (Exception e) { - throw new UsernameNotFoundException(JSON.toJSONString(ConstantCode.DB_EXCEPTION)); + throw new UsernameNotFoundException(JsonTools.toJSONString(ConstantCode.DB_EXCEPTION)); } if (null == accountRow) { - throw new UsernameNotFoundException(JSON.toJSONString(ConstantCode.INVALID_ACCOUNT_NAME)); + throw new UsernameNotFoundException(JsonTools.toJSONString(ConstantCode.INVALID_ACCOUNT_NAME)); } // add role diff --git a/src/main/java/com/webank/webase/node/mgr/security/JsonAccessDeniedHandler.java b/src/main/java/com/webank/webase/node/mgr/security/JsonAccessDeniedHandler.java index 4fb05f4f8..2880f142b 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/JsonAccessDeniedHandler.java +++ b/src/main/java/com/webank/webase/node/mgr/security/JsonAccessDeniedHandler.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.security; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; import java.io.IOException; @@ -39,7 +39,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, BaseResponse baseResponse = new BaseResponse(ConstantCode.ACCESS_DENIED); response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write(JSON.toJSONString(baseResponse)); + response.getWriter().write(JsonTools.toJSONString(baseResponse)); } } diff --git a/src/main/java/com/webank/webase/node/mgr/security/JsonAuthenticationEntryPoint.java b/src/main/java/com/webank/webase/node/mgr/security/JsonAuthenticationEntryPoint.java index 4d6f1cd27..f68546db6 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/JsonAuthenticationEntryPoint.java +++ b/src/main/java/com/webank/webase/node/mgr/security/JsonAuthenticationEntryPoint.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.security; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; import java.io.IOException; @@ -38,7 +38,7 @@ public void commence(HttpServletRequest request, HttpServletResponse response, log.debug("user not logged in"); BaseResponse baseResponse = new BaseResponse(ConstantCode.USER_NOT_LOGGED_IN); response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write(JSON.toJSONString(baseResponse)); + response.getWriter().write(JsonTools.toJSONString(baseResponse)); } } diff --git a/src/main/java/com/webank/webase/node/mgr/security/JsonLogoutSuccessHandler.java b/src/main/java/com/webank/webase/node/mgr/security/JsonLogoutSuccessHandler.java index b07167b63..30914a45d 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/JsonLogoutSuccessHandler.java +++ b/src/main/java/com/webank/webase/node/mgr/security/JsonLogoutSuccessHandler.java @@ -21,7 +21,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; import org.springframework.stereotype.Component; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; import com.webank.webase.node.mgr.base.tools.NodeMgrTools; @@ -42,13 +42,13 @@ public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse resp try { token = NodeMgrTools.getToken(request); } catch (NodeMgrException ex) { - NodeMgrTools.responseString(response, JSON.toJSONString(ex.getRetCode())); + NodeMgrTools.responseString(response, JsonTools.toJSONString(ex.getRetCode())); return; } //remove token tokenService.deleteToken(token, null); log.debug("logout success"); - NodeMgrTools.responseString(response, JSON.toJSONString(ConstantCode.SUCCESS)); + NodeMgrTools.responseString(response, JsonTools.toJSONString(ConstantCode.SUCCESS)); } } diff --git a/src/main/java/com/webank/webase/node/mgr/security/LoginFailHandler.java b/src/main/java/com/webank/webase/node/mgr/security/LoginFailHandler.java index 8c9dd4054..992bab413 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/LoginFailHandler.java +++ b/src/main/java/com/webank/webase/node/mgr/security/LoginFailHandler.java @@ -13,8 +13,7 @@ */ package com.webank.webase.node.mgr.security; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.code.RetCode; import com.webank.webase.node.mgr.base.entity.BaseResponse; @@ -37,11 +36,11 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo String errorMsg = ex.getMessage(); RetCode retCode = ConstantCode.PASSWORD_ERROR; // default password fail if (errorMsg.contains("code")) { - retCode = JSONObject.parseObject(errorMsg, RetCode.class); + retCode = JsonTools.toJavaObject(errorMsg, RetCode.class); } BaseResponse baseResponse = new BaseResponse(retCode); response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write(JSON.toJSONString(baseResponse)); + response.getWriter().write(JsonTools.toJSONString(baseResponse)); } } diff --git a/src/main/java/com/webank/webase/node/mgr/security/LoginSuccessHandler.java b/src/main/java/com/webank/webase/node/mgr/security/LoginSuccessHandler.java index c53c3391b..990c9a974 100644 --- a/src/main/java/com/webank/webase/node/mgr/security/LoginSuccessHandler.java +++ b/src/main/java/com/webank/webase/node/mgr/security/LoginSuccessHandler.java @@ -25,7 +25,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.stereotype.Component; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.account.AccountService; import com.webank.webase.node.mgr.account.entity.TbAccountInfo; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -64,7 +64,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); baseResponse.setData(rsp); - String backStr = JSON.toJSONString(baseResponse); + String backStr = JsonTools.toJSONString(baseResponse); log.debug("login backInfo:{}", backStr); response.setContentType("application/json;charset=UTF-8"); diff --git a/src/main/java/com/webank/webase/node/mgr/transaction/TransHashController.java b/src/main/java/com/webank/webase/node/mgr/transaction/TransHashController.java index 438bf2e18..c13083354 100644 --- a/src/main/java/com/webank/webase/node/mgr/transaction/TransHashController.java +++ b/src/main/java/com/webank/webase/node/mgr/transaction/TransHashController.java @@ -15,7 +15,7 @@ */ package com.webank.webase.node.mgr.transaction; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.entity.BaseResponse; import com.webank.webase.node.mgr.base.code.ConstantCode; @@ -24,7 +24,7 @@ import com.webank.webase.node.mgr.group.GroupService; import com.webank.webase.node.mgr.transaction.entity.TbTransHash; import com.webank.webase.node.mgr.transaction.entity.TransListParam; -import com.webank.webase.node.mgr.transaction.entity.TransReceipt; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; import com.webank.webase.node.mgr.transaction.entity.TransactionInfo; import java.math.BigInteger; import java.time.Duration; @@ -73,7 +73,7 @@ public BasePageResponse queryTransList(@PathVariable("groupId") Integer groupId, if(StringUtils.isEmpty(transHash) && blockNumber == null) { count = transHashService.queryCountOfTranByMinus(groupId); } else { - // TODO select count(1) in InnoDb is slow when data gets large + // select count(1) in InnoDb is slow when data gets large, instead use tx_id to record count count = transHashService.queryCountOfTran(groupId, queryParam); } if (count != null && count > 0) { @@ -97,7 +97,7 @@ public BasePageResponse queryTransList(@PathVariable("groupId") Integer groupId, } log.info("end queryBlockList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pageResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pageResponse)); return pageResponse; } @@ -112,10 +112,10 @@ public BaseResponse getTransReceipt(@PathVariable("groupId") Integer groupId, log.info("start getTransReceipt startTime:{} groupId:{} transaction:{}", startTime.toEpochMilli(), groupId, transHash); BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); - TransReceipt transReceipt = transHashService.getTransReceipt(groupId, transHash); + TransactionReceipt transReceipt = transHashService.getTransReceipt(groupId, transHash); baseResponse.setData(transReceipt); log.info("end getTransReceipt useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -133,7 +133,7 @@ public BaseResponse getTransaction(@PathVariable("groupId") Integer groupId, TransactionInfo transInfo = transHashService.getTransaction(groupId, transHash); baseResponse.setData(transInfo); log.info("end getTransaction useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } } diff --git a/src/main/java/com/webank/webase/node/mgr/transaction/TransHashService.java b/src/main/java/com/webank/webase/node/mgr/transaction/TransHashService.java index 51d525ab5..fe3b077cf 100644 --- a/src/main/java/com/webank/webase/node/mgr/transaction/TransHashService.java +++ b/src/main/java/com/webank/webase/node/mgr/transaction/TransHashService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.transaction; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.TableName; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -21,7 +21,7 @@ import com.webank.webase.node.mgr.frontinterface.FrontInterfaceService; import com.webank.webase.node.mgr.transaction.entity.TbTransHash; import com.webank.webase.node.mgr.transaction.entity.TransListParam; -import com.webank.webase.node.mgr.transaction.entity.TransReceipt; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; import com.webank.webase.node.mgr.transaction.entity.TransactionInfo; import java.math.BigInteger; @@ -51,7 +51,7 @@ public class TransHashService { */ public void addTransInfo(int groupId, TbTransHash tbTransHash) throws NodeMgrException { log.debug("start addTransInfo groupId:{} tbTransHash:{}", groupId, - JSON.toJSONString(tbTransHash)); + JsonTools.toJSONString(tbTransHash)); String tableName = TableName.TRANS.getTableName(groupId); transHashMapper.add(tableName, tbTransHash); log.debug("end addTransInfo"); @@ -62,17 +62,17 @@ public void addTransInfo(int groupId, TbTransHash tbTransHash) throws NodeMgrExc */ public List queryTransList(int groupId, TransListParam param) throws NodeMgrException { - log.debug("start queryTransList. TransListParam:{}", JSON.toJSONString(param)); + log.debug("start queryTransList. TransListParam:{}", JsonTools.toJSONString(param)); String tableName = TableName.TRANS.getTableName(groupId); List listOfTran = null; try { listOfTran = transHashMapper.getList(tableName, param); } catch (RuntimeException ex) { - log.error("fail queryBlockList. TransListParam:{} ", JSON.toJSONString(param), ex); + log.error("fail queryBlockList. TransListParam:{} ", JsonTools.toJSONString(param), ex); throw new NodeMgrException(ConstantCode.DB_EXCEPTION); } - log.debug("end queryBlockList. listOfTran:{}", JSON.toJSONString(listOfTran)); + log.debug("end queryBlockList. listOfTran:{}", JsonTools.toJSONString(listOfTran)); return listOfTran; } @@ -81,15 +81,15 @@ public List queryTransList(int groupId, TransListParam param) */ public Integer queryCountOfTran(int groupId, TransListParam queryParam) throws NodeMgrException { - log.debug("start queryCountOfTran. queryParam:{}", JSON.toJSONString(queryParam)); + log.debug("start queryCountOfTran. queryParam:{}", JsonTools.toJSONString(queryParam)); String tableName = TableName.TRANS.getTableName(groupId); try { Integer count = transHashMapper.getCount(tableName, queryParam); - log.info("end queryCountOfTran. queryParam:{} count:{}", JSON.toJSONString(queryParam), + log.info("end queryCountOfTran. queryParam:{} count:{}", JsonTools.toJSONString(queryParam), count); return count; } catch (RuntimeException ex) { - log.error("fail queryCountOfTran. queryParam:{}", JSON.toJSONString(queryParam), ex); + log.error("fail queryCountOfTran. queryParam:{}", JsonTools.toJSONString(queryParam), ex); throw new NodeMgrException(ConstantCode.DB_EXCEPTION); } } @@ -109,7 +109,7 @@ public Integer queryCountOfTranByMinus(int groupId) } return count; } catch (BadSqlGrammarException ex) { - // TODO v1.2.2+: if trans_number not exists, use queryCountOfTran() instead + // v1.2.2+: if trans_number not exists, use queryCountOfTran() instead log.error("fail queryCountOfTranByMinus. ", ex); log.info("restart from queryCountOfTranByMinus to queryCountOfTran: []", ex.getCause()); TransListParam queryParam = new TransListParam(null, null); @@ -246,14 +246,14 @@ public TbTransHash getTbTransFromFrontByHash(Integer groupId, String transHash) tbTransHash = new TbTransHash(transHash, trans.getFrom(), trans.getTo(), trans.getBlockNumber(), null); } - log.info("end getTransFromFrontByHash. tbTransHash:{}", JSON.toJSONString(tbTransHash)); + log.info("end getTransFromFrontByHash. tbTransHash:{}", JsonTools.toJSONString(tbTransHash)); return tbTransHash; } /** * get transaction receipt */ - public TransReceipt getTransReceipt(int groupId, String transHash) { + public TransactionReceipt getTransReceipt(int groupId, String transHash) { return frontInterface.getTransReceipt(groupId, transHash); } diff --git a/src/main/java/com/webank/webase/node/mgr/transaction/entity/TransReceipt.java b/src/main/java/com/webank/webase/node/mgr/transaction/entity/TransReceipt.java deleted file mode 100644 index b0f02cbd0..000000000 --- a/src/main/java/com/webank/webase/node/mgr/transaction/entity/TransReceipt.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2014-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.webank.webase.node.mgr.transaction.entity; - - -import java.math.BigInteger; -import java.util.List; -import lombok.Data; - -/** - * transaction receipt entity - */ -@Data -public class TransReceipt { - - private String transactionHash; - private int transactionIndex; - private String blockHash; - private BigInteger blockNumber; - private int cumulativeGasUsed; - private int gasUsed; - private String contractAddress; - private String status; - private String from; - private String to; - private String output; - private List logs; - private String logsBloom; - private String blockNumberRaw; - private String transactionIndexRaw; - private boolean statusOK; - private String gasUsedRaw; - - private String root; - private String message; - private String input; - /** - * list of MerkleProofUnit - */ - private List txProof; - private List receiptProof; -} diff --git a/src/main/java/com/webank/webase/node/mgr/transdaily/TransDailyService.java b/src/main/java/com/webank/webase/node/mgr/transdaily/TransDailyService.java index f0b9caa5d..a5debb368 100644 --- a/src/main/java/com/webank/webase/node/mgr/transdaily/TransDailyService.java +++ b/src/main/java/com/webank/webase/node/mgr/transdaily/TransDailyService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.transdaily; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.fasterxml.jackson.core.JsonProcessingException; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.exception.NodeMgrException; @@ -46,7 +46,7 @@ public List listSeventDayOfTrans(Integer groupId) throws NodeMg // qurey List transList = tbTransDailyMapper .listSeventDayOfTransDaily(groupId); - log.debug("end listSeventDayOfTrans transList:{}", JSON.toJSONString(transList)); + log.debug("end listSeventDayOfTrans transList:{}", JsonTools.toJSONString(transList)); return transList; } catch (RuntimeException ex) { log.debug("fail listSeventDayOfTrans groupId:{}", groupId, ex); @@ -62,7 +62,7 @@ public void updateTransDaily(Integer groupId, LocalDate transDay, BigInteger old throws NodeMgrException { log.debug( "start updateTransDaily groupId:{} transDay:{} oldBlockNumber:{} " - + "latestBlockNumber:{} transCount:{}", groupId, JSON.toJSONString(transDay), + + "latestBlockNumber:{} transCount:{}", groupId, JsonTools.toJSONString(transDay), oldBlockNumber, latestBlockNumber, transCount); Map paramMap = new HashMap<>(); paramMap.put("groupId", groupId); @@ -90,7 +90,7 @@ public void updateTransDaily(Integer groupId, LocalDate transDay, BigInteger old public void addTbTransDailyInfo(Integer groupId, LocalDate transDay, Integer transCount, BigInteger blockNumber) throws NodeMgrException { log.debug("start addTbTransDailyInfo groupId:{} transDay:{} transCount:{} blockNumber:{}", - groupId, JSON.toJSONString(transDay), + groupId, JsonTools.toJSONString(transDay), transCount, blockNumber); // check group id @@ -103,7 +103,7 @@ public void addTbTransDailyInfo(Integer groupId, LocalDate transDay, Integer tra } catch (RuntimeException ex) { log.error( "start addTbTransDailyInfo groupId:{} transDay:{} transCount:{} blockNumber:{}", - groupId, JSON.toJSONString(transDay), + groupId, JsonTools.toJSONString(transDay), transCount, blockNumber, ex); throw new NodeMgrException(ConstantCode.DB_EXCEPTION); } diff --git a/src/main/java/com/webank/webase/node/mgr/user/UserController.java b/src/main/java/com/webank/webase/node/mgr/user/UserController.java index 86f0c908c..9fdbae39a 100644 --- a/src/main/java/com/webank/webase/node/mgr/user/UserController.java +++ b/src/main/java/com/webank/webase/node/mgr/user/UserController.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.user; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.controller.BaseController; import com.webank.webase.node.mgr.base.entity.BasePageResponse; import com.webank.webase.node.mgr.base.entity.BaseResponse; @@ -74,7 +74,7 @@ public BaseResponse addUserInfo(@RequestBody @Valid NewUserInputParam user, baseResponse.setData(userRow); log.info("end addUserInfo useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -97,7 +97,7 @@ public BaseResponse bindUserInfo(@RequestBody @Valid BindUserInputParam user, baseResponse.setData(userRow); log.info("end bindUserInfo useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -112,7 +112,7 @@ public BaseResponse updateUserInfo(@RequestBody @Valid UpdateUserInputParam user BaseResponse baseResponse = new BaseResponse(ConstantCode.SUCCESS); Instant startTime = Instant.now(); log.info("start updateUserInfo startTime:{} User:{}", startTime.toEpochMilli(), - JSON.toJSONString(user)); + JsonTools.toJSONString(user)); // update user row userService.updateUser(user); @@ -121,7 +121,7 @@ public BaseResponse updateUserInfo(@RequestBody @Valid UpdateUserInputParam user baseResponse.setData(userRow); log.info("end updateUserInfo useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -158,7 +158,7 @@ public BasePageResponse userList(@PathVariable("groupId") Integer groupId, } log.info("end userList useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(pagesponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(pagesponse)); return pagesponse; } @@ -180,7 +180,7 @@ public BaseResponse importPrivateKey(@Valid @RequestBody ReqImportPrivateKey req baseResponse.setData(userRow); log.info("end importPrivateKey useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -202,7 +202,7 @@ public BaseResponse importPemPrivateKey(@Valid @RequestBody ReqImportPem reqImpo baseResponse.setData(userRow); log.info("end importPemPrivateKey useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return baseResponse; } @@ -228,7 +228,7 @@ public BaseResponse importP12PrivateKey(@RequestParam MultipartFile p12File, baseResponse.setData(userRow); log.info("end importPemPrivateKey useTime:{} result:{}", - Duration.between(startTime, Instant.now()).toMillis(), JSON.toJSONString(baseResponse)); + Duration.between(startTime, Instant.now()).toMillis(), JsonTools.toJSONString(baseResponse)); return new BaseResponse(ConstantCode.SUCCESS); } diff --git a/src/main/java/com/webank/webase/node/mgr/user/UserService.java b/src/main/java/com/webank/webase/node/mgr/user/UserService.java index 996ebe927..1cfd098c4 100644 --- a/src/main/java/com/webank/webase/node/mgr/user/UserService.java +++ b/src/main/java/com/webank/webase/node/mgr/user/UserService.java @@ -13,7 +13,7 @@ */ package com.webank.webase.node.mgr.user; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.code.ConstantCode; import com.webank.webase.node.mgr.base.enums.HasPk; import com.webank.webase.node.mgr.base.enums.UserType; @@ -128,7 +128,7 @@ public Integer addUserInfo(Integer groupId, String userName, String description, */ @Transactional public Integer bindUserInfo(BindUserInputParam user) throws NodeMgrException { - log.debug("start bindUserInfo User:{}", JSON.toJSONString(user)); + log.debug("start bindUserInfo User:{}", JsonTools.toJSONString(user)); String publicKey = user.getPublicKey(); if (StringUtils.isBlank(publicKey)) { @@ -185,14 +185,14 @@ public Integer bindUserInfo(BindUserInputParam user) throws NodeMgrException { * query count of user. */ public Integer countOfUser(UserParam userParam) throws NodeMgrException { - log.debug("start countOfUser. userParam:{}", JSON.toJSONString(userParam)); + log.debug("start countOfUser. userParam:{}", JsonTools.toJSONString(userParam)); try { Integer count = userMapper.countOfUser(userParam); - log.debug("end countOfUser userParam:{} count:{}", JSON.toJSONString(userParam), count); + log.debug("end countOfUser userParam:{} count:{}", JsonTools.toJSONString(userParam), count); return count; } catch (RuntimeException ex) { - log.error("fail countOfUser userParam:{}", JSON.toJSONString(userParam), ex); + log.error("fail countOfUser userParam:{}", JsonTools.toJSONString(userParam), ex); throw new NodeMgrException(ConstantCode.DB_EXCEPTION); } } @@ -210,10 +210,10 @@ private Integer countOfUser(Integer userId) throws NodeMgrException { * query user list by page. */ public List qureyUserList(UserParam userParam) throws NodeMgrException { - log.debug("start qureyUserList userParam:{}", JSON.toJSONString(userParam)); + log.debug("start qureyUserList userParam:{}", JsonTools.toJSONString(userParam)); // query user list List listOfUser = userMapper.listOfUser(userParam); - log.debug("end qureyUserList listOfUser:{}", JSON.toJSONString(listOfUser)); + log.debug("end qureyUserList listOfUser:{}", JsonTools.toJSONString(listOfUser)); return listOfUser; } @@ -228,7 +228,7 @@ public TbUser queryUser(Integer userId, Integer groupId, String userName, String TbUser userRow = userMapper.queryUser(userId, groupId, userName, address); log.debug( "end queryUser userId:{} groupId:{} userName:{} address:{} TbUser:{}", - userId, groupId, userName, address, JSON.toJSONString(userRow)); + userId, groupId, userName, address, JsonTools.toJSONString(userRow)); return userRow; } catch (RuntimeException ex) { log.error("fail queryUser userId:{} groupId:{} userName:{} address:{}", @@ -284,7 +284,7 @@ public void updateUser(UpdateUserInputParam user) throws NodeMgrException { * update user info. */ public void updateUser(TbUser user) throws NodeMgrException { - log.debug("start updateUser user", JSON.toJSONString(user)); + log.debug("start updateUser user", JsonTools.toJSONString(user)); Integer userId = Optional.ofNullable(user).map(u -> u.getUserId()).orElse(null); String description = Optional.ofNullable(user).map(u -> u.getDescription()).orElse(null); if (userId == null) { diff --git a/src/test/java/node/mgr/test/abi/AbiControllerTest.java b/src/test/java/node/mgr/test/abi/AbiControllerTest.java index d84f8a782..c35cb79db 100644 --- a/src/test/java/node/mgr/test/abi/AbiControllerTest.java +++ b/src/test/java/node/mgr/test/abi/AbiControllerTest.java @@ -17,7 +17,7 @@ package node.mgr.test.abi; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.abi.entity.ReqImportAbi; import org.junit.Before; @@ -61,12 +61,12 @@ public void testInserAbi() throws Exception { abiInsert.setContractAddress("0xd8e1e0834b38081982f4a080aeae350a6d422915"); abiInsert.setContractName("Hello"); String abiStr = "[{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_ua\",\"type\":\"uint256[]\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; - abiInsert.setContractAbi(JSON.parseArray(abiStr)); + abiInsert.setContractAbi(JsonTools.toJavaObjectList(abiStr, Object.class)); // post action ResultActions resultActions = mockMvc.perform( MockMvcRequestBuilders.post("/abi") - .content(JSON.toJSONString(abiInsert)) + .content(JsonTools.toJSONString(abiInsert)) .contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions @@ -118,12 +118,12 @@ public void testUpdateAbi() throws Exception { abiUpdate.setContractAddress("0xd8e1e0834b38081982f4a080aeae350a6d422915"); abiUpdate.setContractName("Hello_222"); String abiStr = "[{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_ua\",\"type\":\"uint256[]\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; - abiUpdate.setContractAbi(JSON.parseArray(abiStr)); + abiUpdate.setContractAbi(JsonTools.toJavaObjectList(abiStr, Object.class)); // post action ResultActions resultActions = mockMvc.perform( MockMvcRequestBuilders.put("/abi") - .content(JSON.toJSONString(abiUpdate)) + .content(JsonTools.toJSONString(abiUpdate)) .contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. diff --git a/src/test/java/node/mgr/test/abi/AbiServiceTest.java b/src/test/java/node/mgr/test/abi/AbiServiceTest.java index 01cf2a1e5..4c9af76fa 100644 --- a/src/test/java/node/mgr/test/abi/AbiServiceTest.java +++ b/src/test/java/node/mgr/test/abi/AbiServiceTest.java @@ -16,7 +16,7 @@ package node.mgr.test.abi; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.abi.AbiService; import com.webank.webase.node.mgr.abi.entity.AbiInfo; @@ -46,7 +46,7 @@ public void testInsert() { abiInsert.setContractAddress("0xd8e1e0834b38081982f4a080aeae350a6d422915"); abiInsert.setContractName("Hello"); String abiStr = "[{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_ua\",\"type\":\"uint256[]\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"; - abiInsert.setContractAbi(JSON.parseArray(abiStr)); + abiInsert.setContractAbi(JsonTools.toJavaObjectList(abiStr, Object.class)); abiService.saveAbi(abiInsert); int afterCount = abiService.countOfAbi(); Assert.assertTrue("insert failed", afterCount > count); diff --git a/src/test/java/node/mgr/test/alert/mail/AlertContentTest.java b/src/test/java/node/mgr/test/alert/mail/AlertContentTest.java index 6837cd509..859971d24 100644 --- a/src/test/java/node/mgr/test/alert/mail/AlertContentTest.java +++ b/src/test/java/node/mgr/test/alert/mail/AlertContentTest.java @@ -16,7 +16,7 @@ package node.mgr.test.alert.mail; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.base.tools.AlertRuleTools; import org.junit.Test; diff --git a/src/test/java/node/mgr/test/alert/mail/SendMailTest.java b/src/test/java/node/mgr/test/alert/mail/SendMailTest.java index 76a602d6b..82892da26 100644 --- a/src/test/java/node/mgr/test/alert/mail/SendMailTest.java +++ b/src/test/java/node/mgr/test/alert/mail/SendMailTest.java @@ -16,7 +16,7 @@ package node.mgr.test.alert.mail; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.alert.mail.MailService; import com.webank.webase.node.mgr.alert.rule.AlertRuleMapper; @@ -110,7 +110,7 @@ public void testSending() { public void testFinalEmailContent() { TbAlertRule alertRule = alertRuleService.queryByRuleId(1); System.out.println("=========alertRule========="); - System.out.println(JSON.toJSON(alertRule)); + System.out.println(JsonTools.toJSONString(alertRule)); String emailTitle = AlertRuleTools.getAlertTypeStrFromEnum(alertRule.getAlertType()); System.out.println("=========emailTitle========="); @@ -142,12 +142,12 @@ public void testProcessEmailContent() { // 假设只有一个参数时 List testParam = new ArrayList<>(); testParam.add("nodeId"); - String afterTestParam = JSON.toJSONString(testParam); + String afterTestParam = JsonTools.toJSONString(testParam); System.out.println("=======afterTestParam======"); System.out.println(afterTestParam); // 转回去,可能出错 - List finalParamList = (List) JSON.parse(afterTestParam); + List finalParamList = JsonTools.toJavaObjectList(afterTestParam, String.class); // 待处理的string String alertContent = "您的节点nodeId状态异常"; @@ -169,7 +169,7 @@ public void parseString2List() { // testList.add("yourmail@163.com"); // System.out.println(JSON.toJSON(testList)); String listStr = "[\"targetmail@163.com\",\"yourmail@163.com\"]"; - List list = (List) JSON.parse(listStr); + List list = JsonTools.toJavaObjectList(listStr, String.class); System.out.println(list); } diff --git a/src/test/java/node/mgr/test/alert/task/ParseToolTest.java b/src/test/java/node/mgr/test/alert/task/ParseToolTest.java index ac9752d47..6f165a905 100644 --- a/src/test/java/node/mgr/test/alert/task/ParseToolTest.java +++ b/src/test/java/node/mgr/test/alert/task/ParseToolTest.java @@ -16,7 +16,7 @@ package node.mgr.test.alert.task; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.fasterxml.jackson.databind.JsonNode; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.node.Node; diff --git a/src/test/java/node/mgr/test/contract/ContractControllerTest.java b/src/test/java/node/mgr/test/contract/ContractControllerTest.java index dc92a5985..be6e31968 100644 --- a/src/test/java/node/mgr/test/contract/ContractControllerTest.java +++ b/src/test/java/node/mgr/test/contract/ContractControllerTest.java @@ -13,9 +13,7 @@ */ package node.mgr.test.contract; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.contract.entity.Contract; import com.webank.webase.node.mgr.contract.entity.DeployInputParam; @@ -91,7 +89,7 @@ public void testSaveContract() throws Exception { "60606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806366c99139146100465780636d4ce63c14610066575bfe5b341561004e57fe5b610064600480803590602001909190505061008c565b005b341561006e57fe5b610076610264565b6040518082815260200191505060405180910390f35b806000600101540360006001018190555080600260010160008282540192505081905550600480548060010182816100c49190610272565b916000526020600020906004020160005b608060405190810160405280604060405190810160405280600881526020017f32303137303431330000000000000000000000000000000000000000000000008152508152602001600060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001600260000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200185815250909190915060008201518160000190805190602001906101c49291906102a4565b5060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550606082015181600301555050505b50565b600060026001015490505b90565b81548183558181151161029f5760040281600402836000526020600020918201910161029e9190610324565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102e557805160ff1916838001178555610313565b82800160010185558215610313579182015b828111156103125782518255916020019190600101906102f7565b5b50905061032091906103aa565b5090565b6103a791905b808211156103a357600060008201600061034491906103cf565b6001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905560038201600090555060040161032a565b5090565b90565b6103cc91905b808211156103c85760008160009055506001016103b0565b5090565b90565b50805460018160011615610100020316600290046000825580601f106103f55750610414565b601f01602090049060005260206000209081019061041391906103aa565b5b505600a165627a7a72305820d453cb481a312519166e409e7248d76d8c2672458c08b9500945a4004a1b69020029"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post("/contract/save"). - content(JSON.toJSONString(testUpdate)). + content(JsonTools.toJSONString(testUpdate)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -122,7 +120,7 @@ public void testDeploy() throws Exception { ResultActions resultActions = mockMvc .perform(MockMvcRequestBuilders.post("/contract/deploy"). - content(JSON.toJSONString(deployInputParam)). + content(JsonTools.toJSONString(deployInputParam)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -146,7 +144,7 @@ public void testQueryContractList() throws Exception { ResultActions resultActions = mockMvc .perform(MockMvcRequestBuilders.post("/contract/contractList"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -166,7 +164,7 @@ public void testFindByPartOfBytecodeBin() throws Exception { ResultActions resultActions = mockMvc .perform(MockMvcRequestBuilders.post("/contract/findByPartOfBytecodeBin"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -181,7 +179,7 @@ public void testFindByPartOfBytecodeBin() throws Exception { public void tesSendTransaction() throws Exception { //abi String abiStr = "[{\"constant\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"trans\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"a\",\"type\":\"string\"}],\"name\":\"abb\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"b\",\"type\":\"string\"}],\"name\":\"bba\",\"type\":\"event\"}]"; - List abiList = JSONArray.parseArray(abiStr); + List abiList = JsonTools.toJavaObjectList(abiStr, Object.class); //param TransactionInputParam param = new TransactionInputParam(); @@ -198,7 +196,7 @@ public void tesSendTransaction() throws Exception { ResultActions resultActions = mockMvc .perform(MockMvcRequestBuilders.post("/contract/transaction"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. diff --git a/src/test/java/node/mgr/test/contract/ContractServiceTest.java b/src/test/java/node/mgr/test/contract/ContractServiceTest.java index 03f6a5ea3..1892db501 100644 --- a/src/test/java/node/mgr/test/contract/ContractServiceTest.java +++ b/src/test/java/node/mgr/test/contract/ContractServiceTest.java @@ -16,8 +16,7 @@ package node.mgr.test.contract; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.contract.entity.DeployInputParam; import com.webank.webase.node.mgr.contract.ContractService; @@ -55,14 +54,14 @@ public void deployTest(){ //deploy TbContract tbContract = contractService.deployContract(deployInputParam); assert (tbContract.getContractId()!=null); - System.out.println("=========================================deploy result:"+ JSON.toJSONString(tbContract)); + System.out.println("=========================================deploy result:"+ JsonTools.toJSONString(tbContract)); } @Test public void sendTransactionTest(){ //abi String abiStr = "[{\"constant\":false,\"inputs\":[{\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"trans\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"}]"; - List abiList = JSONArray.parseArray(abiStr); + List abiList = JsonTools.toJavaObjectList(abiStr, Object.class); //param TransactionInputParam param = new TransactionInputParam(); diff --git a/src/test/java/node/mgr/test/front/FrontControllerTest.java b/src/test/java/node/mgr/test/front/FrontControllerTest.java index f24803abb..daec297df 100644 --- a/src/test/java/node/mgr/test/front/FrontControllerTest.java +++ b/src/test/java/node/mgr/test/front/FrontControllerTest.java @@ -13,7 +13,7 @@ */ package node.mgr.test.front; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.front.entity.FrontInfo; import org.junit.Before; @@ -57,7 +57,7 @@ public void testNewFront() throws Exception { param.setAgency("1fe"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post( "/front/new"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. diff --git a/src/test/java/node/mgr/test/frontInterface/FrontServiceTest.java b/src/test/java/node/mgr/test/frontInterface/FrontServiceTest.java index be3a9b5eb..ec95078f2 100644 --- a/src/test/java/node/mgr/test/frontInterface/FrontServiceTest.java +++ b/src/test/java/node/mgr/test/frontInterface/FrontServiceTest.java @@ -13,7 +13,7 @@ */ package node.mgr.test.frontInterface; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.block.entity.BlockInfo; import com.webank.webase.node.mgr.front.entity.TotalTransCountInfo; @@ -21,7 +21,7 @@ import com.webank.webase.node.mgr.frontinterface.entity.SyncStatus; import com.webank.webase.node.mgr.monitor.ChainTransInfo; import com.webank.webase.node.mgr.node.entity.PeerInfo; -import com.webank.webase.node.mgr.transaction.entity.TransReceipt; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; import com.webank.webase.node.mgr.transaction.entity.TransactionInfo; import java.math.BigInteger; import java.util.List; @@ -58,30 +58,30 @@ public void getContractCodeTest() { @Test public void getTransReceiptTest() { - TransReceipt transReceipt = frontInterface.getTransReceipt(groupId, transHash); + TransactionReceipt transReceipt = frontInterface.getTransReceipt(groupId, transHash); assert (transReceipt != null); - System.out.println(JSON.toJSONString(transReceipt)); + System.out.println(JsonTools.toJSONString(transReceipt)); } @Test public void getTransactionTest() { TransactionInfo transactionInfo = frontInterface.getTransaction(groupId, transHash); assert (transactionInfo != null); - System.out.println(JSON.toJSONString(transactionInfo)); + System.out.println(JsonTools.toJSONString(transactionInfo)); } @Test public void getBlockByNumberTest() { BlockInfo blockInfo = frontInterface.getBlockByNumber(groupId, new BigInteger("1000")); // assert (blockInfo != null); - System.out.println(JSON.toJSONString(blockInfo)); + System.out.println(JsonTools.toJSONString(blockInfo)); } @Test public void getblockFromFrontByHashTest() { BlockInfo blockInfo = frontInterface.getblockByHash(groupId, blockHash); assert (blockInfo != null); - System.out.println(JSON.toJSONString(blockInfo)); + System.out.println(JsonTools.toJSONString(blockInfo)); } @Test @@ -89,7 +89,7 @@ public void getTransFromFrontByHashTest() { ChainTransInfo chainTransInfo = frontInterface .getTransInfoByHash(groupId, transHash); assert (chainTransInfo != null); - System.out.println(JSON.toJSONString(chainTransInfo)); + System.out.println(JsonTools.toJSONString(chainTransInfo)); } @Test @@ -113,21 +113,21 @@ public void getCodeFromFronthTest() { public void getTotalTransactionCountTest() { TotalTransCountInfo totalTransCount = frontInterface.getTotalTransactionCount(groupId); assert (totalTransCount != null); - System.out.println(JSON.toJSONString(totalTransCount)); + System.out.println(JsonTools.toJSONString(totalTransCount)); } @Test public void getTransByBlockNumberTest() { List list = frontInterface.getTransByBlockNumber(groupId, blockNumber); assert (list != null && list.size() > 0); - System.out.println(JSON.toJSONString(list)); + System.out.println(JsonTools.toJSONString(list)); } @Test public void getGroupPeersTest() { List list = frontInterface.getGroupPeers(groupId); assert (list != null && list.size() > 0); - System.out.println(JSON.toJSONString(list)); + System.out.println(JsonTools.toJSONString(list)); } @@ -135,14 +135,14 @@ public void getGroupPeersTest() { public void getGroupListTest() { List list = frontInterface.getGroupListFromSpecificFront(frontIp, frontPort); assert (list != null && list.size() > 0); - System.out.println("=====================list:" + JSON.toJSONString(list)); + System.out.println("=====================list:" + JsonTools.toJSONString(list)); } @Test public void getPeersTest() { PeerInfo[] list = frontInterface.getPeers(groupId); assert (list != null && list.length > 0); - System.out.println("=====================list:" + JSON.toJSONString(list)); + System.out.println("=====================list:" + JsonTools.toJSONString(list)); } @Test @@ -156,7 +156,7 @@ public void getConsensusStatusTest() { public void syncStatusTest() { SyncStatus status = frontInterface.getSyncStatus(groupId); assert (status != null); - System.out.println("=====================status:" + JSON.toJSONString(status)); + System.out.println("=====================status:" + JsonTools.toJSONString(status)); } @Test diff --git a/src/test/java/node/mgr/test/frontgroupmap/FrontGroupMapServiceTest.java b/src/test/java/node/mgr/test/frontgroupmap/FrontGroupMapServiceTest.java index 472710790..06705097f 100644 --- a/src/test/java/node/mgr/test/frontgroupmap/FrontGroupMapServiceTest.java +++ b/src/test/java/node/mgr/test/frontgroupmap/FrontGroupMapServiceTest.java @@ -13,7 +13,7 @@ */ package node.mgr.test.frontgroupmap; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.frontgroupmap.FrontGroupMapService; import com.webank.webase.node.mgr.frontgroupmap.entity.FrontGroup; @@ -38,14 +38,14 @@ public void getListTest() { param.setGroupId(2); List list = frontGroupMapService.getList(param); assert (list != null); - System.out.println(JSON.toJSONString(list)); + System.out.println(JsonTools.toJSONString(list)); } @Test public void listByGroupIdTest() { List list = frontGroupMapService.listByGroupId(2); assert (list != null); - System.out.println(JSON.toJSONString(list)); + System.out.println(JsonTools.toJSONString(list)); } @Test diff --git a/src/test/java/node/mgr/test/group/GroupControllerTest.java b/src/test/java/node/mgr/test/group/GroupControllerTest.java index f9e6aef7c..b7a919a40 100644 --- a/src/test/java/node/mgr/test/group/GroupControllerTest.java +++ b/src/test/java/node/mgr/test/group/GroupControllerTest.java @@ -15,7 +15,7 @@ */ package node.mgr.test.group; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.group.entity.ReqGenerateGroup; import com.webank.webase.node.mgr.group.entity.ReqGroupStatus; @@ -113,7 +113,7 @@ public void testGenerateSingle() throws Exception { param.setDescription("test"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post("/group/generate/" + targetNodeId). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -134,7 +134,7 @@ public void testGenerate() throws Exception { param.setDescription("test"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post( "/group/generate"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -153,7 +153,7 @@ public void testOperate() throws Exception { // param.setType("recover"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders .post("/group/operate/" + targetNodeId). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -186,7 +186,7 @@ public void testGroupStatusList() throws Exception { param.setNodeIdList(nodeIdList); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders .post("/group/queryGroupStatus/list") - .content(JSON.toJSONString(param)) + .content(JsonTools.toJSONString(param)) .contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. diff --git a/src/test/java/node/mgr/test/method/MethodControllerTest.java b/src/test/java/node/mgr/test/method/MethodControllerTest.java index f78de4107..1665ea9d8 100644 --- a/src/test/java/node/mgr/test/method/MethodControllerTest.java +++ b/src/test/java/node/mgr/test/method/MethodControllerTest.java @@ -15,7 +15,7 @@ */ package node.mgr.test.method; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.method.entity.Method; import com.webank.webase.node.mgr.method.entity.NewMethodInputParam; @@ -63,7 +63,7 @@ public void testAddMethod() throws Exception { param.setGroupId(2); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post( "/method/add"). - content(JSON.toJSONString(param)). + content(JsonTools.toJSONString(param)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. diff --git a/src/test/java/node/mgr/test/token/TokenTest.java b/src/test/java/node/mgr/test/token/TokenTest.java index 894b11a04..6e6e3ad87 100644 --- a/src/test/java/node/mgr/test/token/TokenTest.java +++ b/src/test/java/node/mgr/test/token/TokenTest.java @@ -1,6 +1,6 @@ package node.mgr.test.token; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.token.TokenService; import com.webank.webase.node.mgr.transaction.TransHashService; diff --git a/src/test/java/node/mgr/test/transaction/TransHashServiceTest.java b/src/test/java/node/mgr/test/transaction/TransHashServiceTest.java index 308496095..53214f3c0 100644 --- a/src/test/java/node/mgr/test/transaction/TransHashServiceTest.java +++ b/src/test/java/node/mgr/test/transaction/TransHashServiceTest.java @@ -1,6 +1,6 @@ package node.mgr.test.transaction; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.transaction.TransHashMapper; import com.webank.webase.node.mgr.transaction.entity.TbTransHash; @@ -48,11 +48,11 @@ public void getTransListFromChain() { BigInteger blockNumber = new BigInteger("12"); List trans = transHashService.getTransListFromChain(groupId, transHash, blockNumber); assert (trans != null); - System.out.println(JSON.toJSONString(trans)); + System.out.println(JsonTools.toJSONString(trans)); } /** - * TODO optimize getCount's time + * optimize getCount's time: use tx_id to record count */ @Test public void getCountTimeCost() { diff --git a/src/test/java/node/mgr/test/user/UserControllerTest.java b/src/test/java/node/mgr/test/user/UserControllerTest.java index 57f088f68..d5999c603 100644 --- a/src/test/java/node/mgr/test/user/UserControllerTest.java +++ b/src/test/java/node/mgr/test/user/UserControllerTest.java @@ -13,7 +13,7 @@ */ package node.mgr.test.user; -import com.alibaba.fastjson.JSON; +import com.webank.webase.node.mgr.base.tools.JsonTools; import com.webank.webase.node.mgr.Application; import com.webank.webase.node.mgr.frontgroupmap.FrontGroupMapCache; import com.webank.webase.node.mgr.user.entity.BindUserInputParam; @@ -62,7 +62,7 @@ public void testNewUser() throws Exception { newUser.setGroupId(1); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post("/user/userInfo"). - content(JSON.toJSONString(newUser)). + content(JsonTools.toJSONString(newUser)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -79,7 +79,7 @@ public void testUpdateUser() throws Exception { updateUser.setDescription("testtttttttttttttttttttttttt"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.put("/user/userInfo"). - content(JSON.toJSONString(updateUser)). + content(JsonTools.toJSONString(updateUser)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions. @@ -99,7 +99,7 @@ public void testBindUser() throws Exception { "tettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweewtettewetrweew"); ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post("/user/bind"). - content(JSON.toJSONString(newUser)). + content(JsonTools.toJSONString(newUser)). contentType(MediaType.APPLICATION_JSON_UTF8) ); resultActions.