use of justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping in project earth-snow by justlive1.
the class RouteRegisterFactory method parseVertxRouteMapping.
/**
* 解析{@code VertxRoute}注解类下注解了{@code VertxRouteMapping}的方法
*
* @param root
* @param method
* @param bean
*/
private void parseVertxRouteMapping(String root, Method method, Object bean) {
VertxRouteMapping routeMapping = method.getAnnotation(VertxRouteMapping.class);
String[] paths = routeMapping.value();
String baseUrl = "";
if (root.length() != 0) {
baseUrl = BaseConstants.ROOT_PATH.concat(root);
}
for (String path : paths) {
String url = "";
String p = transferUri(path);
if (p.length() != 0) {
url = baseUrl.concat(BaseConstants.ROOT_PATH).concat(p);
}
if (routeWraps.containsKey(url)) {
throw Exceptions.fail(ErrorCodes.URL_HAS_BOUND);
}
Parameter[] parameters = method.getParameters();
ParamWrap[] paramWraps = parseVertxRouterParamters(parameters);
RouteWrap wrap = new RouteWrap(url, method, bean, paramWraps, routeMapping);
routeWraps.put(url, wrap);
}
}
use of justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping in project earth-snow by justlive1.
the class RouteRegisterFactory method register.
/**
* 讲Route注册到vertx中
*/
private void register() {
for (Map.Entry<String, RouteWrap> entry : routeWraps.entrySet()) {
RouteWrap wrap = entry.getValue();
VertxRouteMapping routeMapping = wrap.getRouteMapping();
Route route = router.route().path(entry.getKey());
for (String consume : routeMapping.consumes()) {
route.consumes(consume);
}
for (String produce : routeMapping.produces()) {
route.produces(produce);
}
for (HttpMethod method : routeMapping.method()) {
route.method(method);
}
Handler<RoutingContext> handler = ctx -> executeWithArgs(wrap, ctx);
if (routeMapping.blocking()) {
route.blockingHandler(handler);
} else {
route.handler(handler);
}
if (log.isDebugEnabled()) {
log.debug("register url [{}]", entry.getKey());
}
}
}
Aggregations