Search in sources :

Example 1 with HandlerProvider

use of com.networknt.handler.HandlerProvider in project light-4j by networknt.

the class Server method middlewareInit.

private static HttpHandler middlewareInit() {
    HttpHandler handler = null;
    // API routing handler or others handler implemented by application developer.
    HandlerProvider handlerProvider = SingletonServiceFactory.getBean(HandlerProvider.class);
    if (handlerProvider != null) {
        handler = handlerProvider.getHandler();
    }
    if (handler == null) {
        logger.error("Unable to start the server - no route handler provider available in service.yml");
        throw new RuntimeException("Unable to start the server - no route handler provider available in service.yml");
    }
    // Middleware Handlers plugged into the handler chain.
    MiddlewareHandler[] middlewareHandlers = SingletonServiceFactory.getBeans(MiddlewareHandler.class);
    if (middlewareHandlers != null) {
        for (int i = middlewareHandlers.length - 1; i >= 0; i--) {
            logger.info("Plugin: " + middlewareHandlers[i].getClass().getName());
            if (middlewareHandlers[i].isEnabled()) {
                handler = middlewareHandlers[i].setNext(handler);
                middlewareHandlers[i].register();
            }
        }
    }
    return handler;
}
Also used : MiddlewareHandler(com.networknt.handler.MiddlewareHandler) HttpHandler(io.undertow.server.HttpHandler) HandlerProvider(com.networknt.handler.HandlerProvider)

Aggregations

HandlerProvider (com.networknt.handler.HandlerProvider)1 MiddlewareHandler (com.networknt.handler.MiddlewareHandler)1 HttpHandler (io.undertow.server.HttpHandler)1