Java Code Examples for io.vertx.ext.web.Route#path()
The following examples show how to use
io.vertx.ext.web.Route#path() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 初始化前置路由器 * * @param path * 路径 * @param method * 类型 * @param consumes * 接收类型 * @param route * 路由 * @throws Exception */ public void initBeforeHandler(VxApis api, Route route) throws Exception { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } // 添加consumes if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } // 添加handler VxApiBeforeHandlerOptions options = api.getBeforeHandlerOptions(); VxApiBeforeHandler beforeHandler = VxApiBeforeHandlerFactory.getBeforeHandler(options.getInFactoryName(), options.getOption(), api, httpClient); route.handler(beforeHandler); }
Example 2
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 初始化后置路由器 * * @param path * 路径 * @param method * 类型 * @param consumes * 接收类型 * @param route * 路由 * @throws Exception */ public void initAfterHandler(VxApis api, Route route) throws Exception { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } // 添加consumes if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } // 添加handler VxApiAfterHandlerOptions options = api.getAfterHandlerOptions(); VxApiAfterHandler afterHandler = VxApiAfterHandlerFactory.getAfterHandler(options.getInFactoryName(), options.getOption(), api, httpClient); route.handler(afterHandler); }
Example 3
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 初始化流量限制 * * @param api * @param route */ public void initApiLimit(VxApis api, Route route) { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } // 添加consumes if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } if (api.getLimitUnit() != null) { if (api.getApiLimit() <= -1 && api.getIpLimit() <= -1) { api.setLimitUnit(null); } } // 流量限制处理处理器 VxApiRouteHandlerApiLimit apiLimitHandler = VxApiRouteHandlerApiLimit.create(api); route.handler(apiLimitHandler); }
Example 4
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 初始化异常Handler * * @param api * @param route */ public void initExceptionHanlder(VxApis api, Route route) { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } route.failureHandler(rct -> { rct.response().putHeader(SERVER, VxApiGatewayAttribute.FULL_NAME).putHeader(CONTENT_TYPE, api.getContentType()) .setStatusCode(api.getResult().getFailureStatus()).end(api.getResult().getFailureExample()); VxApiTrackInfos infos = new VxApiTrackInfos(appName, api.getApiName()); if (rct.failure() != null) { infos.setErrMsg(rct.failure().getMessage()); infos.setErrStackTrace(rct.failure().getStackTrace()); } else { infos.setErrMsg("没有进一步信息 failure 为 null"); } vertx.eventBus().send(thisVertxName + VxApiEventBusAddressConstant.SYSTEM_PLUS_ERROR, infos.toJson()); }); }
Example 5
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 5 votes |
/** * 初始化权限认证 * * @param path * 路径 * @param method * 类型 * @param consumes * 接收类型 * @param route * 路由 * @throws Exception */ public void initAuthHandler(VxApis api, Route route) throws Exception { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } // 添加consumes if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } // 添加handler VxApiAuthOptions authOptions = api.getAuthOptions(); VxApiAuth authHandler = VxApiAuthFactory.getVxApiAuth(authOptions.getInFactoryName(), authOptions.getOption(), api, httpClient); route.handler(authHandler); }
Example 6
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 5 votes |
/** * 初始化参数检查,参数检查已经交给处理器做了 * * @param api * @param route */ public void initParamCheck(VxApis api, Route route) { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } // 添加consumes if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } VxApiRouteHandlerParamCheck paramCheckHandler = VxApiRouteHandlerParamCheck.create(api, appOption.getContentLength()); route.handler(paramCheckHandler); }
Example 7
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 5 votes |
/** * 初始化与后端服务交互 * * @param isNext * 下一步还是结束(也就是说如有后置处理器inNext=true,反则false) * @param api * @param route * @throws Exception */ public void initServerHandler(boolean isNext, VxApis api, Route route) throws Exception { route.path(api.getPath()); if (api.getMethod() != HttpMethodEnum.ALL) { route.method(HttpMethod.valueOf(api.getMethod().getVal())); } if (api.getConsumes() != null) { api.getConsumes().forEach(va -> route.consumes(va)); } if (api.getServerEntrance().getServerType() == ApiServerTypeEnum.CUSTOM) { serverCustomTypeHandler(isNext, api, route); } else if (api.getServerEntrance().getServerType() == ApiServerTypeEnum.REDIRECT) { serverRedirectTypeHandler(isNext, api, route); } else if (api.getServerEntrance().getServerType() == ApiServerTypeEnum.HTTP_HTTPS) { serverHttpTypeHandler(isNext, api, route); } else { route.handler(rct -> { // TODO 当没有响应服务时next或者结束请求 if (isNext) { rct.next(); } else { rct.response().putHeader(SERVER, VxApiGatewayAttribute.FULL_NAME).putHeader(CONTENT_TYPE, api.getContentType()).setStatusCode(404) .end(); } }); } }