use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method deleteBucket.
@Override
public void deleteBucket(String bucketName) {
bucketName = buildBucketName(bucketName);
String path = "/drop/" + bucketName + "\n";
String accessToken = auth.sign(path);
String url = "http://rs.qiniu.com/drop/" + bucketName;
Request request = new Request.Builder().url(url).addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Authorization", "QBox " + accessToken).build();
okhttp3.Response re = null;
try {
re = httpClient.newCall(request).execute();
if (!re.isSuccessful()) {
throw new JeesuiteBaseException(re.code(), re.message());
}
} catch (IOException e) {
throw new JeesuiteBaseException(e.getMessage());
}
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class CurrentSystemHolder method updateModuleRouteInfos.
/**
* @param module
* @param definition
*/
private static void updateModuleRouteInfos(BizSystemModule module, List<RouteDefinition> defaultRouteDefs) {
RouteDefinition routeDef = defaultRouteDefs.stream().filter(def -> StringUtils.equalsIgnoreCase(module.getServiceId(), def.getId())).findFirst().orElse(null);
if (routeDef == null)
return;
FilterDefinition stripPrefixDef = routeDef.getFilters().stream().filter(p -> "StripPrefix".equals(p.getName())).findFirst().orElse(null);
int stripPrefix = 0;
if (stripPrefixDef != null) {
stripPrefix = Integer.parseInt(stripPrefixDef.getArgs().get("_genkey_0"));
}
module.setStripPrefix(stripPrefix);
PredicateDefinition pathDef = routeDef.getPredicates().stream().filter(p -> "Path".equals(p.getName())).findFirst().orElse(null);
if (pathDef != null) {
String pathPattern = pathDef.getArgs().get("_genkey_0");
if (!pathPattern.startsWith(GatewayConstants.PATH_PREFIX)) {
throw new JeesuiteBaseException("route path must startWith:" + GatewayConstants.PATH_PREFIX);
}
String[] parts = StringUtils.split(pathPattern, "/");
module.setRouteName(parts[1]);
}
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class AbstracRequestFilter method filter.
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
exchange.getAttributes().put(GatewayConstants.CONTEXT_REQUEST_START_TIME, System.currentTimeMillis());
String requestUri = exchange.getRequest().getPath().value();
if (ignoreUris.stream().anyMatch(o -> requestUri.endsWith(o))) {
exchange.getAttributes().put(GatewayConstants.CONTEXT_IGNORE_FILTER, Boolean.TRUE);
return chain.filter(exchange);
}
BizSystemModule module = RuequestHelper.getCurrentModule(exchange);
try {
Builder requestBuilder = exchange.getRequest().mutate();
for (PreFilterHandler handler : handlers) {
requestBuilder = handler.process(exchange, module, requestBuilder);
}
exchange = exchange.mutate().request(requestBuilder.build()).build();
} catch (Exception e) {
exchange.getAttributes().clear();
if (e instanceof JeesuiteBaseException == false) {
logger.error("requestFilter_error", e);
}
ServerHttpResponse response = exchange.getResponse();
byte[] bytes = JsonUtils.toJson(WrapperResponse.fail(e)).getBytes(StandardCharsets.UTF_8);
return response.writeWith(Mono.just(response.bufferFactory().wrap(bytes)));
}
return chain.filter(exchange);
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class SensitiveOperProtectHandler method onInterceptor.
@Override
public Object onInterceptor(InvocationVals invocation) throws Throwable {
Object[] objects = invocation.getArgs();
MappedStatement ms = (MappedStatement) objects[0];
if (ms.getSqlCommandType().equals(SqlCommandType.DELETE)) {
throw new JeesuiteBaseException(4003, "当前已开启敏感操作保护");
}
return null;
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class CustomErrorDecoder method decode.
@Override
public Exception decode(String methodKey, Response response) {
if (response.body() != null) {
try {
String content = CharStreams.toString(new InputStreamReader(response.body().asInputStream(), StandardCharsets.UTF_8));
Map responseBody = JsonUtils.toObject(content, Map.class);
if (responseBody.containsKey("code")) {
int code = Integer.parseInt(responseBody.get("code").toString());
return new JeesuiteBaseException(code, Objects.toString(responseBody.get("msg")));
}
} catch (Exception e) {
}
} else {
logger.error("feign_client_error ->method:{},status:{},message:{}", methodKey, response.status(), response.reason());
String message = response.reason();
if (message == null)
message = "服务调用错误";
return new JeesuiteBaseException(response.status(), message + "(" + methodKey + ")");
}
String error = String.format("feign_client_error ->method:%s,status:%s,message:%s", methodKey, response.status(), response.reason());
return new JeesuiteBaseException(500, error);
}
Aggregations