Search in sources :

Example 11 with JeesuiteBaseException

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

the class QcloudProvider method createUploadToken.

// https://github.com/tencentyun/qcloud-cos-sts-sdk/tree/master/java
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
    TreeMap<String, Object> config = new TreeMap<String, Object>();
    config.put("SecretId", conf.getAccessKey());
    config.put("SecretKey", conf.getSecretKey());
    config.put("durationSeconds", param.getExpires());
    config.put("bucket", buildBucketName(param.getBucketName()));
    config.put("region", conf.getRegionName());
    // config.put("allowPrefix", "a.jpg");
    // 密钥的权限列表。简单上传、表单上传和分片上传需要以下的权限,其他权限列表请看
    // https://cloud.tencent.com/document/product/436/31923
    String[] allowActions = new String[] { // 简单上传
    "name/cos:PutObject", // 表单上传、小程序上传
    "name/cos:PostObject", // 分片上传
    "name/cos:InitiateMultipartUpload", "name/cos:ListMultipartUploads", "name/cos:ListParts", "name/cos:UploadPart", "name/cos:CompleteMultipartUpload" };
    config.put("allowActions", allowActions);
    try {
        org.json.JSONObject json = CosStsClient.getCredential(config);
        return json.toMap();
    } catch (IOException e) {
        throw new JeesuiteBaseException("生成临时凭证错误:" + e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) COSObject(com.qcloud.cos.model.COSObject) CUploadObject(com.jeesuite.cos.CUploadObject) IOException(java.io.IOException) TreeMap(java.util.TreeMap)

Example 12 with JeesuiteBaseException

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

the class CosProviderServiceFacade method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    // 
    if (defaultBucket == null) {
        defaultBucket = ResourceUtils.getProperty("cos.defaultBucket");
    }
    if (type == null) {
        type = ResourceUtils.getAndValidateProperty("cos.provider");
    }
    if (config == null) {
        config = new CosProviderConfig();
        config.setAccessKey(ResourceUtils.getProperty("cos.accessKey"));
        config.setSecretKey(ResourceUtils.getProperty("cos.secretKey"));
        config.setAppId(ResourceUtils.getProperty("cos.appId"));
        config.setRegionName(ResourceUtils.getProperty("cos.regionName"));
        config.setMaxConnectionsCount(ResourceUtils.getInt("cos.maxConnections", 200));
    }
    if (AliyunProvider.NAME.equals(type)) {
        provider = new AliyunProvider(config);
    } else if (QcloudProvider.NAME.equals(type)) {
        provider = new QcloudProvider(config);
    } else if (QiniuProvider.NAME.equals(type)) {
        provider = new QiniuProvider(config);
    } else {
        throw new JeesuiteBaseException("cos[" + type + "] not support");
    }
    if (defaultBucket != null) {
        BucketConfig bucketConfig = provider.getBucketConfig(defaultBucket);
        bucketConfig.setUrlPrefix(ResourceUtils.getProperty("cos.defaultUrlPrefix"));
        ((AbstractProvider) provider).addBucketConfig(bucketConfig);
    } else {
        Map<String, String> urlPrefixMappings = ResourceUtils.getMappingValues("cos.bucket.urlPrefix.mapping");
        if (urlPrefixMappings != null) {
            urlPrefixMappings.forEach((bucket, urlPrefix) -> {
                BucketConfig bucketConfig = provider.getBucketConfig(defaultBucket);
                bucketConfig.setUrlPrefix(ResourceUtils.getProperty("cos.defaultUrlPrefix"));
                ((AbstractProvider) provider).addBucketConfig(bucketConfig);
            });
        }
    }
    logUrl = ResourceUtils.getProperty("cos.loghandler.url");
    if (logUrl != null && Boolean.parseBoolean(ResourceUtils.getProperty("cos.loghandler.enabled", "true"))) {
        int nThread = ResourceUtils.getInt("cos.loghandler.threads", 1);
        int capacity = ResourceUtils.getInt("cos.loghandler.queueSize", 1000);
        logHandleExecutor = new ThreadPoolExecutor(nThread, nThread, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(capacity), new StandardThreadFactory("cosLogHandleExecutor"));
        logger.info("init logHandleExecutor OK ,nThread:{},queue:{}", nThread, capacity);
    }
}
Also used : AbstractProvider(com.jeesuite.cos.provider.AbstractProvider) AliyunProvider(com.jeesuite.cos.provider.aliyun.AliyunProvider) StandardThreadFactory(com.jeesuite.common.async.StandardThreadExecutor.StandardThreadFactory) QiniuProvider(com.jeesuite.cos.provider.qiniu.QiniuProvider) QcloudProvider(com.jeesuite.cos.provider.qcloud.QcloudProvider) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 13 with JeesuiteBaseException

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

the class RequestLoggingInterceptor method around.

@Around("pointcut()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    ActionLog actionLog = ActionLogCollector.currentActionLog();
    if (actionLog == null) {
        return pjp.proceed();
    }
    HttpServletRequest request = CurrentRuntimeContext.getRequest();
    Method method = ((MethodSignature) pjp.getSignature()).getMethod();
    boolean requestLog = true;
    boolean responseLog = !ignoreResponseBody;
    if (method.isAnnotationPresent(ApiMetadata.class)) {
        ApiMetadata metadata = method.getAnnotation(ApiMetadata.class);
        requestLog = metadata.requestLog();
        responseLog = metadata.responseLog();
        if (!requestLog && !responseLog) {
            return pjp.proceed();
        }
    }
    Map<String, Object> parameters = null;
    Object body = null;
    if (requestLog) {
        Object[] args = pjp.getArgs();
        if (args.length > 0) {
            List<ParameterLogConfig> parameterConfigs = getParameterConfigs(pjp.getTarget().getClass().getName(), method);
            parameters = new HashMap<>(3);
            ParameterLogConfig config;
            for (int i = 0; i < args.length; i++) {
                if ((config = parameterConfigs.get(i)).ignore)
                    continue;
                if (config.isBody) {
                    body = args[i];
                } else if (config.paramName != null && args[i] != null) {
                    parameters.put(config.paramName, args[i].toString());
                }
            }
        }
        if (log.isDebugEnabled()) {
            String requestLogMessage = RequestLogBuilder.requestLogMessage(request.getRequestURI(), request.getMethod(), parameters, body);
            log.debug(requestLogMessage);
        }
    }
    actionLog.setQueryParameters(ParameterUtils.mapToQueryParams(parameters));
    actionLog.setRequestData(body);
    Object result = null;
    try {
        result = pjp.proceed();
        // 
        if (responseLog) {
            actionLog.setResponseData(result);
        }
        return result;
    } catch (Exception e) {
        if (e instanceof JeesuiteBaseException) {
            actionLog.setExceptions(e.getMessage());
        } else {
            actionLog.setExceptions(ExceptionUtils.getMessage(e));
        }
        throw e;
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) ApiMetadata(com.jeesuite.common.annotation.ApiMetadata) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) HttpServletRequest(javax.servlet.http.HttpServletRequest) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) Around(org.aspectj.lang.annotation.Around)

Example 14 with JeesuiteBaseException

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

the class LogFactory method setImplementation.

private static void setImplementation(Class<? extends Logger> implClass) {
    try {
        Constructor<? extends Logger> candidate = implClass.getConstructor(String.class);
        Logger log = candidate.newInstance(LogFactory.class.getName());
        if (log.isDebugEnabled()) {
            log.debug("Logging initialized using '" + implClass + "' adapter.");
        }
        logConstructor = candidate;
    } catch (Throwable t) {
        throw new JeesuiteBaseException("Error setting Log implementation.  Cause: " + t);
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 15 with JeesuiteBaseException

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

the class MQServiceRegistryBean method startProducer.

private void startProducer(String providerName) throws Exception {
    if ("rocketmq".equals(providerName)) {
        producer = new RocketProducerAdapter();
    } else if ("cmq".equals(providerName)) {
        producer = new CMQProducerAdapter();
    } else if ("memoryqueue".equals(providerName)) {
        producer = new MemoryQueueProducerAdapter();
    } else {
        throw new JeesuiteBaseException("NOT_SUPPORT[providerName]:" + providerName);
    }
    producer.start();
    logger.info("MQ_PRODUCER started -> groupName:{},providerName:{}", MQContext.getGroupName(), providerName);
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) CMQProducerAdapter(com.jeesuite.amqp.qcloud.cmq.CMQProducerAdapter) RocketProducerAdapter(com.jeesuite.amqp.rocketmq.RocketProducerAdapter) MemoryQueueProducerAdapter(com.jeesuite.amqp.memoryqueue.MemoryQueueProducerAdapter)

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