Search in sources :

Example 1 with HEADER_SERVER

use of com.adeptj.runtime.common.Constants.HEADER_SERVER in project adeptj-runtime by AdeptJ.

the class Server method rootHandler.

/**
 * Chaining of Undertow {@link HttpHandler} instances as follows.
 * <p>
 * 1. GracefulShutdownHandler
 * 2. RequestLimitingHandler
 * 3. AllowedMethodsHandler
 * 4. PredicateHandler which resolves to either RedirectHandler or SetHeadersHandler
 * 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
 * 5. And Finally ServletInitialHandler
 *
 * @param servletInitialHandler the {@link io.undertow.servlet.handlers.ServletInitialHandler}
 * @return GracefulShutdownHandler as the root handler
 */
private GracefulShutdownHandler rootHandler(HttpHandler servletInitialHandler) {
    Config cfg = Objects.requireNonNull(this.cfgReference.get());
    Map<HttpString, String> headers = new HashMap<>();
    headers.put(HttpString.tryFromString(HEADER_SERVER), cfg.getString(KEY_HEADER_SERVER));
    if (Environment.isDev()) {
        headers.put(HttpString.tryFromString(HEADER_X_POWERED_BY), Version.getFullVersionString());
    }
    HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeadersHandler(new RequestBufferingHandler(servletInitialHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS))), headers) : new SetHeadersHandler(servletInitialHandler, headers);
    return Handlers.gracefulShutdown(new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)), new AllowedMethodsHandler(Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()), Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler), this.allowedMethods(cfg))));
}
Also used : KEY_HTTPS(com.adeptj.runtime.server.ServerConstants.KEY_HTTPS) KEY_MAX_CONCURRENT_REQS(com.adeptj.runtime.common.Constants.KEY_MAX_CONCURRENT_REQS) CryptoServlet(com.adeptj.runtime.servlet.CryptoServlet) DIR_ADEPTJ_RUNTIME(com.adeptj.runtime.common.Constants.DIR_ADEPTJ_RUNTIME) KEY_HTTP_ONLY(com.adeptj.runtime.server.ServerConstants.KEY_HTTP_ONLY) HttpString(io.undertow.util.HttpString) OptionMap(org.xnio.OptionMap) KEY_WS_WEB_SOCKET_OPTIONS(com.adeptj.runtime.server.ServerConstants.KEY_WS_WEB_SOCKET_OPTIONS) ServerSocket(java.net.ServerSocket) Environment(com.adeptj.runtime.common.Environment) REALM(com.adeptj.runtime.server.ServerConstants.REALM) Map(java.util.Map) ServerLogsWebSocket(com.adeptj.runtime.websocket.ServerLogsWebSocket) HEADER_SERVER(com.adeptj.runtime.common.Constants.HEADER_SERVER) KEY_WS_TASK_MAX_THREADS(com.adeptj.runtime.server.ServerConstants.KEY_WS_TASK_MAX_THREADS) AllowedMethodsHandler(io.undertow.server.handlers.AllowedMethodsHandler) Set(java.util.Set) KEY_WORKER_OPTIONS(com.adeptj.runtime.server.ServerConstants.KEY_WORKER_OPTIONS) CONTEXT_PATH(com.adeptj.runtime.common.Constants.CONTEXT_PATH) ATTRIBUTE_NAME(io.undertow.websockets.jsr.WebSocketDeploymentInfo.ATTRIBUTE_NAME) Stoppable(com.adeptj.runtime.common.Stoppable) KEY_SECURED_URLS_ALLOWED_METHODS(com.adeptj.runtime.server.ServerConstants.KEY_SECURED_URLS_ALLOWED_METHODS) KEY_PORT(com.adeptj.runtime.common.Constants.KEY_PORT) KEY_HTTP(com.adeptj.runtime.common.Constants.KEY_HTTP) SYS_PROP_REQ_BUFF_MAX_BUFFERS(com.adeptj.runtime.server.ServerConstants.SYS_PROP_REQ_BUFF_MAX_BUFFERS) KEY_WORKER_TASK_CORE_THREADS(com.adeptj.runtime.server.ServerConstants.KEY_WORKER_TASK_CORE_THREADS) ArrayList(java.util.ArrayList) Servlets(io.undertow.servlet.Servlets) KEY_AUTH_ROLES(com.adeptj.runtime.server.ServerConstants.KEY_AUTH_ROLES) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) SYS_PROP_SESSION_TIMEOUT(com.adeptj.runtime.server.ServerConstants.SYS_PROP_SESSION_TIMEOUT) CRYPTO_SERVLET(com.adeptj.runtime.server.ServerConstants.CRYPTO_SERVLET) KEY_INVALIDATE_SESSION_ON_LOGOUT(com.adeptj.runtime.server.ServerConstants.KEY_INVALIDATE_SESSION_ON_LOGOUT) KEY_MULTIPART_MAX_REQUEST_SIZE(com.adeptj.runtime.server.ServerConstants.KEY_MULTIPART_MAX_REQUEST_SIZE) KEY_WORKER_TASK_MAX_THREADS(com.adeptj.runtime.server.ServerConstants.KEY_WORKER_TASK_MAX_THREADS) Verb(com.adeptj.runtime.common.Verb) WORKER_TASK_THREAD_MULTIPLIER(com.adeptj.runtime.server.ServerConstants.WORKER_TASK_THREAD_MULTIPLIER) Times(com.adeptj.runtime.common.Times) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) DEFAULT_WAIT_TIME(com.adeptj.runtime.server.ServerConstants.DEFAULT_WAIT_TIME) LinkedHashSet(java.util.LinkedHashSet) DIR_DEPLOYMENT(com.adeptj.runtime.common.Constants.DIR_DEPLOYMENT) SYS_TASK_THREAD_MULTIPLIER(com.adeptj.runtime.server.ServerConstants.SYS_TASK_THREAD_MULTIPLIER) KEY_MULTIPART_FILE_SIZE_THRESHOLD(com.adeptj.runtime.server.ServerConstants.KEY_MULTIPART_FILE_SIZE_THRESHOLD) Config(com.typesafe.config.Config) Files(java.nio.file.Files) TOOLS_CRYPTO_URI(com.adeptj.runtime.common.Constants.TOOLS_CRYPTO_URI) KEY_WS_IO_THREADS(com.adeptj.runtime.server.ServerConstants.KEY_WS_IO_THREADS) SYS_PROP_MAX_CONCUR_REQ(com.adeptj.runtime.server.ServerConstants.SYS_PROP_MAX_CONCUR_REQ) KEY_HOST(com.adeptj.runtime.common.Constants.KEY_HOST) USER_DIR(org.apache.commons.lang3.SystemUtils.USER_DIR) IOException(java.io.IOException) ErrorPageServlet(com.adeptj.runtime.servlet.ErrorPageServlet) RequestLimitingHandler(io.undertow.server.handlers.RequestLimitingHandler) RequestBufferingHandler(io.undertow.server.handlers.RequestBufferingHandler) KEY_MULTIPART_MAX_FILE_SIZE(com.adeptj.runtime.server.ServerConstants.KEY_MULTIPART_MAX_FILE_SIZE) TOOLS_DASHBOARD_URI(com.adeptj.runtime.common.Constants.TOOLS_DASHBOARD_URI) Paths(java.nio.file.Paths) SYS_PROP_ENABLE_REQ_BUFF(com.adeptj.runtime.server.ServerConstants.SYS_PROP_ENABLE_REQ_BUFF) SYS_PROP_SHUTDOWN_WAIT_TIME(com.adeptj.runtime.server.ServerConstants.SYS_PROP_SHUTDOWN_WAIT_TIME) KEY_ERROR_PAGES(com.adeptj.runtime.server.ServerConstants.KEY_ERROR_PAGES) GracefulShutdownHandler(io.undertow.server.handlers.GracefulShutdownHandler) KEY_SECURED_URLS(com.adeptj.runtime.server.ServerConstants.KEY_SECURED_URLS) KEY_DEFAULT_ENCODING(com.adeptj.runtime.server.ServerConstants.KEY_DEFAULT_ENCODING) DEPLOYMENT_NAME(com.adeptj.runtime.common.Constants.DEPLOYMENT_NAME) TOOLS_LOGIN_URI(com.adeptj.runtime.common.Constants.TOOLS_LOGIN_URI) Handlers(io.undertow.Handlers) ToolsServlet(com.adeptj.runtime.servlet.ToolsServlet) ServletException(javax.servlet.ServletException) TOOLS_ERROR_URL(com.adeptj.runtime.server.ServerConstants.TOOLS_ERROR_URL) URL(java.net.URL) KEY_USE_CACHED_AUTH_MECHANISM(com.adeptj.runtime.server.ServerConstants.KEY_USE_CACHED_AUTH_MECHANISM) LoggerFactory(org.slf4j.LoggerFactory) ServletInfo(io.undertow.servlet.api.ServletInfo) Undertow(io.undertow.Undertow) KEY_IGNORE_FLUSH(com.adeptj.runtime.server.ServerConstants.KEY_IGNORE_FLUSH) IOUtils(com.adeptj.runtime.common.IOUtils) KEY_HEADER_SERVER(com.adeptj.runtime.common.Constants.KEY_HEADER_SERVER) ErrorPage(io.undertow.servlet.api.ErrorPage) KEY_ALLOWED_METHODS(com.adeptj.runtime.common.Constants.KEY_ALLOWED_METHODS) KEY_MULTIPART_FILE_LOCATION(com.adeptj.runtime.server.ServerConstants.KEY_MULTIPART_FILE_LOCATION) TOOLS_LOGOUT_URI(com.adeptj.runtime.common.Constants.TOOLS_LOGOUT_URI) KEY_WS_BUFFER_SIZE(com.adeptj.runtime.server.ServerConstants.KEY_WS_BUFFER_SIZE) KEY_REQ_BUFF_MAX_BUFFERS(com.adeptj.runtime.common.Constants.KEY_REQ_BUFF_MAX_BUFFERS) AUTH_SERVLET(com.adeptj.runtime.server.ServerConstants.AUTH_SERVLET) StandardOpenOption(java.nio.file.StandardOpenOption) Configs(com.adeptj.runtime.config.Configs) MultipartConfigElement(javax.servlet.MultipartConfigElement) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) KEY_WS_TASK_CORE_THREADS(com.adeptj.runtime.server.ServerConstants.KEY_WS_TASK_CORE_THREADS) TOOLS_DASHBOARD_URL(com.adeptj.runtime.server.ServerConstants.TOOLS_DASHBOARD_URL) Options(org.xnio.Options) Objects(java.util.Objects) List(java.util.List) OSGI_CONSOLE_URL(com.adeptj.runtime.common.Constants.OSGI_CONSOLE_URL) BANNER_TXT(com.adeptj.runtime.common.Constants.BANNER_TXT) KEY_KEYSTORE(com.adeptj.runtime.server.ServerConstants.KEY_KEYSTORE) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) KEY_WS_TCP_NO_DELAY(com.adeptj.runtime.server.ServerConstants.KEY_WS_TCP_NO_DELAY) SYS_PROP_CHECK_PORT(com.adeptj.runtime.server.ServerConstants.SYS_PROP_CHECK_PORT) SYS_PROP_ENABLE_AJP(com.adeptj.runtime.server.ServerConstants.SYS_PROP_ENABLE_AJP) CrawlerSessionManagerConfig(io.undertow.servlet.api.CrawlerSessionManagerConfig) Xnio(org.xnio.Xnio) Builder(io.undertow.Undertow.Builder) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) HashMap(java.util.HashMap) BindException(java.net.BindException) FORM_AUTH(javax.servlet.http.HttpServletRequest.FORM_AUTH) TOOLS_SERVLET(com.adeptj.runtime.server.ServerConstants.TOOLS_SERVLET) SecurityConstraint(io.undertow.servlet.api.SecurityConstraint) ERROR_PAGE_SERVLET(com.adeptj.runtime.server.ServerConstants.ERROR_PAGE_SERVLET) WeakReference(java.lang.ref.WeakReference) SYS_PROP_ENABLE_HTTP2(com.adeptj.runtime.server.ServerConstants.SYS_PROP_ENABLE_HTTP2) SYS_PROP_SERVER_PORT(com.adeptj.runtime.common.Constants.SYS_PROP_SERVER_PORT) KEY_AJP(com.adeptj.runtime.server.ServerConstants.KEY_AJP) Version(io.undertow.Version) KEY_SESSION_TIMEOUT(com.adeptj.runtime.server.ServerConstants.KEY_SESSION_TIMEOUT) Logger(org.slf4j.Logger) SslContextFactory(com.adeptj.runtime.common.SslContextFactory) LogbackManager(com.adeptj.runtime.tools.logging.LogbackManager) ARG_OPEN_CONSOLE(com.adeptj.runtime.common.Constants.ARG_OPEN_CONSOLE) HEADER_X_POWERED_BY(com.adeptj.runtime.common.Constants.HEADER_X_POWERED_BY) ContainerInitializer(com.adeptj.runtime.core.ContainerInitializer) XnioWorker(org.xnio.XnioWorker) SERVER_CONF_FILE(com.adeptj.runtime.common.Constants.SERVER_CONF_FILE) DeploymentManager(io.undertow.servlet.api.DeploymentManager) KEY_WS_USE_DIRECT_BUFFER(com.adeptj.runtime.server.ServerConstants.KEY_WS_USE_DIRECT_BUFFER) AuthServlet(com.adeptj.runtime.servlet.AuthServlet) HttpHandler(io.undertow.server.HttpHandler) ServerSocketChannel(java.nio.channels.ServerSocketChannel) FrameworkLauncher(com.adeptj.runtime.osgi.FrameworkLauncher) ServletContainerInitializerInfo(io.undertow.servlet.api.ServletContainerInitializerInfo) KEY_CHANGE_SESSIONID_ON_LOGIN(com.adeptj.runtime.server.ServerConstants.KEY_CHANGE_SESSIONID_ON_LOGIN) DefaultExecutorService(com.adeptj.runtime.common.DefaultExecutorService) InputStream(java.io.InputStream) HttpHandler(io.undertow.server.HttpHandler) AllowedMethodsHandler(io.undertow.server.handlers.AllowedMethodsHandler) HashMap(java.util.HashMap) RequestBufferingHandler(io.undertow.server.handlers.RequestBufferingHandler) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) Config(com.typesafe.config.Config) CrawlerSessionManagerConfig(io.undertow.servlet.api.CrawlerSessionManagerConfig) HttpString(io.undertow.util.HttpString) RequestLimitingHandler(io.undertow.server.handlers.RequestLimitingHandler) HttpString(io.undertow.util.HttpString)

Aggregations

ARG_OPEN_CONSOLE (com.adeptj.runtime.common.Constants.ARG_OPEN_CONSOLE)1 BANNER_TXT (com.adeptj.runtime.common.Constants.BANNER_TXT)1 CONTEXT_PATH (com.adeptj.runtime.common.Constants.CONTEXT_PATH)1 DEPLOYMENT_NAME (com.adeptj.runtime.common.Constants.DEPLOYMENT_NAME)1 DIR_ADEPTJ_RUNTIME (com.adeptj.runtime.common.Constants.DIR_ADEPTJ_RUNTIME)1 DIR_DEPLOYMENT (com.adeptj.runtime.common.Constants.DIR_DEPLOYMENT)1 HEADER_SERVER (com.adeptj.runtime.common.Constants.HEADER_SERVER)1 HEADER_X_POWERED_BY (com.adeptj.runtime.common.Constants.HEADER_X_POWERED_BY)1 KEY_ALLOWED_METHODS (com.adeptj.runtime.common.Constants.KEY_ALLOWED_METHODS)1 KEY_HEADER_SERVER (com.adeptj.runtime.common.Constants.KEY_HEADER_SERVER)1 KEY_HOST (com.adeptj.runtime.common.Constants.KEY_HOST)1 KEY_HTTP (com.adeptj.runtime.common.Constants.KEY_HTTP)1 KEY_MAX_CONCURRENT_REQS (com.adeptj.runtime.common.Constants.KEY_MAX_CONCURRENT_REQS)1 KEY_PORT (com.adeptj.runtime.common.Constants.KEY_PORT)1 KEY_REQ_BUFF_MAX_BUFFERS (com.adeptj.runtime.common.Constants.KEY_REQ_BUFF_MAX_BUFFERS)1 OSGI_CONSOLE_URL (com.adeptj.runtime.common.Constants.OSGI_CONSOLE_URL)1 SERVER_CONF_FILE (com.adeptj.runtime.common.Constants.SERVER_CONF_FILE)1 SYS_PROP_SERVER_PORT (com.adeptj.runtime.common.Constants.SYS_PROP_SERVER_PORT)1 TOOLS_CRYPTO_URI (com.adeptj.runtime.common.Constants.TOOLS_CRYPTO_URI)1 TOOLS_DASHBOARD_URI (com.adeptj.runtime.common.Constants.TOOLS_DASHBOARD_URI)1