Search in sources :

Example 11 with ControllerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ControllerProxy in project ezyhttp by youngmonkeys.

the class RequestHandlersImplementer method implement.

public Map<RequestURI, List<RequestHandler>> implement(Object controller) {
    Map<RequestURI, List<RequestHandler>> handlers = new HashMap<>();
    ControllerProxy proxy = new ControllerProxy(controller);
    String feature = proxy.getFeature();
    for (RequestHandlerMethod method : proxy.getRequestHandlerMethods()) {
        RequestHandlerImplementer implementer = newImplementer(proxy, method);
        RequestHandler handler = implementer.implement();
        HttpMethod httpMethod = handler.getMethod();
        String requestURI = handler.getRequestURI();
        String methodFeature = method.getFeature();
        RequestURIMeta uriMeta = RequestURIMeta.builder().api(method.isApi() || proxy.isApi()).authenticated(method.isAuthenticated() || proxy.isAuthenticated()).management(method.isManagement() || proxy.isManagement()).payment(method.isPayment() || proxy.isPayment()).feature(methodFeature != null ? methodFeature : feature).build();
        RequestURI uri = new RequestURI(httpMethod, requestURI, uriMeta);
        handlers.computeIfAbsent(uri, k -> new ArrayList<>()).add(handler);
    }
    return handlers;
}
Also used : Setter(lombok.Setter) Collection(java.util.Collection) EzyLoggable(com.tvd12.ezyfox.util.EzyLoggable) HashMap(java.util.HashMap) RequestURIDecorator(com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator) ArrayList(java.util.ArrayList) List(java.util.List) RequestURIMeta(com.tvd12.ezyhttp.server.core.request.RequestURIMeta) Map(java.util.Map) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) HttpMethod(com.tvd12.ezyhttp.core.constant.HttpMethod) RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RequestURIMeta(com.tvd12.ezyhttp.server.core.request.RequestURIMeta) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) ArrayList(java.util.ArrayList) List(java.util.List) HttpMethod(com.tvd12.ezyhttp.core.constant.HttpMethod)

Aggregations

ControllerProxy (com.tvd12.ezyhttp.server.core.reflect.ControllerProxy)10 Test (org.testng.annotations.Test)10 BaseTest (com.tvd12.test.base.BaseTest)8 RequestHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod)5 RequestHandlerImplementer (com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer)4 HomeController (com.tvd12.ezyhttp.server.boot.test.controller.HomeController)2 HomeController (com.tvd12.ezyhttp.server.core.test.controller.HomeController)2 HomeController (com.tvd12.ezyhttp.server.jetty.test.controller.HomeController)2 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 EzyLoggable (com.tvd12.ezyfox.util.EzyLoggable)1 EzyRequestControllerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy)1 HelloController (com.tvd12.ezyfoxserver.support.test.controller.HelloController)1 HttpMethod (com.tvd12.ezyhttp.core.constant.HttpMethod)1 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1 RequestURIDecorator (com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator)1 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)1 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)1 RequestURIMeta (com.tvd12.ezyhttp.server.core.request.RequestURIMeta)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1