Search in sources :

Example 1 with BaseResArrayModel

use of com.bsnbase.sdk.entity.base.BaseResArrayModel 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);
    }
}
Also used : JsonException(javax.json.JsonException) BaseResArrayModel(com.bsnbase.sdk.entity.base.BaseResArrayModel) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) JsonException(javax.json.JsonException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

BaseResArrayModel (com.bsnbase.sdk.entity.base.BaseResArrayModel)1 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)1 JsonException (javax.json.JsonException)1