Skip to content

Commit

Permalink
Merge pull request #14179 from phillip-kruger/non-application-path
Browse files Browse the repository at this point in the history
Some Non-Application path updates
  • Loading branch information
phillip-kruger authored Jan 8, 2021
2 parents 291ea15 + 8de45ed commit 2133dd2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLRecorder;
import io.quarkus.smallrye.graphql.runtime.SmallRyeGraphQLRuntimeConfig;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RequireBodyHandlerBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
Expand Down Expand Up @@ -92,6 +93,8 @@ public class SmallRyeGraphQLProcessor {
private static final String FILE_TO_UPDATE = "render.js";
private static final String LINE_TO_UPDATE = "const api = '";
private static final String LINE_FORMAT = LINE_TO_UPDATE + "%s';";
private static final String UI_LINE_TO_UPDATE = "const ui = '";
private static final String UI_LINE_FORMAT = UI_LINE_TO_UPDATE + "%s';";

@BuildStep
void feature(BuildProducer<FeatureBuildItem> featureProducer) {
Expand Down Expand Up @@ -205,15 +208,21 @@ void buildExecutionEndpoint(
// add graphql endpoint for not found display in dev or test mode
if (launchMode.getLaunchMode().isDevOrTest()) {
notFoundPageDisplayableEndpointProducer
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLConfig.rootPath));
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLConfig.rootPath,
"MicroProfile GraphQL Endpoint"));
notFoundPageDisplayableEndpointProducer
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLConfig.rootPath + SCHEMA_PATH));
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLConfig.rootPath + SCHEMA_PATH,
"MicroProfile GraphQL Schema"));
}

Boolean allowGet = ConfigProvider.getConfig().getOptionalValue(ConfigKey.ALLOW_GET, boolean.class).orElse(false);

Handler<RoutingContext> executionHandler = recorder.executionHandler(allowGet);
routeProducer.produce(new RouteBuildItem(graphQLConfig.rootPath, executionHandler, HandlerType.BLOCKING));
routeProducer.produce(new RouteBuildItem.Builder()
.route(graphQLConfig.rootPath)
.handler(executionHandler)
.blockingRoute()
.build());

}

Expand Down Expand Up @@ -431,6 +440,7 @@ void getGraphqlUiFinalDestination(
BuildProducer<NotFoundPageDisplayableEndpointBuildItem> notFoundPageDisplayableEndpointProducer,
BuildProducer<SmallRyeGraphQLBuildItem> smallRyeGraphQLBuildProducer,
HttpRootPathBuildItem httpRootPath,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
CurateOutcomeBuildItem curateOutcomeBuildItem,
LaunchModeBuildItem launchMode,
SmallRyeGraphQLConfig graphQLConfig) throws Exception {
Expand All @@ -443,18 +453,21 @@ void getGraphqlUiFinalDestination(
}

String graphQLPath = httpRootPath.adjustPath(graphQLConfig.rootPath);
String graphQLUiPath = nonApplicationRootPathBuildItem
.adjustPath(httpRootPath.adjustPath(graphQLConfig.ui.rootPath));

AppArtifact artifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, GRAPHQL_UI_WEBJAR_GROUP_ID,
GRAPHQL_UI_WEBJAR_ARTIFACT_ID);
if (launchMode.getLaunchMode().isDevOrTest()) {
Path tempPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem, launchMode, artifact,
GRAPHQL_UI_WEBJAR_PREFIX);
WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLPath, LINE_TO_UPDATE, LINE_FORMAT);
WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLUiPath, UI_LINE_TO_UPDATE, UI_LINE_FORMAT);

smallRyeGraphQLBuildProducer.produce(new SmallRyeGraphQLBuildItem(tempPath.toAbsolutePath().toString(),
httpRootPath.adjustPath(graphQLConfig.ui.rootPath)));
graphQLUiPath));
notFoundPageDisplayableEndpointProducer
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLConfig.ui.rootPath + "/"));
.produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLUiPath + "/", "MicroProfile GraphQL UI"));

} else {
Map<String, byte[]> files = WebJarUtil.copyResourcesForProduction(curateOutcomeBuildItem, artifact,
Expand All @@ -469,6 +482,10 @@ void getGraphqlUiFinalDestination(
.updateUrl(new String(content, StandardCharsets.UTF_8), graphQLPath, LINE_TO_UPDATE,
LINE_FORMAT)
.getBytes(StandardCharsets.UTF_8);
content = WebJarUtil
.updateUrl(new String(content, StandardCharsets.UTF_8), graphQLPath, UI_LINE_TO_UPDATE,
UI_LINE_FORMAT)
.getBytes(StandardCharsets.UTF_8);
}
fileName = GRAPHQL_UI_FINAL_DESTINATION + "/" + fileName;

Expand All @@ -477,7 +494,7 @@ void getGraphqlUiFinalDestination(
}

smallRyeGraphQLBuildProducer.produce(new SmallRyeGraphQLBuildItem(GRAPHQL_UI_FINAL_DESTINATION,
httpRootPath.adjustPath(graphQLConfig.ui.rootPath)));
graphQLUiPath));
}
}
}
Expand All @@ -495,8 +512,16 @@ void registerGraphQLUiHandler(
if (shouldInclude(launchMode, graphQLConfig)) {
Handler<RoutingContext> handler = recorder.uiHandler(smallRyeGraphQLBuildItem.getGraphqlUiFinalDestination(),
smallRyeGraphQLBuildItem.getGraphqlUiPath(), runtimeConfig);
routeProducer.produce(new RouteBuildItem(graphQLConfig.ui.rootPath, handler));
routeProducer.produce(new RouteBuildItem(graphQLConfig.ui.rootPath + "/*", handler));
routeProducer.produce(new RouteBuildItem.Builder()
.nonApplicationRoute(true)
.route(graphQLConfig.ui.rootPath)
.handler(handler)
.build());
routeProducer.produce(new RouteBuildItem.Builder()
.nonApplicationRoute(true)
.route(graphQLConfig.ui.rootPath + "/*")
.handler(handler)
.build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void build(SmallRyeHealthRecorder recorder,
BuildProducer<AdditionalBeanBuildItem> additionalBean,
BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotation,
BuildProducer<NotFoundPageDisplayableEndpointBuildItem> displayableEndpoints,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchMode,
SmallRyeHealthConfig healthConfig)
throws IOException, ClassNotFoundException {
Expand All @@ -136,15 +137,16 @@ void build(SmallRyeHealthRecorder recorder,

// add health endpoints to not found page
if (launchMode.getLaunchMode().isDevOrTest()) {
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.rootPath));
String basePath = nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath);
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath));
displayableEndpoints
.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.rootPath + healthConfig.livenessPath));
.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.livenessPath));
displayableEndpoints
.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.rootPath + healthConfig.readinessPath));
.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.readinessPath));
displayableEndpoints
.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.rootPath + healthConfig.groupPath));
.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.groupPath));
displayableEndpoints
.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.rootPath + healthConfig.wellnessPath));
.produce(new NotFoundPageDisplayableEndpointBuildItem(basePath + healthConfig.wellnessPath));
}

// Discover the beans annotated with @Health, @Liveness, @Readiness, @HealthGroup,
Expand Down Expand Up @@ -258,14 +260,16 @@ public void defineHealthRoutes(BuildProducer<RouteBuildItem> routes,

@BuildStep(onlyIf = OpenAPIIncluded.class)
public void includeInOpenAPIEndpoint(BuildProducer<AddToOpenAPIDefinitionBuildItem> openAPIProducer,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
Capabilities capabilities,
SmallRyeHealthConfig healthConfig) {

// Add to OpenAPI if OpenAPI is available
if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI)) {
HealthOpenAPIFilter filter = new HealthOpenAPIFilter(healthConfig.rootPath,
healthConfig.rootPath + healthConfig.livenessPath,
healthConfig.rootPath + healthConfig.readinessPath);
String basePath = nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath);
HealthOpenAPIFilter filter = new HealthOpenAPIFilter(basePath,
basePath + healthConfig.livenessPath,
basePath + healthConfig.readinessPath);
openAPIProducer.produce(new AddToOpenAPIDefinitionBuildItem(filter));
}
}
Expand Down Expand Up @@ -367,6 +371,7 @@ void registerUiExtension(
BuildProducer<NotFoundPageDisplayableEndpointBuildItem> notFoundPageDisplayableEndpointProducer,
BuildProducer<SmallRyeHealthBuildItem> smallRyeHealthBuildProducer,
HttpRootPathBuildItem httpRootPath,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
SmallRyeHealthConfig healthConfig,
CurateOutcomeBuildItem curateOutcomeBuildItem,
LaunchModeBuildItem launchMode) throws Exception {
Expand All @@ -378,7 +383,7 @@ void registerUiExtension(
"quarkus.smallrye-health.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else.");
}

String healthPath = httpRootPath.adjustPath(healthConfig.rootPath);
String healthPath = nonApplicationRootPathBuildItem.adjustPath(httpRootPath.adjustPath(healthConfig.rootPath));

AppArtifact artifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, HEALTH_UI_WEBJAR_GROUP_ID,
HEALTH_UI_WEBJAR_ARTIFACT_ID);
Expand All @@ -392,7 +397,9 @@ void registerUiExtension(
httpRootPath.adjustPath(healthConfig.ui.rootPath)));

notFoundPageDisplayableEndpointProducer
.produce(new NotFoundPageDisplayableEndpointBuildItem(healthConfig.ui.rootPath + "/"));
.produce(new NotFoundPageDisplayableEndpointBuildItem(
nonApplicationRootPathBuildItem
.adjustPath(httpRootPath.adjustPath(healthConfig.ui.rootPath + "/"))));
} else {
Map<String, byte[]> files = WebJarUtil.copyResourcesForProduction(curateOutcomeBuildItem, artifact,
HEALTH_UI_WEBJAR_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void testOpenApiPathAccessResource() {
.when().get(OPEN_API_PATH)
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("paths", Matchers.hasKey("/health/ready"))
.body("paths", Matchers.hasKey("/health/live"))
.body("paths", Matchers.hasKey("/health"))
.body("paths", Matchers.hasKey("/q/health/ready"))
.body("paths", Matchers.hasKey("/q/health/live"))
.body("paths", Matchers.hasKey("/q/health"))
.body("components.schemas.HealthCheckResponse.type", Matchers.equalTo("object"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import io.quarkus.smallrye.openapi.runtime.OpenApiRecorder;
import io.quarkus.smallrye.openapi.runtime.OpenApiRuntimeConfig;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
import io.smallrye.openapi.api.OpenApiConfig;
Expand Down Expand Up @@ -149,6 +150,7 @@ List<HotDeploymentWatchedFileBuildItem> configFiles() {
RouteBuildItem handler(LaunchModeBuildItem launch,
BuildProducer<NotFoundPageDisplayableEndpointBuildItem> displayableEndpoints,
OpenApiRecorder recorder,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
OpenApiRuntimeConfig openApiRuntimeConfig,
ShutdownContextBuildItem shutdownContext,
SmallRyeOpenApiConfig openApiConfig) {
Expand All @@ -165,7 +167,8 @@ RouteBuildItem handler(LaunchModeBuildItem launch,
*/
if (launch.getLaunchMode() == LaunchMode.DEVELOPMENT) {
recorder.setupClDevMode(shutdownContext);
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(openApiConfig.path, "Open API"));
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(
nonApplicationRootPathBuildItem.adjustPath(openApiConfig.path), "Open API Schema document"));
}

Handler<RoutingContext> handler = recorder.handler(openApiRuntimeConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void getSwaggerUiFinalDestination(

swaggerUiBuildProducer.produce(new SwaggerUiBuildItem(tempPath.toAbsolutePath().toString(),
nonApplicationRootPathBuildItem.adjustPath(swaggerUiConfig.path)));
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(swaggerUiConfig.path + "/"));
displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem(
nonApplicationRootPathBuildItem.adjustPath(swaggerUiConfig.path + "/"), "Open API UI"));
} else {
Map<String, byte[]> files = WebJarUtil.copyResourcesForProduction(curateOutcomeBuildItem, artifact,
SWAGGER_UI_WEBJAR_PREFIX);
Expand Down

0 comments on commit 2133dd2

Please sign in to comment.