Search in sources :

Example 31 with JeesuiteBaseException

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

the class QcloudProvider method getObjectMetadata.

@Override
public CObjectMetadata getObjectMetadata(String bucketName, String fileKey) {
    try {
        String _bucketName = buildBucketName(bucketName);
        String _fileKey = resolveFileKey(bucketName, fileKey);
        ObjectMetadata metadata = cosclient.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, buildMessage(bucketName, e));
    }
}
Also used : CObjectMetadata(com.mendmix.cos.CObjectMetadata) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) CObjectMetadata(com.mendmix.cos.CObjectMetadata) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) CosServiceException(com.qcloud.cos.exception.CosServiceException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) IOException(java.io.IOException)

Example 32 with JeesuiteBaseException

use of com.mendmix.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.mendmix.common.JeesuiteBaseException) CosServiceException(com.qcloud.cos.exception.CosServiceException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) IOException(java.io.IOException)

Example 33 with JeesuiteBaseException

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

the class QcloudProvider method createBucket.

@Override
public void createBucket(String bucketName, boolean isPrivate) {
    bucketName = buildBucketName(bucketName);
    if (cosclient.doesBucketExist(bucketName)) {
        throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
    }
    CreateBucketRequest request = new CreateBucketRequest(bucketName);
    if (isPrivate) {
        request.setCannedAcl(CannedAccessControlList.Private);
    } else {
        request.setCannedAcl(CannedAccessControlList.PublicRead);
    }
    cosclient.createBucket(request);
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) CreateBucketRequest(com.qcloud.cos.model.CreateBucketRequest)

Example 34 with JeesuiteBaseException

use of com.mendmix.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 = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).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.mendmix.common.annotation.ApiMetadata) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) HttpServletRequest(javax.servlet.http.HttpServletRequest) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Around(org.aspectj.lang.annotation.Around)

Example 35 with JeesuiteBaseException

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

the class ActuatorController method health.

@GetMapping("/health")
public Map<String, Object> health(@RequestParam(value = "details", required = false) boolean details) {
    Map<String, Object> result = new HashMap<>(1);
    result.put("status", "UP");
    result.put("startTime", GlobalRuntimeContext.STARTUP_TIME);
    if (details) {
        Collection<BizSystemModule> modules = CurrentSystemHolder.getModules();
        Map<String, Object> moduleStatus = new HashMap<>(modules.size());
        for (BizSystemModule module : modules) {
            try {
                String status = HttpRequestEntity.get(module.getHealthUri()).execute().toValue("status");
                moduleStatus.put(module.getServiceId(), status);
            } catch (JeesuiteBaseException e) {
                if (e.getCode() == 404 || e.getCode() == 401 || e.getCode() == 403) {
                    result.put(module.getServiceId(), "UP");
                } else {
                    result.put(module.getServiceId(), "UNKNOW");
                }
            } catch (Exception e) {
                result.put(module.getServiceId(), "UNKNOW");
            }
        }
        result.put("modules", moduleStatus);
    }
    return result;
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) HashMap(java.util.HashMap) BizSystemModule(com.mendmix.gateway.model.BizSystemModule) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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