Search in sources :

Example 6 with HttpMethod

use of com.blade.mvc.http.HttpMethod in project blade by biezhi.

the class Routers method addRoute.

public void addRoute(HttpMethod httpMethod, String path, com.blade.mvc.handler.RouteHandler handler, String methodName) throws NoSuchMethodException {
    Class<?> handleType = handler.getClass();
    Method method = handleType.getMethod(methodName, Request.class, Response.class);
    addRoute(httpMethod, path, handler, com.blade.mvc.handler.RouteHandler.class, method);
}
Also used : HttpMethod(com.blade.mvc.http.HttpMethod) Method(java.lang.reflect.Method)

Example 7 with HttpMethod

use of com.blade.mvc.http.HttpMethod in project blade by biezhi.

the class Routers method route.

public void route(String path, Class<?> clazz, String methodName, HttpMethod httpMethod) {
    try {
        Assert.notNull(path, "Route path not is null!");
        Assert.notNull(clazz, "Class Type not is null!");
        Assert.notNull(methodName, "Method name not is null");
        Assert.notNull(httpMethod, "Request Method not is null");
        Method[] methods = classMethosPool.get(clazz.getName());
        if (null == methods) {
            methods = clazz.getMethods();
            classMethosPool.put(clazz.getName(), methods);
        }
        if (null != methods) {
            for (Method method : methods) {
                if (method.getName().equals(methodName)) {
                    Object controller = controllerPool.get(clazz);
                    if (null == controller) {
                        controller = ReflectKit.newInstance(clazz);
                        controllerPool.put(clazz, controller);
                    }
                    addRoute(httpMethod, path, controller, clazz, method);
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : HttpMethod(com.blade.mvc.http.HttpMethod) Method(java.lang.reflect.Method) BladeException(com.blade.exception.BladeException)

Example 8 with HttpMethod

use of com.blade.mvc.http.HttpMethod in project blade by biezhi.

the class AbstractFileRouteLoader method buildRoute.

/**
     * Construct a routing object
     *
     * @param httpMethod        request httpMethod
     * @param path                route path
     * @param controllerName    controller name
     * @param methodName        method name
     * @return return route object
     * @throws RouteException
     */
private Route buildRoute(String httpMethod, String path, String controllerName, String methodName) throws RouteException {
    Object controller = controllerLoader.load(controllerName);
    Class<?> controllerType = controller.getClass();
    Method method = getMethod(controllerType, methodName);
    return new Route(HttpMethod.valueOf(httpMethod.toUpperCase()), path, controller, controllerType, method);
}
Also used : HttpMethod(com.blade.mvc.http.HttpMethod) Method(java.lang.reflect.Method) Route(com.blade.mvc.route.Route)

Aggregations

HttpMethod (com.blade.mvc.http.HttpMethod)8 Method (java.lang.reflect.Method)4 BladeException (com.blade.exception.BladeException)2 Matcher (java.util.regex.Matcher)2 Controller (com.blade.mvc.annotation.Controller)1 RestController (com.blade.mvc.annotation.RestController)1 Route (com.blade.mvc.annotation.Route)1 Route (com.blade.mvc.route.Route)1 URISyntaxException (java.net.URISyntaxException)1