use of io.undertow.Handlers in project light-4j by networknt.
the class Server method start.
public static void start() {
// add shutdown hook here.
addDaemonShutdownHook();
// add startup hooks here.
StartupHookProvider[] startupHookProviders = SingletonServiceFactory.getBeans(StartupHookProvider.class);
if (startupHookProviders != null)
Arrays.stream(startupHookProviders).forEach(s -> s.onStartup());
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();
}
}
}
if (config.dynamicPort) {
for (int i = config.minPort; i < config.maxPort; i++) {
boolean b = bind(handler, i);
if (b) {
break;
}
}
} else {
bind(handler, -1);
}
}
Aggregations