Skip to content

Commit

Permalink
Some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 19, 2021
1 parent a5d46b1 commit f2c8fd9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.runtime.configuration;

import static io.quarkus.runtime.configuration.ConverterSupport.DEFAULT_QUARKUS_CONVERTER_PRIORITY;

import javax.annotation.Priority;

import org.eclipse.microprofile.config.spi.Converter;

/**
* A converter to support locales.
*/
@Priority(DEFAULT_QUARKUS_CONVERTER_PRIORITY)
public class NormalizedHttpPathConverter implements Converter<String> {

private static final String SLASH = "/";

@Override
public String convert(String value) throws IllegalArgumentException, NullPointerException {
if (value == null) {
return SLASH;
}

value = value.trim();
if (SLASH.equals(value)) {
return value;
}
if (!value.startsWith(SLASH)) {
value = SLASH + value;
}
if (!value.endsWith(SLASH)) {
value = value + SLASH;
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
import io.quarkus.resteasy.server.common.spi.AllowedJaxRsAnnotationPrefixBuildItem;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConvertWith;
import io.quarkus.runtime.configuration.NormalizedHttpPathConverter;

/**
* Processor that builds the RESTEasy server configuration.
Expand Down Expand Up @@ -138,6 +140,7 @@ static final class ResteasyConfig {
* annotated application classes.
*/
@ConfigItem(defaultValue = "/")
@ConvertWith(NormalizedHttpPathConverter.class)
String path;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentBuildItem;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;
import io.quarkus.vertx.http.deployment.DefaultRouteBuildItem;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RequireVirtualHttpBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.runtime.HttpBuildTimeConfig;
import io.quarkus.vertx.http.runtime.HttpConfiguration;
import io.quarkus.vertx.http.runtime.VertxHttpRecorder;
import io.vertx.core.Handler;
Expand All @@ -50,32 +50,16 @@ public void staticInit(ResteasyStandaloneRecorder recorder,
ResteasyDeploymentBuildItem deployment,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
ResteasyInjectionReadyBuildItem resteasyInjectionReady,
HttpBuildTimeConfig httpConfig,
HttpRootPathBuildItem httpRootPathBuildItem,
BuildProducer<ResteasyStandaloneBuildItem> standalone) throws Exception {
if (capabilities.isPresent(Capability.SERVLET)) {
return;
}

String deploymentRootPath = null;
// The context path + the resources path
String rootPath = httpConfig.rootPath;

if (deployment != null) {
deploymentRootPath = deployment.getRootPath();
if (rootPath.endsWith("/")) {
if (deploymentRootPath.startsWith("/")) {
rootPath += deploymentRootPath.substring(1);
} else {
rootPath += deploymentRootPath;
}
} else if (!deploymentRootPath.equals("/")) {
if (!deploymentRootPath.startsWith("/")) {
rootPath += "/";
}
rootPath += deploymentRootPath;
}
recorder.staticInit(deployment.getDeployment(), rootPath);
standalone.produce(new ResteasyStandaloneBuildItem(deploymentRootPath));
recorder.staticInit(deployment.getDeployment(),
httpRootPathBuildItem.resolvePath(deployment.getRootPath().substring(1)));
standalone.produce(new ResteasyStandaloneBuildItem(deployment.getRootPath()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ ServiceStartBuildItem finalizeRouter(
LaunchModeBuildItem launchMode,
List<DefaultRouteBuildItem> defaultRoutes, List<FilterBuildItem> filters,
VertxWebRouterBuildItem httpRouteRouter,
HttpRootPathBuildItem httpRootPathBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
HttpBuildTimeConfig httpBuildTimeConfig, HttpConfiguration httpConfiguration,
List<RequireBodyHandlerBuildItem> requireBodyHandlerBuildItems,
Expand Down Expand Up @@ -256,7 +257,8 @@ ServiceStartBuildItem finalizeRouter(

recorder.finalizeRouter(beanContainer.getValue(),
defaultRoute.map(DefaultRouteBuildItem::getRoute).orElse(null),
listOfFilters, vertx.getVertx(), lrc, mainRouter, httpRouteRouter.getHttpRouter(), httpBuildTimeConfig.rootPath,
listOfFilters, vertx.getVertx(), lrc, mainRouter, httpRouteRouter.getHttpRouter(),
httpRootPathBuildItem.getRootPath(),
launchMode.getLaunchMode(),
!requireBodyHandlerBuildItems.isEmpty(), bodyHandler, httpConfiguration, gracefulShutdownFilter,
shutdownConfig, executorBuildItem.getExecutorProxy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import java.time.Duration;

import org.eclipse.microprofile.config.spi.Converter;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConvertWith;
import io.quarkus.runtime.configuration.NormalizedHttpPathConverter;
import io.vertx.core.http.ClientAuth;

@ConfigRoot(name = "http", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
Expand All @@ -17,7 +16,7 @@ public class HttpBuildTimeConfig {
* The HTTP root path. All web content will be served relative to this root path.
*/
@ConfigItem(defaultValue = "/")
@ConvertWith(NormalizeHttpRootPathConverter.class)
@ConvertWith(NormalizedHttpPathConverter.class)
public String rootPath;

public AuthConfig auth;
Expand Down Expand Up @@ -58,32 +57,4 @@ public class HttpBuildTimeConfig {
*/
@ConfigItem(defaultValue = "30s")
public Duration testTimeout;

/**
* Make sure the HTTP root path is fully normalized and always starts and ends with a '/'.
*/
public static class NormalizeHttpRootPathConverter implements Converter<String> {

private static final String SLASH = "/";

@Override
public String convert(String value) throws IllegalArgumentException, NullPointerException {
if (value == null) {
return SLASH;
}

value = value.trim();
if (SLASH.equals(value)) {
return value;
}
if (!value.startsWith(SLASH)) {
value = SLASH + value;
}
if (!value.endsWith(SLASH)) {
value = value + SLASH;
}

return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public Consumer<Route> start() {
StaticHandler staticHandler = StaticHandler.create(META_INF_RESOURCES).setDefaultContentEncoding("UTF-8");
handlers.add(ctx -> {
String rel = ctx.mountPoint() == null ? ctx.normalisedPath()
: ctx.normalisedPath().substring(ctx.mountPoint().length() - 1);
: ctx.normalisedPath().substring(
// let's be extra careful here in case Vert.x normalizes the mount points at some point
ctx.mountPoint().endsWith("/") ? ctx.mountPoint().length() - 1 : ctx.mountPoint().length());
if (knownPaths.contains(rel)) {
staticHandler.handle(ctx);
} else {
Expand Down

0 comments on commit f2c8fd9

Please sign in to comment.