Search in sources :

Example 1 with ContextPathPredicate

use of com.adeptj.runtime.predicate.ContextPathPredicate in project adeptj-runtime by AdeptJ.

the class Server method createHandlerChain.

/**
 * Chaining of Undertow {@link HttpHandler} instances as follows.
 * <p>
 * 1. GracefulShutdownHandler
 * 2. RequestLimitingHandler
 * 3. AllowedMethodsHandler
 * 4. PathHandler which resolves to either PredicateHandler or HealthCheckHandler
 * 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
 * 5. And Finally HttpContinueReadHandler
 *
 * @param httpContinueReadHandler the {@link io.undertow.server.handlers.HttpContinueReadHandler}
 * @param cfg                     the undertow server config object.
 * @return GracefulShutdownHandler as the root handler
 */
private GracefulShutdownHandler createHandlerChain(HttpHandler httpContinueReadHandler, Config cfg) {
    RedirectHandler contextHandler = Handlers.redirect(cfg.getString(KEY_SYSTEM_CONSOLE_PATH));
    RequestBufferingHandler requestBufferingHandler = new RequestBufferingHandler(httpContinueReadHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS)));
    HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeaderHandler(requestBufferingHandler, SERVER_STRING, cfg.getString(KEY_HEADER_SERVER)) : new SetHeaderHandler(httpContinueReadHandler, SERVER_STRING, cfg.getString(KEY_HEADER_SERVER));
    ContextPathPredicate contextPathPredicate = new ContextPathPredicate(cfg.getString(KEY_CONTEXT_PATH));
    PredicateHandler predicateHandler = Handlers.predicate(contextPathPredicate, contextHandler, headersHandler);
    PathHandler pathHandler = Handlers.path(predicateHandler).addPrefixPath(cfg.getString(KEY_HEALTH_CHECK_HANDLER_PATH), new HealthCheckHandler());
    AllowedMethodsHandler allowedMethodsHandler = new AllowedMethodsHandler(pathHandler, this.allowedMethods(cfg));
    int maxConcurrentRequests = Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQUESTS));
    int queueSize = Integer.getInteger(SYS_PROP_REQ_LIMIT_QUEUE_SIZE, cfg.getInt(KEY_REQ_LIMIT_QUEUE_SIZE));
    RequestLimit limit = new RequestLimit(maxConcurrentRequests, queueSize);
    RequestLimitingHandler requestLimitingHandler = Handlers.requestLimitingHandler(limit, allowedMethodsHandler);
    return Handlers.gracefulShutdown(requestLimitingHandler);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) AllowedMethodsHandler(io.undertow.server.handlers.AllowedMethodsHandler) RequestLimit(io.undertow.server.handlers.RequestLimit) RequestBufferingHandler(io.undertow.server.handlers.RequestBufferingHandler) RedirectHandler(io.undertow.server.handlers.RedirectHandler) SetHeaderHandler(io.undertow.server.handlers.SetHeaderHandler) ContextPathPredicate(com.adeptj.runtime.predicate.ContextPathPredicate) PathHandler(io.undertow.server.handlers.PathHandler) PredicateHandler(io.undertow.server.handlers.PredicateHandler) HealthCheckHandler(com.adeptj.runtime.handler.HealthCheckHandler) RequestLimitingHandler(io.undertow.server.handlers.RequestLimitingHandler) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint)

Aggregations

HealthCheckHandler (com.adeptj.runtime.handler.HealthCheckHandler)1 ContextPathPredicate (com.adeptj.runtime.predicate.ContextPathPredicate)1 HttpHandler (io.undertow.server.HttpHandler)1 AllowedMethodsHandler (io.undertow.server.handlers.AllowedMethodsHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 PredicateHandler (io.undertow.server.handlers.PredicateHandler)1 RedirectHandler (io.undertow.server.handlers.RedirectHandler)1 RequestBufferingHandler (io.undertow.server.handlers.RequestBufferingHandler)1 RequestLimit (io.undertow.server.handlers.RequestLimit)1 RequestLimitingHandler (io.undertow.server.handlers.RequestLimitingHandler)1 SetHeaderHandler (io.undertow.server.handlers.SetHeaderHandler)1 SecurityConstraint (io.undertow.servlet.api.SecurityConstraint)1