Search in sources :

Example 1 with BaseResModel

use of com.bsnbase.sdk.entity.base.BaseResModel in project PCNGateway-Java-SDK by BSNDA.

the class HttpService method noSignPost.

public BaseResModel<K> noSignPost(BaseReqModel<T> req, String url, Class<K> clazz) {
    String res;
    BaseResModel<K> resModel = new BaseResModel<K>();
    try {
        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());
            resModel.setBody(JSON.parseObject(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);
        }
        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) BaseResModel(com.bsnbase.sdk.entity.base.BaseResModel) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) JsonException(javax.json.JsonException)

Example 2 with BaseResModel

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

Aggregations

BaseResModel (com.bsnbase.sdk.entity.base.BaseResModel)2 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)2 JsonException (javax.json.JsonException)2