Search in sources :

Example 1 with QiniuException

use of com.qiniu.common.QiniuException in project paascloud-master by paascloud.

the class MdcTopicConsumer method handlerSendSmsTopic.

/**
 * Handler send sms topic.
 *
 * @param body      the body
 * @param topicName the topic name
 * @param tags      the tags
 * @param keys      the keys
 */
@Transactional(rollbackFor = Exception.class)
public void handlerSendSmsTopic(String body, String topicName, String tags, String keys) throws QiniuException {
    MqMessage.checkMessage(body, keys, topicName);
    if (StringUtils.equals(tags, AliyunMqTopicConstants.MqTagEnum.DELETE_ATTACHMENT.getTag())) {
        List<Long> idList = opcAttachmentService.queryAttachmentByRefNo(body);
        for (final Long id : idList) {
            opcAttachmentService.deleteFile(id);
        }
    } else {
        UpdateAttachmentDto attachmentDto;
        try {
            attachmentDto = JacksonUtil.parseJson(body, UpdateAttachmentDto.class);
        } catch (Exception e) {
            log.error("发送短信MQ出现异常={}", e.getMessage(), e);
            throw new IllegalArgumentException("JSON转换异常", e);
        }
        opcAttachmentService.updateAttachment(attachmentDto);
    }
}
Also used : UpdateAttachmentDto(com.paascloud.provider.model.dto.UpdateAttachmentDto) QiniuException(com.qiniu.common.QiniuException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with QiniuException

use of com.qiniu.common.QiniuException in project xmall by Exrick.

the class QiniuUtil method qiniuUpload.

public static String qiniuUpload(String filePath) {
    // 构造一个带指定Zone对象的配置类 zone2华南
    Configuration cfg = new Configuration(Zone.zone2());
    UploadManager uploadManager = new UploadManager(cfg);
    String localFilePath = filePath;
    // 默认不指定key的情况下,以文件内容的hash值作为文件名
    String key = null;
    Auth auth = Auth.create(accessKey, secretKey);
    String upToken = auth.uploadToken(bucket);
    try {
        Response response = uploadManager.put(localFilePath, key, upToken);
        // 解析上传成功的结果
        DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
        return origin + putRet.key;
    } catch (QiniuException ex) {
        Response r = ex.response;
        log.warn(r.toString());
        try {
            log.warn(r.bodyString());
            return r.bodyString();
        } catch (QiniuException ex2) {
        // ignore
        }
    }
    return null;
}
Also used : Response(com.qiniu.http.Response) QiniuException(com.qiniu.common.QiniuException) Configuration(com.qiniu.storage.Configuration) Auth(com.qiniu.util.Auth) Gson(com.google.gson.Gson) DefaultPutRet(com.qiniu.storage.model.DefaultPutRet) UploadManager(com.qiniu.storage.UploadManager)

Aggregations

QiniuException (com.qiniu.common.QiniuException)2 Gson (com.google.gson.Gson)1 UpdateAttachmentDto (com.paascloud.provider.model.dto.UpdateAttachmentDto)1 Response (com.qiniu.http.Response)1 Configuration (com.qiniu.storage.Configuration)1 UploadManager (com.qiniu.storage.UploadManager)1 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)1 Auth (com.qiniu.util.Auth)1 Transactional (org.springframework.transaction.annotation.Transactional)1