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);
}
Aggregations