/** * Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully. * * @param next The next http handler * @return The graceful shutdown handler */ public static GracefulShutdownHandler gracefulShutdown(HttpHandler next) { return new GracefulShutdownHandler(next); }
@Inject public UndertowServer(final org.jooby.spi.HttpHandler dispatcher, final Config conf, final Provider<SSLContext> sslContext) throws Exception { awaitShutdown = conf.getDuration("undertow.awaitShutdown", TimeUnit.MILLISECONDS); boolean http2 = conf.getBoolean("server.http2.enabled"); shutdown = new GracefulShutdownHandler(doHandler(dispatcher, conf)); Undertow.Builder ubuilder = configure(conf, io.undertow.Undertow.builder()) .addHttpListener(conf.getInt("application.port"), host(conf.getString("application.host"))); ubuilder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2); boolean securePort = conf.hasPath("application.securePort"); if (securePort) { ubuilder.addHttpsListener(conf.getInt("application.securePort"), host(conf.getString("application.host")), sslContext.get()); } this.server = ubuilder.setHandler(shutdown) .build(); }
static public 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()); // For backwards compatibility, check if a handler.yml has been included. If // not, default to original configuration. if (Handler.config == null || !Handler.config.isEnabled()) { HttpHandler handler = middlewareInit(); // register the graceful shutdown handler gracefulShutdownHandler = new GracefulShutdownHandler(handler); } else { // initialize the handlers, chains and paths Handler.init(); // register the graceful shutdown handler gracefulShutdownHandler = new GracefulShutdownHandler(new OrchestrationHandler()); } if (config.dynamicPort) { for (int i = config.minPort; i < config.maxPort; i++) { boolean b = bind(gracefulShutdownHandler, i); if (b) { break; } } } else { bind(gracefulShutdownHandler, -1); } }
@Override public void start() { try { pippoDeploymentManager = createPippoDeploymentManager(); HttpHandler pippoHandler = pippoDeploymentManager.start(); HttpHandler contextHandler = createContextHandler(pippoHandler); GracefulShutdownHandler rootHandler = new GracefulShutdownHandler(contextHandler); server = createServer(rootHandler); String version = server.getClass().getPackage().getImplementationVersion(); log.info("Starting Undertow Server {} on port {}", version, getSettings().getPort()); server.start(); } catch (Exception e) { throw new PippoRuntimeException(e); } }
/** * Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully. * * @param next The next http handler * @return The graceful shutdown handler */ public static GracefulShutdownHandler gracefulShutdown(HttpHandler next) { return new GracefulShutdownHandler(next); }
/** * Returns a new handler that can be used to wait for all requests to finish before shutting down the server gracefully. * * @param next The next http handler * @return The graceful shutdown handler */ public static GracefulShutdownHandler gracefulShutdown(HttpHandler next) { return new GracefulShutdownHandler(next); }
/** * Wrapper. * @param handler is the http handler from chain. * @return the Undertown shutdown handler. */ public HttpHandler wrap(final HttpHandler handler) { if(gracefulShutdownHandler == null) { this.gracefulShutdownHandler = new GracefulShutdownHandler(handler); } return gracefulShutdownHandler; }
@Inject public UndertowServer(final org.jooby.spi.HttpHandler dispatcher, final Config conf, final Provider<SSLContext> sslContext) throws Exception { awaitShutdown = conf.getDuration("undertow.awaitShutdown", TimeUnit.MILLISECONDS); boolean http2 = conf.getBoolean("server.http2.enabled"); shutdown = new GracefulShutdownHandler(doHandler(dispatcher, conf)); Undertow.Builder ubuilder = configure(conf, io.undertow.Undertow.builder()) .addHttpListener(conf.getInt("application.port"), host(conf.getString("application.host"))); ubuilder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2); boolean securePort = conf.hasPath("application.securePort"); if (securePort) { ubuilder.addHttpsListener(conf.getInt("application.securePort"), host(conf.getString("application.host")), sslContext.get()); } this.server = ubuilder.setHandler(shutdown) .build(); }
protected void startImpl() { try { fathomDeploymentManager = createFathomDeploymentManager(); HttpHandler fathomHandler = fathomDeploymentManager.start(); String contextPath = settings.getContextPath(); // create a handler than redirects non-context requests to the context PathHandler contextHandler = Handlers.path(Handlers.redirect(contextPath)); // add the handler with the context prefix contextHandler.addPrefixPath(contextPath, fathomHandler); GracefulShutdownHandler rootHandler = new GracefulShutdownHandler(contextHandler); server = createServer(rootHandler); String version = server.getClass().getPackage().getImplementationVersion(); log.info("Starting Undertow {}", version); server.start(); } catch (Exception e) { throw new FathomException(e); } }
/** * buildGracefulShutdownHandler * * @param paths * @return */ private static GracefulShutdownHandler buildGracefulShutdownHandler(PathHandler paths) { return new GracefulShutdownHandler( new RequestLimitingHandler(new RequestLimit(configuration.getRequestLimit()), new AllowedMethodsHandler( new BlockingHandler( new GzipEncodingHandler( new ErrorHandler( new HttpContinueAcceptingHandler(paths) ), configuration.isForceGzipEncoding() ) ), // allowed methods HttpString.tryFromString(RequestContext.METHOD.GET.name()), HttpString.tryFromString(RequestContext.METHOD.POST.name()), HttpString.tryFromString(RequestContext.METHOD.PUT.name()), HttpString.tryFromString(RequestContext.METHOD.DELETE.name()), HttpString.tryFromString(RequestContext.METHOD.PATCH.name()), HttpString.tryFromString(RequestContext.METHOD.OPTIONS.name()) ) ) ); }