use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class EntityUtil method putAnnotationValue.
/**
* 修改注解中的值
*
* @param annotation 注解
* @param k 方法名
* @param v 值
*/
public static void putAnnotationValue(Annotation annotation, String k, Object v) {
try {
InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
Field value = invocationHandler.getClass().getDeclaredField("memberValues");
value.setAccessible(true);
@SuppressWarnings("unchecked") Map<String, Object> memberValues = (Map<String, Object>) value.get(invocationHandler);
memberValues.put(k, v);
} catch (Exception e) {
throw new BusinessException(ExceptionUtil.getMessage(e));
}
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class SignInterceptor method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Object[] args = invocation.getArguments();
Method method = invocation.getMethod();
// 判断是否需要验签
boolean needSign = this.needSign(method);
if (needSign) {
HttpServletRequest request = getRequest();
// 获取签名Sign
String sign = request.getHeader(Sign.SIGN);
Assert.notBlank(sign, "Header[Sign]不能为空");
// 获取时间戳
Long timestamp = Convert.toLong(request.getHeader(Sign.TIMESTAMP));
Assert.notNull(timestamp, "Header[Timestamp]不能为空");
// 重放时间限制(单位)
Long difference = DateUtil.between(DateUtil.date(), DateUtil.date(timestamp), DateUnit.SECOND);
if (difference > config.getTimeout()) {
log.info("前端时间戳:{},服务端时间戳:{}", DateUtil.date(timestamp), DateUtil.date());
throw new BusinessException("已过期的签名");
}
Map<String, Object> signMap = this.buildSignMap(args, method.getParameters());
// 验签
this.checkSign(signMap, sign, timestamp);
}
return invocation.proceed();
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class LicenseController method upload.
@PostMapping(value = "upload")
public Response<LicenseCheckModel> upload(@NotNull MultipartFile licenseFile) {
String ciphertext = null;
try (InputStream in = licenseFile.getInputStream()) {
// 获取密文
ciphertext = IoUtil.readUtf8(in);
Assert.notBlank(ciphertext, "licesne密文解析失败");
// 解析证书内容
String json = config.getRsa().decryptStr(ciphertext, KeyType.PrivateKey);
LicenseCheckModel checkModel = JSONUtil.toBean(json, LicenseCheckModel.class);
return Response.ok(checkModel);
} catch (Exception e) {
throw new BusinessException(StrUtil.format("[证书生成失败! error={},无效的密文:{}]", e.getMessage(), ciphertext));
}
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class TencentMapService method distanceOneToMany.
/**
* 距离计算
*/
@Override
public DistanceResolveDTO distanceOneToMany(DistanceVO vo) throws Exception {
vo.setKey(key);
Map<String, Object> map = BeanUtil.beanToMap(vo);
String get = HttpUtil.get(distanceUrl, map);
DistanceResolveDTO dto = JSONUtil.toBean(get, DistanceResolveDTO.class);
if (!SUCCESS.equals(dto.getStatus())) {
throw new BusinessException(dto.getMessage());
}
return dto;
}
use of com.chao.cloud.common.exception.BusinessException in project chao-cloud by chaojunzi.
the class ZipVelocityTemplateEngine method writer.
public void writer(VelocityContext context, String templatePath, ZipOutputStream zip, String zipNodeFile) throws Exception {
if (StrUtil.isBlank(templatePath)) {
return;
}
VelocityEngine velocityEngine = (VelocityEngine) ReflectUtil.getFieldValue(this, "velocityEngine");
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = velocityEngine.getTemplate(templatePath, ConstVal.UTF8);
tpl.merge(context, sw);
try {
// 获取全局配置信息
String outputDir = getConfigBuilder().getGlobalConfig().getOutputDir();
// 替换->修复路径
zipNodeFile = StrUtil.removePrefix(FileUtil.normalize(zipNodeFile.replace(outputDir, "")), "/");
// 添加到zip
zip.putNextEntry(new ZipEntry(zipNodeFile));
IOUtils.write(sw.toString(), zip, "UTF-8");
IOUtils.closeQuietly(sw);
zip.closeEntry();
} catch (IOException e) {
throw new BusinessException("渲染模板失败,模块:" + zipNodeFile);
}
logger.info("模板: {};", zipNodeFile);
}
Aggregations