Skip to content

Commit

Permalink
Merge pull request #418 from WeBankFinTech/dev
Browse files Browse the repository at this point in the history
v1.3.2 dev=>master
  • Loading branch information
mingzhenliu authored Jun 22, 2020
2 parents af1889d + 8402656 commit e38e4a7
Show file tree
Hide file tree
Showing 48 changed files with 747 additions and 636 deletions.
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
### v1.3.2(2020-06-17)

**Fix**
- 移除Fastjson,替换为Jackson 2.11.0; web3sdk升级为2.4.1
- 升级依赖包:spring: 4.3.27; log4j: 2.13.3; slf4j: 1.7.30; netty-all: 4.1.44+; guava: 29.0;

**兼容性**
- 支持FISCO-BCOS v2.4.0 及以上版本
- WeBASE-Node-Manager 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**
Expand Down
45 changes: 33 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ repositories {

}

def spring_version="4.3.25.RELEASE"
def spring_version="4.3.27.RELEASE"
List spring =[
"org.springframework:spring-core:$spring_version",
"org.springframework:spring-beans:$spring_version",
"org.springframework:spring-context:$spring_version",
"org.springframework:spring-tx:$spring_version",
"org.springframework:spring-web:$spring_version",
"org.springframework:spring-webmvc:$spring_version",
"org.springframework:spring-jdbc:$spring_version"
"org.springframework:spring-jdbc:$spring_version",
// cover old version
"org.springframework:spring-aspects:$spring_version",
"org.springframework:spring-messaging:$spring_version",
"org.springframework:spring-orm:$spring_version",
"org.springframework:spring-test:$spring_version"

]

def spring_boot_version="1.5.9.RELEASE"
def spring_boot_version="1.5.22.RELEASE"
List spring_boot =[
"org.springframework.boot:spring-boot-starter-web:$spring_boot_version",
"org.springframework.boot:spring-boot-autoconfigure:$spring_boot_version",
Expand All @@ -50,13 +56,12 @@ List swagger = [
]


def log4j_version="2.13.1"
def log4j_version="2.13.3"
List logger = [
"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",
"org.slf4j:jcl-over-slf4j:1.7.12"
"org.apache.logging.log4j:log4j-web:$log4j_version"
]

List jaxb = [
Expand All @@ -66,22 +71,38 @@ List jaxb = [
"javax.activation:activation:1.1.1"
]

def jackson_version = "2.11.0"
List jackson = [
"com.fasterxml.jackson.core:jackson-annotations:$jackson_version",
"com.fasterxml.jackson.core:jackson-core:$jackson_version",
"com.fasterxml.jackson.core:jackson-databind:$jackson_version",
"com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version"
]

// cover old version
def tomcat_version = "8.5.56"
List tomcat = [
"org.apache.tomcat.embed:tomcat-embed-core:$tomcat_version",
"org.apache.tomcat.embed:tomcat-embed-el:$tomcat_version",
"org.apache.tomcat.embed:tomcat-embed-websocket:$tomcat_version",
"org.apache.tomcat:tomcat-jdbc:$tomcat_version",
"org.apache.tomcat:tomcat-juli:$tomcat_version"
]

dependencies {
compile spring,spring_boot,swagger,logger,jaxb
compile ('org.fisco-bcos:web3sdk:2.4.0')
compile spring,spring_boot,swagger,logger,jaxb,jackson,tomcat
compile ('org.fisco-bcos:web3sdk:2.4.1')
// support guomi/ecdsa same time, support solcJ-0.5.2
compile ('org.fisco-bcos:solcJ:0.4.25-rc1')
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.0'
compile 'com.alibaba:fastjson:1.2.70'
compile 'com.h2database:h2:1.4.197'
compile 'org.fusesource:sigar:1.6.4'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
compile 'org.projectlombok:lombok:1.18.6'
compile 'com.github.jsqlparser:jsqlparser:2.0'
compile "org.apache.commons:commons-lang3:3.8.1"

compile 'org.apache.commons:commons-lang3:3.8.1'
compile 'org.slf4j:jcl-over-slf4j:1.7.30'
// cover low version guava
compile 'com.google.guava:guava:29.0-jre'
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
Expand Down
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V1.0.0
V1.3.2
6 changes: 3 additions & 3 deletions src/main/java/com/webank/webase/front/abi/AbiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.webank.webase.front.abi;

import com.alibaba.fastjson.JSON;
import com.webank.webase.front.abi.entity.AbiInfo;
import com.webank.webase.front.abi.entity.ReqImportAbi;
import com.webank.webase.front.base.code.ConstantCode;
import com.webank.webase.front.base.exception.FrontException;
import com.webank.webase.front.util.FrontUtils;
import com.webank.webase.front.util.JsonUtils;
import com.webank.webase.front.web3api.Web3ApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void insertAbiInfo(ReqImportAbi param) {
String contractAddress = param.getContractAddress();
String contractAbiStr;
try {
contractAbiStr = JSON.toJSONString(param.getContractAbi());
contractAbiStr = JsonUtils.toJSONString(param.getContractAbi());
} catch (Exception e) {
log.warn("abi parse string error:{}", param.getContractAbi());
throw new FrontException(ConstantCode.PARAM_FAIL_ABI_INVALID);
Expand Down Expand Up @@ -98,7 +98,7 @@ public void updateAbiInfo(ReqImportAbi param) {
BeanUtils.copyProperties(param, updateAbi);
String contractAbiStr;
try {
contractAbiStr = JSON.toJSONString(param.getContractAbi());
contractAbiStr = JsonUtils.toJSONString(param.getContractAbi());
} catch (Exception e) {
log.warn("abi parse string error:{}", param.getContractAbi());
throw new FrontException(ConstantCode.PARAM_FAIL_ABI_INVALID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ public class ConstantCode {
public static final RetCode KEYSTORE_NOT_EXIST = RetCode.mark(201040, "private key not exists");
public static final RetCode PARAM_FAIL_APPID_SIGN_USER_ID_EMPTY = RetCode.mark(201041, "external user's appId and signUserId cannot be empty");
public static final RetCode NO_SOL_FILES = RetCode.mark(201042, "There is no sol files in source");
public static final RetCode ENCODE_STR_CANNOT_BE_NULL = RetCode.mark(201044, "encode string can not be empty!");
public static final RetCode TRANSACTION_FAILED = RetCode.mark(201045, "transaction failed!");

// dynamic group manage
public static final RetCode INVALID_GROUP_OPERATE_TYPE = RetCode.mark(201043, "invalid group operate type");
// freeze contract
public static final RetCode INVALID_DATA_TYPE = RetCode.mark(201044, "invalid data type");
// tx channel
public static final RetCode ENCODE_STR_CANNOT_BE_NULL = RetCode.mark(201045, "encode string can not be empty!");
public static final RetCode TRANSACTION_FAILED = RetCode.mark(201046, "transaction failed!");

public static final RetCode FAIL_PARSE_JSON = RetCode.mark(201050, "Fail to parse json");
public static final RetCode GET_CONSENSUS_STATUS_FAIL = RetCode.mark(201051, "get consensus status fail");

/* system error */
public static final RetCode SYSTEM_ERROR = RetCode.mark(101001, "system error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public RabbitAdmin initRabbitAdmin(ConnectionFactory connectionFactory) {

/**
* 用于发送消息到队列
* 传输的message消息体在Message实体类中使用Fastjson进行序列化
* 传输的message消息体在Message实体类中使用jackson进行序列化
* @param rabbitAdmin
* @return
*/
Expand Down
37 changes: 26 additions & 11 deletions src/main/java/com/webank/webase/front/base/config/Web3Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.webank.webase.front.base.properties.Constants;
import com.webank.webase.front.event.callback.NewBlockEventCallback;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -57,6 +56,8 @@ public class Web3Config {
private String ip = "127.0.0.1";
private String channelPort = "20200";
private int encryptType;

private int independentGroupId = Integer.MAX_VALUE;
/**
* 覆盖EncryptType构造函数
* @return
Expand All @@ -68,33 +69,48 @@ public EncryptType EncryptType() {
return new EncryptType(encryptType);
}

/**
* singleton instance of config
* @case1: if add new web3j in web3jmap, add connection to channelConnectionsList of this bean
* @case2: if create a brand new web3j of new connections config,
* use getGroupChannelConnectionsConfig method to create new config
* @return
*/
@Bean
public GroupChannelConnectionsConfig getGroupChannelConnectionsConfig() {
public GroupChannelConnectionsConfig initGroupChannelConnectionsConfig() {
return getGroupChannelConnectionsConfig();
}

/**
* get a new config instance
* @return
*/
private GroupChannelConnectionsConfig getGroupChannelConnectionsConfig() {
List<ChannelConnections> channelConnectionsList = new ArrayList<>();

List<String> connectionsList = new ArrayList<>();
connectionsList.add(ip + ":" + channelPort);
log.info("*****" + ip + ":" + channelPort);
ChannelConnections channelConnections = new ChannelConnections();
channelConnections.setConnectionsStr(connectionsList);
channelConnections.setGroupId(1);
channelConnections.setGroupId(independentGroupId);
channelConnectionsList.add(channelConnections);

GroupChannelConnectionsConfig groupChannelConnectionsConfig =
new GroupChannelConnectionsConfig();
new GroupChannelConnectionsConfig();
groupChannelConnectionsConfig.setAllChannelConnections(channelConnectionsList);
return groupChannelConnectionsConfig;
}

/**
* init getWeb3j.
* init Web3j of default group id 1
*/
@Bean
public Web3j getWeb3j(GroupChannelConnectionsConfig groupChannelConnectionsConfig)
throws Exception {
Service service = new Service();
service.setOrgID(orgName);
service.setGroupId(1);
service.setGroupId(independentGroupId);
service.setThreadPool(sdkThreadPool());
service.setAllChannelConnections(groupChannelConnectionsConfig);
service.run();
Expand Down Expand Up @@ -135,12 +151,11 @@ public ThreadPoolTaskExecutor sdkThreadPool() {
*/
@Bean(name = "serviceMap")
@DependsOn("encryptType")
public Map<Integer, Service> serviceMap(Web3j web3j,
GroupChannelConnectionsConfig groupChannelConnectionsConfig,
NewBlockEventCallback newBlockEventCallBack) throws Exception {
public Map<Integer, Service> serviceMap(Web3j web3j, NewBlockEventCallback newBlockEventCallBack)
throws Exception {
List<String> groupIdList = web3j.getGroupList().send().getGroupList();
List<ChannelConnections> channelConnectionsList =
groupChannelConnectionsConfig.getAllChannelConnections();
GroupChannelConnectionsConfig groupChannelConnectionsConfig = getGroupChannelConnectionsConfig();
List<ChannelConnections> channelConnectionsList = groupChannelConnectionsConfig.getAllChannelConnections();
channelConnectionsList.clear();
for (int i = 0; i < groupIdList.size(); i++) {
List<String> connectionsList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.webank.webase.front.base.config;

import com.webank.webase.front.solc.SolcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.webank.webase.front.base.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.webank.webase.front.base.code.ConstantCode;
import com.webank.webase.front.base.code.RetCode;
import com.webank.webase.front.base.response.BaseResponse;
import com.webank.webase.front.base.exception.FrontException;
import com.webank.webase.front.util.JsonUtils;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -52,8 +51,7 @@ protected BaseResponse checkParamResult(BindingResult bindingResult) throws Fron

RetCode retCode = null;
try {
JSONObject jsonObject = JSON.parseObject(errorMsg);
retCode = JSONObject.toJavaObject(jsonObject, RetCode.class);
retCode = JsonUtils.toJavaObject(errorMsg, RetCode.class);
} catch (Exception ex) {
log.warn("OnWarning:retCodeJson convert error");
throw new FrontException(ConstantCode.PARAM_VAILD_FAIL);
Expand All @@ -64,7 +62,7 @@ protected BaseResponse checkParamResult(BindingResult bindingResult) throws Fron

private String getParamValidFaildMessage(BindingResult bindingResult) {
List<ObjectError> errorList = bindingResult.getAllErrors();
log.info("errorList:{}", JSON.toJSONString(errorList));
log.info("errorList:{}", JsonUtils.toJSONString(errorList));
if (errorList == null) {
log.warn("onWarning:errorList is empty!");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
*/
package com.webank.webase.front.base.exception;

import com.webank.webase.front.util.JsonUtils;
import java.util.HashMap;
import java.util.Map;

import com.webank.webase.front.base.code.RetCode;
import com.webank.webase.front.util.ErrorCodeHandleUtils;
import org.fisco.bcos.web3j.protocol.exceptions.MessageDecodingException;
import org.fisco.bcos.web3j.protocol.exceptions.MessageEncodingException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -73,7 +71,7 @@ public ResponseEntity typeMismatchExceptionHandler(TypeMismatchException ex) {
// map.put("exception", frontException);
map.put("errorMessage", ex.getMessage());
map.put("code", 400);
log.warn("typeMismatchException return:{}", JSON.toJSONString(map));
log.warn("typeMismatchException return:{}", JsonUtils.toJSONString(map));
return ResponseEntity.status(400).body(map);
}

Expand All @@ -86,7 +84,7 @@ public ResponseEntity bindExceptionHandler(ServletRequestBindingException ex) {
// map.put("exception", frontException);
map.put("errorMessage", ex.getMessage());
map.put("code", 400);
log.warn("bindExceptionHandler return:{}", JSON.toJSONString(map));
log.warn("bindExceptionHandler return:{}", JsonUtils.toJSONString(map));
return ResponseEntity.status(400).body(map);
}

Expand Down
Loading

0 comments on commit e38e4a7

Please sign in to comment.