use of com.mendmix.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class RuequestHelper method getCurrentApi.
public static ApiInfo getCurrentApi(ServerWebExchange exchange) {
ApiInfo api = exchange.getAttribute(GatewayConstants.CONTEXT_CURRENT_API);
if (api != null)
return api;
BizSystemModule module = getCurrentModule(exchange);
ServerHttpRequest request = exchange.getRequest();
ApiInfo apiInfo = module.getApiInfo(request.getMethodValue(), request.getPath().value());
if (apiInfo != null) {
exchange.getAttributes().put(GatewayConstants.CONTEXT_CURRENT_API, apiInfo);
}
return apiInfo;
}
use of com.mendmix.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class CurrentSystemHolder method loadLocalRouteModules.
private static void loadLocalRouteModules() {
if (localModules != null)
return;
localModules = new ArrayList<>();
List<RouteDefinition> defaultRouteDefs = InstanceFactory.getInstance(GatewayProperties.class).getRoutes();
Properties properties = ResourceUtils.getAllProperties("spring.cloud.gateway.routes");
Set<Entry<Object, Object>> entrySet = properties.entrySet();
BizSystemModule module;
String prefix;
for (Entry<Object, Object> entry : entrySet) {
if (entry.getKey().toString().endsWith(".id")) {
prefix = entry.getKey().toString().replace(".id", "");
module = new BizSystemModule();
module.setDefaultRoute(true);
module.setServiceId(entry.getValue().toString());
module.setProxyUri(properties.getProperty(prefix + ".uri"));
module.setAnonymousUris(properties.getProperty(prefix + ".anonymousUris"));
//
updateModuleRouteInfos(module, defaultRouteDefs);
localModules.add(module);
}
}
}
use of com.mendmix.gateway.model.BizSystemModule 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.gateway.model.BizSystemModule 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;
}
use of com.mendmix.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class RouteErrorWebExceptionHandler method getErrorAttributes.
@Override
protected Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
Throwable error = super.getError(request);
logger.warn("routeError{},errorType:{},errorMsg:{}", LogMessageFormat.buildLogTail(request.path()), error.getClass().getName(), error.getMessage());
String msg = error.getMessage();
Integer code = HttpStatus.INTERNAL_SERVER_ERROR.value();
if (msg.contains("Connection refused") || msg.contains("connection timed out")) {
msg = "Service Unavailable";
code = 503;
}
Map<String, Object> errorAttributes = new HashMap<>(3);
errorAttributes.put(GlobalConstants.PARAM_MSG, msg);
errorAttributes.put(GlobalConstants.PARAM_CODE, code);
Map<String, String> data = new HashMap<>(2);
String routeName = RuequestHelper.resolveRouteName(request.path());
BizSystemModule module = CurrentSystemHolder.getModule(routeName);
data.put("serviceId", module.getServiceId());
data.put("path", request.path());
errorAttributes.put(GlobalConstants.PARAM_DATA, data);
return errorAttributes;
}
Aggregations