Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.quarkus.vertx.http.runtime;
import static io.quarkus.vertx.core.runtime.context.VertxContextSafetyToggle.setContextSafe;
import java.io.File;
import java.io.IOException;
import java.net.BindException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import jakarta.enterprise.event.Event;
import jakarta.enterprise.inject.Default;
import org.crac.Resource;
import org.jboss.logging.Logger;
import org.wildfly.common.cpu.ProcessorInfo;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.quarkus.arc.Arc;
import io.quarkus.arc.InstanceHandle;
import io.quarkus.arc.runtime.BeanContainer;
import io.quarkus.bootstrap.runner.Timing;
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.dev.spi.HotReplacementContext;
import io.quarkus.netty.runtime.virtual.VirtualAddress;
import io.quarkus.netty.runtime.virtual.VirtualChannel;
import io.quarkus.netty.runtime.virtual.VirtualServerChannel;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.LiveReloadConfig;
import io.quarkus.runtime.QuarkusBindException;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.configuration.ConfigInstantiator;
import io.quarkus.runtime.configuration.MemorySize;
import io.quarkus.runtime.shutdown.ShutdownConfig;
import io.quarkus.vertx.core.runtime.VertxCoreRecorder;
import io.quarkus.vertx.core.runtime.config.VertxConfiguration;
import io.quarkus.vertx.http.HttpServerOptionsCustomizer;
import io.quarkus.vertx.http.ManagementInterface;
import io.quarkus.vertx.http.runtime.HttpConfiguration.InsecureRequests;
import io.quarkus.vertx.http.runtime.devmode.RemoteSyncHandler;
import io.quarkus.vertx.http.runtime.devmode.VertxHttpHotReplacementSetup;
import io.quarkus.vertx.http.runtime.filters.Filter;
import io.quarkus.vertx.http.runtime.filters.Filters;
import io.quarkus.vertx.http.runtime.filters.GracefulShutdownFilter;
import io.quarkus.vertx.http.runtime.filters.QuarkusRequestWrapper;
import io.quarkus.vertx.http.runtime.filters.accesslog.AccessLogHandler;
import io.quarkus.vertx.http.runtime.filters.accesslog.AccessLogReceiver;
import io.quarkus.vertx.http.runtime.filters.accesslog.DefaultAccessLogReceiver;
import io.quarkus.vertx.http.runtime.filters.accesslog.JBossLoggingAccessLogReceiver;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig;
import io.quarkus.vertx.http.runtime.management.ManagementInterfaceConfiguration;
import io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers;
import io.quarkus.vertx.http.runtime.options.HttpServerOptionsUtils;
import io.smallrye.common.vertx.VertxContext;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.Cookie;
import io.vertx.core.http.CookieSameSite;
import io.vertx.core.http.HttpConnection;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.impl.Http1xServerConnection;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.EventLoopContext;
import io.vertx.core.impl.Utils;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.net.impl.ConnectionBase;
import io.vertx.core.net.impl.VertxHandler;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.handler.CorsHandler;
@Recorder
public class VertxHttpRecorder {
/**
* The key that the request start time is stored under
*/
public static final String REQUEST_START_TIME = "io.quarkus.request-start-time";
public static final String MAX_REQUEST_SIZE_KEY = "io.quarkus.max-request-size";
private static final String DISABLE_WEBSOCKETS_PROP_NAME = "vertx.disableWebsockets";
/**
* Order mark for route with priority over the default route (add an offset from this mark)
**/
public static final int BEFORE_DEFAULT_ROUTE_ORDER_MARK = 1_000;
/**
* Default route order (i.e. Static Resources, Servlet)
**/
public static final int DEFAULT_ROUTE_ORDER = 10_000;
/**
* Order mark for route without priority over the default route (add an offset from this mark)
**/
public static final int AFTER_DEFAULT_ROUTE_ORDER_MARK = 20_000;
private static final Logger LOGGER = Logger.getLogger(VertxHttpRecorder.class.getName());
private static volatile Handler hotReplacementHandler;
private static volatile HotReplacementContext hotReplacementContext;
private static volatile RemoteSyncHandler remoteSyncHandler;
private static volatile Runnable closeTask;
static volatile Handler rootHandler;
private static volatile Handler nonApplicationRedirectHandler;
private static volatile int actualHttpPort = -1;
private static volatile int actualHttpsPort = -1;
private static volatile int actualManagementPort = -1;
public static final String GET = "GET";
private static final Handler ACTUAL_ROOT = new Handler() {
/** JVM system property that disables URI validation, don't use this in production. */
private static final String DISABLE_URI_VALIDATION_PROP_NAME = "vertx.disableURIValidation";
/**
* Disables HTTP headers validation, so we can save some processing and save some allocations.
*/
private final boolean DISABLE_URI_VALIDATION = Boolean.getBoolean(DISABLE_URI_VALIDATION_PROP_NAME);
@Override
public void handle(HttpServerRequest httpServerRequest) {
if (!uriValid(httpServerRequest)) {
httpServerRequest.response().setStatusCode(400).end();
return;
}
//we need to pause the request to make sure that data does
//not arrive before handlers have a chance to install a read handler
//as it is possible filters such as the auth filter can do blocking tasks
//as the underlying handler has not had a chance to install a read handler yet
//and data that arrives while the blocking task is being processed will be lost
httpServerRequest.pause();
Handler rh = VertxHttpRecorder.rootHandler;
if (rh != null) {
rh.handle(httpServerRequest);
} else {
//very rare race condition, that can happen when dev mode is shutting down
httpServerRequest.resume();
httpServerRequest.response().setStatusCode(503).end();
}
}
private boolean uriValid(HttpServerRequest httpServerRequest) {
if (DISABLE_URI_VALIDATION) {
return true;
}
try {
// we simply need to know if the URI is valid
new URI(httpServerRequest.uri());
return true;
} catch (URISyntaxException e) {
return false;
}
}
};
private static HttpServerOptions httpMainSslServerOptions;
private static HttpServerOptions httpMainServerOptions;
private static HttpServerOptions httpMainDomainSocketOptions;
private static HttpServerOptions httpManagementServerOptions;
final HttpBuildTimeConfig httpBuildTimeConfig;
final ManagementInterfaceBuildTimeConfig managementBuildTimeConfig;
final RuntimeValue httpConfiguration;
final RuntimeValue managementConfiguration;
private static volatile Handler managementRouter;
public VertxHttpRecorder(HttpBuildTimeConfig httpBuildTimeConfig,
ManagementInterfaceBuildTimeConfig managementBuildTimeConfig,
RuntimeValue httpConfiguration,
RuntimeValue managementConfiguration) {
this.httpBuildTimeConfig = httpBuildTimeConfig;
this.httpConfiguration = httpConfiguration;
this.managementBuildTimeConfig = managementBuildTimeConfig;
this.managementConfiguration = managementConfiguration;
}
public static void setHotReplacement(Handler handler, HotReplacementContext hrc) {
hotReplacementHandler = handler;
hotReplacementContext = hrc;
}
public static void shutDownDevMode() {
if (closeTask != null) {
closeTask.run();
closeTask = null;
}
rootHandler = null;
hotReplacementHandler = null;
}
public static void startServerAfterFailedStart() {
if (closeTask != null) {
//it is possible start failed after the server was started
//we shut it down in this case, as we have no idea what state it is in
final Handler prevHotReplacementHandler = hotReplacementHandler;
shutDownDevMode();
// reset back to the older live reload handler, so that it can be used
// to watch any artifacts that need hot deployment to fix the reason which caused
// the server start to fail
hotReplacementHandler = prevHotReplacementHandler;
}
Supplier supplier = VertxCoreRecorder.getVertx();
Vertx vertx;
if (supplier == null) {
VertxConfiguration vertxConfiguration = new VertxConfiguration();
ConfigInstantiator.handleObject(vertxConfiguration);
vertx = VertxCoreRecorder.recoverFailedStart(vertxConfiguration).get();
} else {
vertx = supplier.get();
}
try {
HttpBuildTimeConfig buildConfig = new HttpBuildTimeConfig();
ConfigInstantiator.handleObject(buildConfig);
ManagementInterfaceBuildTimeConfig managementBuildTimeConfig = new ManagementInterfaceBuildTimeConfig();
ConfigInstantiator.handleObject(managementBuildTimeConfig);
HttpConfiguration config = new HttpConfiguration();
ConfigInstantiator.handleObject(config);
ManagementInterfaceConfiguration managementConfig = new ManagementInterfaceConfiguration();
ConfigInstantiator.handleObject(managementConfig);
if (config.host == null) {
//HttpHostConfigSource does not come into play here
config.host = "localhost";
}
Router router = Router.router(vertx);
if (hotReplacementHandler != null) {
router.route().order(Integer.MIN_VALUE).blockingHandler(hotReplacementHandler);
}
Handler root = router;
LiveReloadConfig liveReloadConfig = new LiveReloadConfig();
ConfigInstantiator.handleObject(liveReloadConfig);
if (liveReloadConfig.password.isPresent()
&& hotReplacementContext.getDevModeType() == DevModeType.REMOTE_SERVER_SIDE) {
root = remoteSyncHandler = new RemoteSyncHandler(liveReloadConfig.password.get(), root, hotReplacementContext);
}
rootHandler = root;
//we can't really do
doServerStart(vertx, buildConfig, managementBuildTimeConfig, null, config, managementConfig, LaunchMode.DEVELOPMENT,
new Supplier() {
@Override
public Integer get() {
return ProcessorInfo.availableProcessors(); //this is dev mode, so the number of IO threads not always being 100% correct does not really matter in this case
}
}, null, false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public RuntimeValue initializeRouter(final Supplier vertxRuntimeValue) {
Vertx vertx = vertxRuntimeValue.get();
Router router = Router.router(vertx);
return new RuntimeValue<>(router);
}
public RuntimeValue createMutinyRouter(final RuntimeValue router) {
return new RuntimeValue<>(new io.vertx.mutiny.ext.web.Router(router.getValue()));
}
public void startServer(Supplier vertx, ShutdownContext shutdown,
LaunchMode launchMode,
boolean startVirtual, boolean startSocket, Supplier ioThreads, List websocketSubProtocols,
boolean auxiliaryApplication, boolean disableWebSockets)
throws IOException {
// disable websockets if we have determined at build time that we should and the user has not overridden the relevant Vert.x property
if (disableWebSockets && !System.getProperties().containsKey(DISABLE_WEBSOCKETS_PROP_NAME)) {
System.setProperty(DISABLE_WEBSOCKETS_PROP_NAME, "true");
}
if (startVirtual) {
initializeVirtual(vertx.get());
shutdown.addShutdownTask(() -> {
try {
virtualBootstrapChannel.channel().close().sync();
} catch (InterruptedException e) {
LOGGER.warn("Unable to close virtualBootstrapChannel");
} finally {
virtualBootstrapChannel = null;
virtualBootstrap = null;
}
});
}
HttpConfiguration httpConfiguration = this.httpConfiguration.getValue();
ManagementInterfaceConfiguration managementConfig = this.managementConfiguration == null ? null
: this.managementConfiguration.getValue();
if (startSocket && (httpConfiguration.hostEnabled || httpConfiguration.domainSocketEnabled
|| managementConfig.hostEnabled || managementConfig.domainSocketEnabled)) {
// Start the server
if (closeTask == null) {
doServerStart(vertx.get(), httpBuildTimeConfig, managementBuildTimeConfig, managementRouter,
httpConfiguration, managementConfig, launchMode, ioThreads, websocketSubProtocols,
auxiliaryApplication);
if (launchMode != LaunchMode.DEVELOPMENT) {
shutdown.addShutdownTask(closeTask);
} else {
shutdown.addShutdownTask(new Runnable() {
@Override
public void run() {
VertxHttpHotReplacementSetup.handleDevModeRestart();
}
});
}
}
}
}
public void mountFrameworkRouter(RuntimeValue mainRouter, RuntimeValue frameworkRouter,
String frameworkPath) {
mainRouter.getValue().mountSubRouter(frameworkPath, frameworkRouter.getValue());
}
public void finalizeRouter(BeanContainer container, Consumer defaultRouteHandler,
List filterList, List managementInterfaceFilterList, Supplier vertx,
LiveReloadConfig liveReloadConfig, Optional> mainRouterRuntimeValue,
RuntimeValue httpRouterRuntimeValue, RuntimeValue mutinyRouter,
RuntimeValue frameworkRouter, RuntimeValue managementRouter,
String rootPath, String nonRootPath,
LaunchMode launchMode, boolean requireBodyHandler,
Handler bodyHandler,
GracefulShutdownFilter gracefulShutdownFilter, ShutdownConfig shutdownConfig,
Executor executor) {
HttpConfiguration httpConfiguration = this.httpConfiguration.getValue();
// install the default route at the end
Router httpRouteRouter = httpRouterRuntimeValue.getValue();
//allow the router to be modified programmatically
Event