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());
}
}
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);
}
}
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;
}
}
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);
}
}
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);
}
Aggregations