use of com.networknt.handler.MiddlewareHandler 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;
}
Aggregations