Search in sources :

Example 1 with VertxRouteMapping

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);
    }
}
Also used : VertxRouteMapping(justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping) Parameter(java.lang.reflect.Parameter)

Example 2 with VertxRouteMapping

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());
        }
    }
}
Also used : Route(io.vertx.ext.web.Route) StringToNumberConverterFactory(justlive.earth.breeze.snow.common.base.convert.support.StringToNumberConverterFactory) DefaultConverterService(justlive.earth.breeze.snow.common.base.convert.support.DefaultConverterService) Set(java.util.Set) Router(io.vertx.ext.web.Router) HashMap(java.util.HashMap) Reflections(org.reflections.Reflections) RoutingContext(io.vertx.ext.web.RoutingContext) StringToBooleanConverter(justlive.earth.breeze.snow.common.base.convert.support.StringToBooleanConverter) Exceptions(justlive.earth.breeze.snow.common.base.exception.Exceptions) Slf4j(lombok.extern.slf4j.Slf4j) ImmutableList(com.google.common.collect.ImmutableList) ErrorCodes(justlive.earth.breeze.snow.common.web.vertx.exception.ErrorCodes) Parameter(java.lang.reflect.Parameter) HttpMethod(io.vertx.core.http.HttpMethod) VertxRoute(justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRoute) VertxRouteMapping(justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping) Map(java.util.Map) StringToCharacterConverter(justlive.earth.breeze.snow.common.base.convert.support.StringToCharacterConverter) BaseConstants(justlive.earth.breeze.snow.common.base.constant.BaseConstants) Handler(io.vertx.core.Handler) Method(java.lang.reflect.Method) RoutingContext(io.vertx.ext.web.RoutingContext) VertxRouteMapping(justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping) HashMap(java.util.HashMap) Map(java.util.Map) Route(io.vertx.ext.web.Route) VertxRoute(justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRoute) HttpMethod(io.vertx.core.http.HttpMethod)

Aggregations

Parameter (java.lang.reflect.Parameter)2 VertxRouteMapping (justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRouteMapping)2 ImmutableList (com.google.common.collect.ImmutableList)1 Handler (io.vertx.core.Handler)1 HttpMethod (io.vertx.core.http.HttpMethod)1 Route (io.vertx.ext.web.Route)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 BaseConstants (justlive.earth.breeze.snow.common.base.constant.BaseConstants)1 DefaultConverterService (justlive.earth.breeze.snow.common.base.convert.support.DefaultConverterService)1 StringToBooleanConverter (justlive.earth.breeze.snow.common.base.convert.support.StringToBooleanConverter)1 StringToCharacterConverter (justlive.earth.breeze.snow.common.base.convert.support.StringToCharacterConverter)1 StringToNumberConverterFactory (justlive.earth.breeze.snow.common.base.convert.support.StringToNumberConverterFactory)1 Exceptions (justlive.earth.breeze.snow.common.base.exception.Exceptions)1 VertxRoute (justlive.earth.breeze.snow.common.web.vertx.annotation.VertxRoute)1 ErrorCodes (justlive.earth.breeze.snow.common.web.vertx.exception.ErrorCodes)1