Search in sources :

Example 1 with Handlers

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);
    }
}
Also used : URLImpl(com.networknt.registry.URLImpl) java.util(java.util) Handlers(io.undertow.Handlers) BufferedInputStream(java.io.BufferedInputStream) LoggerFactory(org.slf4j.LoggerFactory) BindException(java.net.BindException) KeyStoreException(java.security.KeyStoreException) AtomicReference(java.util.concurrent.atomic.AtomicReference) java.nio.file(java.nio.file) Undertow(io.undertow.Undertow) OptionMap(org.xnio.OptionMap) InetAddress(java.net.InetAddress) UnrecoverableKeyException(java.security.UnrecoverableKeyException) ZipFile(java.util.zip.ZipFile) ClientResponse(io.undertow.client.ClientResponse) URI(java.net.URI) Config(com.networknt.config.Config) ZipEntry(java.util.zip.ZipEntry) UndertowOptions(io.undertow.UndertowOptions) SecretConstants(com.networknt.common.SecretConstants) Logger(org.slf4j.Logger) DecryptUtil(com.networknt.common.DecryptUtil) URL(com.networknt.registry.URL) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Util(com.networknt.utility.Util) MiddlewareHandler(com.networknt.handler.MiddlewareHandler) SingletonServiceFactory(com.networknt.service.SingletonServiceFactory) HttpHandler(io.undertow.server.HttpHandler) Options(org.xnio.Options) CountDownLatch(java.util.concurrent.CountDownLatch) Registry(com.networknt.registry.Registry) SwitcherUtil(com.networknt.switcher.SwitcherUtil) ClientConnection(io.undertow.client.ClientConnection) MDC(org.slf4j.MDC) Constants(com.networknt.utility.Constants) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientRequest(io.undertow.client.ClientRequest) Headers(io.undertow.util.Headers) Methods(io.undertow.util.Methods) javax.net.ssl(javax.net.ssl) Http2Client(com.networknt.client.Http2Client) IoUtils(org.xnio.IoUtils) InputStream(java.io.InputStream) MiddlewareHandler(com.networknt.handler.MiddlewareHandler) HttpHandler(io.undertow.server.HttpHandler)

Aggregations

Http2Client (com.networknt.client.Http2Client)1 DecryptUtil (com.networknt.common.DecryptUtil)1 SecretConstants (com.networknt.common.SecretConstants)1 Config (com.networknt.config.Config)1 MiddlewareHandler (com.networknt.handler.MiddlewareHandler)1 Registry (com.networknt.registry.Registry)1 URL (com.networknt.registry.URL)1 URLImpl (com.networknt.registry.URLImpl)1 SingletonServiceFactory (com.networknt.service.SingletonServiceFactory)1 SwitcherUtil (com.networknt.switcher.SwitcherUtil)1 Constants (com.networknt.utility.Constants)1 Util (com.networknt.utility.Util)1 Handlers (io.undertow.Handlers)1 Undertow (io.undertow.Undertow)1 UndertowOptions (io.undertow.UndertowOptions)1 ClientConnection (io.undertow.client.ClientConnection)1 ClientRequest (io.undertow.client.ClientRequest)1 ClientResponse (io.undertow.client.ClientResponse)1 HttpHandler (io.undertow.server.HttpHandler)1 Headers (io.undertow.util.Headers)1