Search in sources :

Example 11 with JeesuiteBaseException

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());
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Request(okhttp3.Request) IOException(java.io.IOException)

Example 12 with JeesuiteBaseException

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]);
    }
}
Also used : FilterDefinition(org.springframework.cloud.gateway.filter.FilterDefinition) RouteDefinition(org.springframework.cloud.gateway.route.RouteDefinition) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) PredicateDefinition(org.springframework.cloud.gateway.handler.predicate.PredicateDefinition)

Example 13 with JeesuiteBaseException

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);
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) BizSystemModule(com.mendmix.gateway.model.BizSystemModule) Builder(org.springframework.http.server.reactive.ServerHttpRequest.Builder) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse)

Example 14 with JeesuiteBaseException

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;
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) MappedStatement(org.apache.ibatis.mapping.MappedStatement)

Example 15 with JeesuiteBaseException

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Map(java.util.Map) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException)

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