use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.
the class HttpService method post.
public BaseResModel<K> post(BaseReqModel<T> req, String url, Class<K> clazz) {
String res;
BaseResModel<K> resModel = new BaseResModel<K>();
try {
req.sign();
res = doPost(req, url);
} catch (GlobalException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
}
if (res != null && res.length() > 0) {
try {
resModel = JSON.parseObject(res, resModel.getClass());
String bodystr = JSON.toJSONString(resModel.getBody());
boolean checkJson = JsonUtil.getJSONType(bodystr);
resModel.setBody(checkJson ? JSON.parseObject(bodystr, clazz) : null);
} catch (Exception e) {
throw new GlobalException(ResultInfoEnum.DATA_CONVERSION_ERROR);
}
// Signature verfication, data transfer
if (resModel == null) {
throw new GlobalException(ResultInfoEnum.INVALID_RESPONSE_ERROR);
}
boolean result = false;
try {
result = resModel.verify();
} catch (Exception e) {
throw new GlobalException(ResultInfoEnum.RES_MAC_ERROR);
}
if (!result) {
throw new GlobalException(ResultInfoEnum.RES_MAC_ERROR);
}
if (resModel.getHeader().getCode() != 0) {
throw new GlobalException(resModel.getHeader().getMsg());
} else {
}
return resModel;
} else {
throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
}
}
use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.
the class HttpService method arrayPost.
public BaseResArrayModel<K> arrayPost(BaseReqModel<T> req, String url, Class<K> clazz) {
String res;
BaseResArrayModel<K> resModel = new BaseResArrayModel<K>();
try {
req.sign();
res = doPost(req, url);
} catch (Exception e) {
e.printStackTrace();
throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
}
if (res != null && res.length() > 0) {
try {
resModel = JSON.parseObject(res, resModel.getClass());
String bodystr = JSON.toJSONString(resModel.getBody());
resModel.setBody(JSON.parseArray(bodystr, clazz));
} catch (JsonException e) {
throw new GlobalException(ResultInfoEnum.DATA_CONVERSION_ERROR);
}
// Signature verfication, data transfer
if (resModel == null) {
throw new GlobalException(ResultInfoEnum.INVALID_RESPONSE_ERROR);
}
boolean result = false;
try {
result = resModel.verify();
} catch (Exception e) {
throw new GlobalException(ResultInfoEnum.RES_MAC_ERROR);
}
if (!result) {
throw new GlobalException(ResultInfoEnum.RES_MAC_ERROR);
}
if (resModel.getHeader().getCode() != 0) {
throw new GlobalException(resModel.getHeader().getMsg());
} else {
}
return resModel;
} else {
throw new GlobalException(ResultInfoEnum.SYSTEM_ERROR);
}
}
use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.
the class StoreUtils method generateCSR.
/**
* csr generation
*
* @param name
* @param appCode
* @return
*/
public static UserCertInfo generateCSR(String name, String appCode) {
try {
String DN = "CN=" + Common.getCNName(name, appCode) + ",OU=client";
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
UserCertInfo certInfo = algorithmTypeContext.getAlgorithmTypeHandle().getUserCertInfo(DN);
if (Objects.isNull(certInfo)) {
throw new GlobalException(ResultInfoEnum.ALGORITHM_TYPE_ERROR);
}
return certInfo;
} catch (Exception e) {
logger.error("Get CSR Exception", e);
throw new GlobalException("Get CSR Exception");
}
}
use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.
the class TransData method getTransdata.
public static String getTransdata(TransactionRequest request, TransactionUser user) throws Exception {
ProposalPackage.Proposal proposal = proposal(request, user);
byte[] proposalBytes = convertToBytes(proposal);
byte[] signBytes;
try {
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(com.bsnbase.sdk.entity.config.Config.config.getAppInfo().getAlgorithmType());
signBytes = FabricTransUtil.getTransSign(algorithmTypeEnum, user.getPrivateKey(), proposalBytes);
} catch (Exception e) {
throw new GlobalException(ResultInfoEnum.TRANSACTION_SIGNING_ERROR);
}
ProposalPackage.SignedProposal.Builder sig = ProposalPackage.SignedProposal.newBuilder();
sig.setProposalBytes(getByteString(proposalBytes));
sig.setSignature(getByteString(signBytes));
byte[] signProposalBytes = convertToBytes(sig.build());
return Base64.getEncoder().encodeToString(signProposalBytes);
}
use of com.bsnbase.sdk.util.exception.GlobalException in project PCNGateway-Java-SDK by BSNDA.
the class BaseReqModel method sign.
/**
* The request gateway calls the "sign" method
*/
@Override
public void sign() throws Exception {
if (this.header == null) {
throw new GlobalException(ResultInfoEnum.REQUEST_HEADER_ERROR);
}
String signValue = this.header.getHeaderString();
if (this.body != null) {
signValue += this.body.getEncryptionValue();
}
AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
String sign = algorithmTypeContext.getAlgorithmTypeHandle().sign(Config.config.getPrk(), signValue);
this.mac = sign;
}
Aggregations