Search in sources :

Example 41 with JeesuiteBaseException

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

the class QiniuProvider method processQiniuException.

private void processQiniuException(String bucketName, QiniuException e) {
    Response r = e.response;
    if (e.code() == 631) {
        throw new JeesuiteBaseException(404, "bucketName[" + bucketName + "]不存在");
    }
    if (e.code() == 614) {
        throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
    }
    if (e.code() == 612) {
        throw new JeesuiteBaseException(404, "资源不存在");
    }
    String message;
    try {
        message = r.bodyString();
    } catch (Exception e2) {
        message = r.toString();
    }
    throw new JeesuiteBaseException(message);
}
Also used : Response(com.qiniu.http.Response) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) QiniuException(com.qiniu.common.QiniuException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) IOException(java.io.IOException)

Example 42 with JeesuiteBaseException

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

the class CurrentSystemHolder method initModuleApiInfos.

private static void initModuleApiInfos(BizSystemModule module) {
    try {
        String url;
        AppMetadata appMetadata;
        if (GlobalRuntimeContext.APPID.equals(module.getRouteName())) {
            appMetadata = AppMetadataHolder.getMetadata();
        } else {
            url = module.getMetadataUri();
            appMetadata = HttpRequestEntity.get(url).backendInternalCall().execute().toObject(AppMetadata.class);
        }
        for (ApiInfo api : appMetadata.getApis()) {
            module.addApiInfo(api);
        }
        moduleApiInfos.put(module.getServiceId(), module.getApiInfos());
        log.info(">>initModuleApiInfos success -> serviceId:{},nums:{}", module.getServiceId(), module.getApiInfos().size());
    } catch (Exception e) {
        boolean ignore = e instanceof ClassCastException;
        if (!ignore && e instanceof JeesuiteBaseException) {
            JeesuiteBaseException ex = (JeesuiteBaseException) e;
            ignore = ex.getCode() == 404 || ex.getCode() == 401 || ex.getCode() == 403;
        }
        if (ignore) {
            module.setApiInfos(new HashMap<>(0));
            moduleApiInfos.put(module.getServiceId(), module.getApiInfos());
        } else if (fetchApiMetaRound <= 1) {
            log.error(">>initModuleApiInfos error -> serviceId:[" + module.getServiceId() + "]", e);
        }
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) HashMap(java.util.HashMap) ApiInfo(com.mendmix.common.model.ApiInfo) AppMetadata(com.mendmix.springweb.model.AppMetadata) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException)

Example 43 with JeesuiteBaseException

use of com.mendmix.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.mendmix.common.JeesuiteBaseException)

Example 44 with JeesuiteBaseException

use of com.mendmix.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.mendmix.cos.provider.AbstractProvider) AliyunProvider(com.mendmix.cos.provider.aliyun.AliyunProvider) StandardThreadFactory(com.mendmix.common.async.StandardThreadExecutor.StandardThreadFactory) QiniuProvider(com.mendmix.cos.provider.qiniu.QiniuProvider) QcloudProvider(com.mendmix.cos.provider.qcloud.QcloudProvider) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)44 IOException (java.io.IOException)13 CObjectMetadata (com.mendmix.cos.CObjectMetadata)4 CUploadResult (com.mendmix.cos.CUploadResult)4 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Request (okhttp3.Request)4 ApiInfo (com.mendmix.common.model.ApiInfo)2 WrapperResponse (com.mendmix.common.model.WrapperResponse)2 BizSystemModule (com.mendmix.gateway.model.BizSystemModule)2 COSObject (com.qcloud.cos.model.COSObject)2 QiniuException (com.qiniu.common.QiniuException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 Map (java.util.Map)2