Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Vert.x HTTP to @ConfigMapping #35246

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void staticInit(FunqyHttpBindingRecorder binding,
return;

// The context path + the resources path
String rootPath = httpConfig.rootPath;
String rootPath = httpConfig.rootPath();
binding.init();
}

Expand All @@ -71,7 +71,7 @@ public void boot(ShutdownContextBuildItem shutdown,
return;
feature.produce(new FeatureBuildItem(FUNQY_HTTP_FEATURE));

String rootPath = httpConfig.rootPath;
String rootPath = httpConfig.rootPath();
Handler<RoutingContext> handler = binding.start(rootPath,
vertx.getVertx(),
shutdown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void boot(ShutdownContextBuildItem shutdown,

feature.produce(new FeatureBuildItem(FUNQY_KNATIVE_FEATURE));

String rootPath = httpConfig.rootPath;
String rootPath = httpConfig.rootPath();
if (rootPath == null) {
rootPath = "/";
} else if (!rootPath.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void init() {
this.port = serverConfig.port;
this.ssl = serverConfig.ssl.certificate.isPresent() || serverConfig.ssl.keyStore.isPresent();
} else {
this.host = httpConfiguration.host;
this.port = httpConfiguration.port;
this.ssl = httpConfiguration.insecureRequests != HttpConfiguration.InsecureRequests.ENABLED;
this.host = httpConfiguration.host();
this.port = httpConfiguration.port();
this.ssl = httpConfiguration.insecureRequests() != HttpConfiguration.InsecureRequests.ENABLED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Supplier<PolicyEnforcerResolver> setup(OidcConfig oidcConfig, KeycloakPol
@Override
public PolicyEnforcerResolver get() {
return new PolicyEnforcerResolver(defaultPolicyEnforcer, policyEnforcerTenants,
httpConfiguration.readTimeout.toMillis());
httpConfiguration.readTimeout().toMillis());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void produceTenantResolverInterceptors(CombinedIndexBuildItem indexBuildI
Capabilities capabilities, OidcRecorder recorder,
BuildProducer<EagerSecurityInterceptorCandidateBuildItem> producer,
HttpBuildTimeConfig buildTimeConfig) {
if (!buildTimeConfig.auth.proactive
if (!buildTimeConfig.auth().proactive()
&& (capabilities.isPresent(Capability.RESTEASY_REACTIVE) || capabilities.isPresent(Capability.RESTEASY))) {
// provide method interceptor that will be run before security checks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public OidcDevJsonRpcService(HttpConfiguration httpConfiguration, SmallRyeConfig
// 'KeycloakDevServicesProcessor' is created with combined index
OidcDevUiRpcSvcPropertiesBean props = Arc.container().instance(OidcDevUiRpcSvcPropertiesBean.class).get();

this.httpPort = httpConfiguration.port;
this.httpPort = httpConfiguration.port();
this.config = config;
this.vertx = vertx;
this.authorizationUrl = props.getAuthorizationUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void validateBeanDeployment(
// access the SecurityIdentity in a synchronous manner
final boolean blocking = annotationStore.hasAnnotation(method, DotNames.BLOCKING);
final boolean alwaysAuthenticateRoute;
if (!httpBuildTimeConfig.auth.proactive && !blocking) {
if (!httpBuildTimeConfig.auth().proactive() && !blocking) {
final DotName returnTypeName = method.returnType().name();
// method either returns 'something' in a synchronous manner or void (in which case we can't tell)
final boolean possiblySynchronousResponse = !returnTypeName.equals(DotNames.UNI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public Handler<RoutingContext> createHandler(String handlerClassName) {
}

public Handler<RoutingContext> compressRouteHandler(Handler<RoutingContext> routeHandler, HttpCompression compression) {
if (httpBuildTimeConfig.enableCompression) {
if (httpBuildTimeConfig.enableCompression()) {
return new HttpCompressionHandler(routeHandler, compression,
compression == HttpCompression.UNDEFINED
? Set.copyOf(httpBuildTimeConfig.compressMediaTypes.orElse(List.of()))
? Set.copyOf(httpBuildTimeConfig.compressMediaTypes().orElse(List.of()))
: Set.of());
} else {
return routeHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void boot(ShutdownContextBuildItem shutdown,
final boolean noCustomAuthCompletionExMapper;
final boolean noCustomAuthFailureExMapper;
final boolean noCustomAuthRedirectExMapper;
if (vertxConfig.auth.proactive) {
if (vertxConfig.auth().proactive()) {
noCustomAuthCompletionExMapper = notFoundCustomExMapper(AuthenticationCompletionException.class.getName(),
AuthenticationCompletionExceptionMapper.class.getName(), combinedIndexBuildItem.getIndex());
noCustomAuthFailureExMapper = notFoundCustomExMapper(AuthenticationFailedException.class.getName(),
Expand All @@ -129,7 +129,7 @@ public void boot(ShutdownContextBuildItem shutdown,
// so that user can define failure handlers that precede exception mappers
final Handler<RoutingContext> failureHandler = recorder.vertxFailureHandler(vertx.getVertx(),
executorBuildItem.getExecutorProxy(), resteasyVertxConfig, noCustomAuthCompletionExMapper,
noCustomAuthFailureExMapper, noCustomAuthRedirectExMapper, vertxConfig.auth.proactive);
noCustomAuthFailureExMapper, noCustomAuthRedirectExMapper, vertxConfig.auth().proactive());
filterBuildItemBuildProducer.produce(FilterBuildItem.ofAuthenticationFailureHandler(failureHandler));

// Exact match for resources matched to the root path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public Handler<RoutingContext> vertxRequestHandler(Supplier<Vertx> vertx, Execut
if (deployment != null) {
Handler<RoutingContext> handler = new VertxRequestHandler(vertx.get(), deployment, contextPath,
new ResteasyVertxAllocator(config.responseBufferSize), executor,
readTimeout.getValue().readTimeout.toMillis());
readTimeout.getValue().readTimeout().toMillis());

Set<String> compressMediaTypes = httpBuildTimeConfig.compressMediaTypes.map(Set::copyOf).orElse(Set.of());
if (httpBuildTimeConfig.enableCompression && !compressMediaTypes.isEmpty()) {
Set<String> compressMediaTypes = httpBuildTimeConfig.compressMediaTypes().map(Set::copyOf).orElse(Set.of());
if (httpBuildTimeConfig.enableCompression() && !compressMediaTypes.isEmpty()) {
// If compression is enabled and the set of compressed media types is not empty then wrap the standalone handler
handler = new HttpCompressionHandler(handler, compressMediaTypes);
}
Expand All @@ -99,7 +99,7 @@ public Handler<RoutingContext> vertxFailureHandler(Supplier<Vertx> vertx, Execut
// used when auth failed before RESTEasy Classic began processing the request
return new VertxRequestHandler(vertx.get(), deployment, contextPath,
new ResteasyVertxAllocator(config.responseBufferSize), executor,
readTimeout.getValue().readTimeout.toMillis()) {
readTimeout.getValue().readTimeout().toMillis()) {

@Override
public void handle(RoutingContext request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CompressionScanner(HttpBuildTimeConfig httpBuildTimeConfig) {
@Override
public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndpointClass,
Map<String, Object> methodContext) {
if (!httpBuildTimeConfig.enableCompression) {
if (!httpBuildTimeConfig.enableCompression()) {
return Collections.emptyList();
}

Expand All @@ -58,7 +58,7 @@ public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndp
return Collections.emptyList();
}
ResteasyReactiveCompressionHandler handler = new ResteasyReactiveCompressionHandler(
Set.copyOf(httpBuildTimeConfig.compressMediaTypes.orElse(Collections.emptyList())));
Set.copyOf(httpBuildTimeConfig.compressMediaTypes().orElse(Collections.emptyList())));
handler.setCompression(compression);
String[] produces = (String[]) methodContext.get(EndpointIndexer.METHOD_PRODUCES);
if ((produces != null) && (produces.length > 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ public void setupDeployment(BeanContainerBuildItem beanContainerBuildItem,
final boolean noCustomAuthCompletionExMapper;
final boolean noCustomAuthFailureExMapper;
final boolean noCustomAuthRedirectExMapper;
if (vertxConfig.auth.proactive) {
if (vertxConfig.auth().proactive()) {
noCustomAuthCompletionExMapper = notFoundCustomExMapper(AuthenticationCompletionException.class.getName(),
AuthenticationCompletionExceptionMapper.class.getName(), exceptionMapping);
noCustomAuthFailureExMapper = notFoundCustomExMapper(AuthenticationFailedException.class.getName(),
Expand All @@ -1287,7 +1287,7 @@ public void setupDeployment(BeanContainerBuildItem beanContainerBuildItem,
}

Handler<RoutingContext> failureHandler = recorder.failureHandler(restInitialHandler, noCustomAuthCompletionExMapper,
noCustomAuthFailureExMapper, noCustomAuthRedirectExMapper, vertxConfig.auth.proactive);
noCustomAuthFailureExMapper, noCustomAuthRedirectExMapper, vertxConfig.auth().proactive());

// we add failure handler right before QuarkusErrorHandler
// so that user can define failure handlers that precede exception mappers
Expand Down Expand Up @@ -1506,10 +1506,10 @@ public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndp
List<HandlerChainCustomizer> securityHandlerList = consumeStandardSecurityAnnotations(method,
actualEndpointClass, index,
(c) -> Collections.singletonList(
EagerSecurityHandler.Customizer.newInstance(httpBuildTimeConfig.auth.proactive)));
EagerSecurityHandler.Customizer.newInstance(httpBuildTimeConfig.auth().proactive())));
if (securityHandlerList == null && (denyJaxRs || hasDefaultJaxRsRolesAllowed)) {
securityHandlerList = Collections
.singletonList(EagerSecurityHandler.Customizer.newInstance(httpBuildTimeConfig.auth.proactive));
.singletonList(EagerSecurityHandler.Customizer.newInstance(httpBuildTimeConfig.auth().proactive()));
}
if (applySecurityInterceptors && eagerSecurityInterceptors.get().applyInterceptorOn(method)) {
List<HandlerChainCustomizer> nextSecurityHandlerList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ResteasyReactiveRequestContext createContext(Deployment deployment,
RuntimeDeploymentManager runtimeDeploymentManager = new RuntimeDeploymentManager(info, EXECUTOR_SUPPLIER,
VirtualThreadsRecorder::getCurrent,
closeTaskHandler, contextFactory, new ArcThreadSetupAction(beanContainer.requestContext()),
vertxConfig.rootPath);
vertxConfig.rootPath());
Deployment deployment = runtimeDeploymentManager.deploy();
DisabledRestEndpoints.set(deployment.getDisabledEndpoints());
initClassFactory.createInstance().getInstance().init(deployment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public Supplier<RuntimeConfiguration> runtimeConfiguration(RuntimeValue<Deployme
ResteasyReactiveServerRuntimeConfig runtimeConf) {
Optional<Long> maxBodySize;

if (httpConf.limits.maxBodySize.isPresent()) {
maxBodySize = Optional.of(httpConf.limits.maxBodySize.get().asLongValue());
if (httpConf.limits().maxBodySize().isPresent()) {
maxBodySize = Optional.of(httpConf.limits().maxBodySize().get().asLongValue());
} else {
maxBodySize = Optional.empty();
}

RuntimeConfiguration runtimeConfiguration = new DefaultRuntimeConfiguration(httpConf.readTimeout,
httpConf.body.deleteUploadedFilesOnEnd, httpConf.body.uploadsDirectory,
httpConf.body.multipart.fileContentTypes.orElse(null),
RuntimeConfiguration runtimeConfiguration = new DefaultRuntimeConfiguration(httpConf.readTimeout(),
httpConf.body().deleteUploadedFilesOnEnd(), httpConf.body().uploadsDirectory(),
httpConf.body().multipart().fileContentTypes().orElse(null),
runtimeConf.multipart().inputPart().defaultCharset(), maxBodySize,
httpConf.limits.maxFormAttributeSize.asLongValue());
httpConf.limits().maxFormAttributeSize().asLongValue());

deployment.getValue().setRuntimeConfiguration(runtimeConfiguration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Supplier<WebAuthnAuthenticationMechanism> setupWebAuthnAuthenticationMech
@Override
public WebAuthnAuthenticationMechanism get() {
String key;
if (!httpConfiguration.getValue().encryptionKey.isPresent()) {
if (!httpConfiguration.getValue().encryptionKey().isPresent()) {
if (encryptionKey != null) {
//persist across dev mode restarts
key = encryptionKey;
Expand All @@ -64,7 +64,7 @@ public WebAuthnAuthenticationMechanism get() {
log.warn("Encryption key was not specified for persistent WebAuthn auth, using temporary key " + key);
}
} else {
key = httpConfiguration.getValue().encryptionKey.get();
key = httpConfiguration.getValue().encryptionKey().get();
}
WebAuthnRunTimeConfig config = WebAuthnRecorder.this.config.getValue();
PersistentLoginManager loginManager = new PersistentLoginManager(key, config.cookieName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void includeInOpenAPIEndpoint(BuildProducer<AddToOpenAPIDefinitionBuildIt
SmallRyeHealthConfig healthConfig) {

// Add to OpenAPI if OpenAPI is available
if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI) && !managementInterfaceBuildTimeConfig.enabled) {
if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI) && !managementInterfaceBuildTimeConfig.enabled()) {
String healthRootPath = nonApplicationRootPathBuildItem.resolvePath(healthConfig.rootPath);
HealthOpenAPIFilter filter = new HealthOpenAPIFilter(healthRootPath,
nonApplicationRootPathBuildItem.resolveManagementNestedPath(healthRootPath, healthConfig.livenessPath),
Expand Down Expand Up @@ -353,7 +353,7 @@ public void kubernetes(NonApplicationRootPathBuildItem nonApplicationRootPathBui
BuildProducer<KubernetesHealthStartupPathBuildItem> startupPathItemProducer,
BuildProducer<KubernetesProbePortNameBuildItem> port) {

if (managementInterfaceBuildTimeConfig.enabled) {
if (managementInterfaceBuildTimeConfig.enabled()) {
// Switch to the "management" port
port.produce(new KubernetesProbePortNameBuildItem("management", selectSchemeForManagement()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private String getManagementRoot(LaunchModeBuildItem launch,
String managementRoot = nonApplicationRootPathBuildItem.resolveManagementPath("/",
managementInterfaceBuildTimeConfig, launch, openApiConfig.managementEnabled);

return managementRoot.split(managementInterfaceBuildTimeConfig.rootPath)[0];
return managementRoot.split(managementInterfaceBuildTimeConfig.rootPath())[0];

}

Expand Down Expand Up @@ -435,7 +435,7 @@ void addAutoFilters(BuildProducer<AddToOpenAPIDefinitionBuildItem> addToOpenAPID
private boolean isManagement(ManagementInterfaceBuildTimeConfig managementInterfaceBuildTimeConfig,
SmallRyeOpenApiConfig smallRyeOpenApiConfig,
LaunchModeBuildItem launchModeBuildItem) {
return managementInterfaceBuildTimeConfig.enabled && smallRyeOpenApiConfig.managementEnabled
return managementInterfaceBuildTimeConfig.enabled() && smallRyeOpenApiConfig.managementEnabled
&& launchModeBuildItem.getLaunchMode().equals(LaunchMode.DEVELOPMENT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public OpenApiRecorder(RuntimeValue<HttpConfiguration> configuration) {
}

public Consumer<Route> corsFilter(Filter filter) {
if (configuration.getValue().corsEnabled && filter.getHandler() != null) {
if (configuration.getValue().corsEnabled() && filter.getHandler() != null) {
return new Consumer<Route>() {
@Override
public void accept(Route route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public ServletDeploymentManagerBuildItem build(List<ServletBuildItem> servlets,
knownPaths.knownDirectories,
launchMode.getLaunchMode(), shutdownContext, httpRootPath.relativePath(contextPath),
servletConfig.defaultCharset, webMetaData.getRequestCharacterEncoding(),
webMetaData.getResponseCharacterEncoding(), httpBuildTimeConfig.auth.proactive,
webMetaData.getResponseCharacterEncoding(), httpBuildTimeConfig.auth().proactive(),
webMetaData.getWelcomeFileList() != null ? webMetaData.getWelcomeFileList().getWelcomeFiles() : null,
hasSecurityCapability(capabilities));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ public void run() {
undertowOptions.set(UndertowOptions.MAX_PARAMETERS, servletRuntimeConfig.maxParameters);
UndertowOptionMap undertowOptionMap = undertowOptions.getMap();

Set<String> compressMediaTypes = httpBuildTimeConfig.enableCompression
? Set.copyOf(httpBuildTimeConfig.compressMediaTypes.get())
Set<String> compressMediaTypes = httpBuildTimeConfig.enableCompression()
? Set.copyOf(httpBuildTimeConfig.compressMediaTypes().get())
: Collections.emptySet();

return new Handler<RoutingContext>() {
Expand Down Expand Up @@ -418,11 +418,11 @@ public void handle(AsyncResult<Void> result) {
});
}

Optional<MemorySize> maxBodySize = httpConfiguration.getValue().limits.maxBodySize;
Optional<MemorySize> maxBodySize = httpConfiguration.getValue().limits().maxBodySize();
if (maxBodySize.isPresent()) {
exchange.setMaxEntitySize(maxBodySize.get().asLongValue());
}
Duration readTimeout = httpConfiguration.getValue().readTimeout;
Duration readTimeout = httpConfiguration.getValue().readTimeout();
exchange.setReadTimeout(readTimeout.toMillis());

exchange.setUndertowOptions(undertowOptionMap);
Expand Down
5 changes: 5 additions & 0 deletions extensions/vertx-http/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down
Loading