Search in sources :

Example 31 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method exists.

@Override
public boolean exists(String bucketName, String fileKey) {
    bucketName = buildBucketName(bucketName);
    fileKey = resolveFileKey(bucketName, fileKey);
    try {
        bucketManager.stat(bucketName, fileKey);
        return true;
    } catch (QiniuException e) {
        if (e.code() == 612)
            return false;
        throw new JeesuiteBaseException(e.code(), e.getMessage());
    }
}
Also used : QiniuException(com.qiniu.common.QiniuException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 32 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class AliyunProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        bucketName = buildBucketName(bucketName);
        fileKey = resolveFileKey(bucketName, fileKey);
        ObjectMetadata metadata = ossClient.getObjectMetadata(bucketName, fileKey);
        CObjectMetadata objectMetadata = new CObjectMetadata();
        objectMetadata.setCreateTime(metadata.getLastModified());
        objectMetadata.setMimeType(metadata.getContentType());
        objectMetadata.setFilesize(metadata.getContentLength());
        objectMetadata.setHash(metadata.getContentMD5());
        objectMetadata.setExpirationTime(metadata.getExpirationTime());
        objectMetadata.setCustomMetadatas(metadata.getUserMetadata());
        return objectMetadata;
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, e.getMessage());
    }
}
Also used : CObjectMetadata(com.jeesuite.cos.CObjectMetadata) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) ObjectMetadata(com.aliyun.oss.model.ObjectMetadata) CObjectMetadata(com.jeesuite.cos.CObjectMetadata) OSSException(com.aliyun.oss.OSSException) IOException(java.io.IOException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 33 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method delete.

@Override
public boolean delete(String bucketName, String fileKey) {
    try {
        bucketName = buildBucketName(bucketName);
        cosclient.deleteObject(bucketName, fileKey);
    } catch (Exception e) {
        throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
    }
    return true;
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) CosServiceException(com.qcloud.cos.exception.CosServiceException) IOException(java.io.IOException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 34 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QcloudProvider method upload.

@Override
public CUploadResult upload(CUploadObject object) {
    PutObjectRequest request;
    String fileKey = object.getFileKey();
    String bucketName = buildBucketName(object.getBucketName());
    if (object.getFile() != null) {
        request = new PutObjectRequest(bucketName, fileKey, object.getFile());
    } else if (object.getBytes() != null) {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(object.getBytes());
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(object.getFileSize());
        request = new PutObjectRequest(bucketName, fileKey, inputStream, objectMetadata);
    } else if (object.getInputStream() != null) {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(object.getFileSize());
        request = new PutObjectRequest(bucketName, fileKey, object.getInputStream(), objectMetadata);
    } else {
        throw new IllegalArgumentException("upload object is NULL");
    }
    try {
        if (object.getFileSize() > conf.getMaxAllowdSingleFileSize()) {
            Upload upload = transferManager.upload(request);
            com.qcloud.cos.model.UploadResult result = upload.waitForUploadResult();
            return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getCrc64Ecma());
        } else {
            PutObjectResult result = cosclient.putObject(request);
            return new CUploadResult(fileKey, getFullPath(object.getBucketName(), fileKey), result.getContentMd5());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new JeesuiteBaseException(500, buildMessage(bucketName, e));
    }
}
Also used : PutObjectResult(com.qcloud.cos.model.PutObjectResult) Upload(com.qcloud.cos.transfer.Upload) CosServiceException(com.qcloud.cos.exception.CosServiceException) IOException(java.io.IOException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) CUploadResult(com.jeesuite.cos.CUploadResult) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) CObjectMetadata(com.jeesuite.cos.CObjectMetadata) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest)

Example 35 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class TokenGenerator method validate.

/**
 * 验证带签名信息的token
 */
public static void validate(String tokenType, String token, boolean validateExpire) {
    long timestamp = 0;
    Date date = new Date();
    try {
        if (tokenType == null) {
            timestamp = Long.parseLong(SimpleCryptUtils.decrypt(token).substring(6));
        } else {
            String cryptKey = getCryptKey(tokenType);
            timestamp = Long.parseLong(DES.decrypt(cryptKey, token).substring(6));
        }
    } catch (Exception e) {
        throw new JeesuiteBaseException(4005, "token格式错误");
    }
    if (validateExpire && date.getTime() - timestamp > EXPIRE) {
        throw new JeesuiteBaseException(4005, "token已过期");
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) Date(java.util.Date) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)41 IOException (java.io.IOException)14 Request (okhttp3.Request)7 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 CObjectMetadata (com.jeesuite.cos.CObjectMetadata)3 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SignatureException (java.security.SignatureException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CUploadResult (com.jeesuite.cos.CUploadResult)2 WrapperResponseEntity (com.jeesuite.springweb.model.WrapperResponseEntity)2 COSObject (com.qcloud.cos.model.COSObject)2 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)2 QiniuException (com.qiniu.common.QiniuException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2