This is an automated email from the ASF dual-hosted git repository.
ricardozanini pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new 82b99c7dd Fix kie-issues-2001: Enable root path for custom UI in
data-index-service (#2234)
82b99c7dd is described below
commit 82b99c7dd994881d4f97f742b24d5c91eb57b4f7
Author: Ricardo Zanini <[email protected]>
AuthorDate: Fri Jun 13 13:45:25 2025 -0300
Fix kie-issues-2001: Enable root path for custom UI in data-index-service
(#2234)
Signed-off-by: Ricardo Zanini <[email protected]>
---
.../index/service/vertx/IndexRouteRegistrar.java | 16 +++--
.../kie/kogito/index/service/CustomUIPageIT.java | 2 +
.../kie/kogito/index/service/CustomUIResource.java | 77 ++++++++++++++++++++++
.../src/test/resources/application.properties | 3 -
4 files changed, 91 insertions(+), 7 deletions(-)
diff --git
a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
index c7481beab..c33928625 100644
---
a/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
+++
b/data-index/data-index-service/data-index-service-common/src/main/java/org/kie/kogito/index/service/vertx/IndexRouteRegistrar.java
@@ -24,6 +24,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
import io.quarkus.runtime.StartupEvent;
import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.FileSystemAccess;
import io.vertx.ext.web.handler.StaticHandler;
import jakarta.enterprise.context.ApplicationScoped;
@@ -52,11 +53,18 @@ public class IndexRouteRegistrar {
.setStatusCode(302)
.end());
-
router.route("/index.html").handler(StaticHandler.create(dir).setIndexPage("index.html"));
+ final String normalized = dir.endsWith("/") ? dir.substring(0,
dir.length() - 1) : dir;
+ final FileSystemAccess fsa = normalized.startsWith("/") ?
FileSystemAccess.ROOT : FileSystemAccess.RELATIVE;
+ final StaticHandler handler = StaticHandler.create(fsa, normalized)
+ .setDefaultContentEncoding("utf-8")
+ .setDirectoryListing(false)
+ .setAlwaysAsyncFS(true)
+ .setIndexPage("index.html")
+ .setCacheEntryTimeout(86400) // cache for one day
+ .setEnableFSTuning(true);
- router.route("/ui/*")
- .handler(StaticHandler.create(dir)
- .setIndexPage("index.html"));
+ router.route("/index.html").handler(handler);
+ router.route("/ui/*").handler(handler);
});
}
}
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
index 5fb812f34..6c0eeeeb1 100644
---
a/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIPageIT.java
@@ -20,12 +20,14 @@ package org.kie.kogito.index.service;
import org.junit.jupiter.api.Test;
+import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
+@QuarkusTestResource(CustomUIResource.class)
public class CustomUIPageIT {
/**
* Override the property to point to our test resources' directory.
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIResource.java
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIResource.java
new file mode 100644
index 000000000..fe0ab3ccc
--- /dev/null
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/java/org/kie/kogito/index/service/CustomUIResource.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.index.service;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+
+public class CustomUIResource implements QuarkusTestResourceLifecycleManager {
+ private static final Logger LOG =
LoggerFactory.getLogger(CustomUIResource.class);
+ private Path tempDir;
+
+ @Override
+ public Map<String, String> start() {
+ try {
+ // Create a temp directory
+ tempDir = Files.createTempDirectory("custom-ui");
+ // Copy 'ui' resources from classpath to tempDir
+ Path uiSource =
Paths.get(getClass().getClassLoader().getResource("ui").toURI());
+ Files.walk(uiSource).forEach(source -> {
+ try {
+ Path dest =
tempDir.resolve(uiSource.relativize(source).toString());
+ if (Files.isDirectory(source)) {
+ Files.createDirectories(dest);
+ } else {
+ Files.copy(source, dest);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to copy UI resource: "
+ source, e);
+ }
+ });
+ LOG.info("Copied UI files to {}", tempDir);
+
+ // Override the config property to point to the temp directory
+ return Collections.singletonMap(
+ "kogito.data-index.ui.path", tempDir.toString());
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to set up CustomUIResource", e);
+ }
+ }
+
+ @Override
+ public void stop() {
+ if (tempDir != null) {
+ try {
+ Files.walk(tempDir)
+ .sorted((a, b) -> b.compareTo(a))
+ .forEach(path -> path.toFile().delete());
+ } catch (Exception e) {
+ LOG.warn("Failed to delete temp UI directory {}", tempDir, e);
+ }
+ }
+ }
+}
diff --git
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
index a31453e9f..0a9f654d2 100644
---
a/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
+++
b/data-index/data-index-service/data-index-service-inmemory/src/test/resources/application.properties
@@ -53,6 +53,3 @@ quarkus.oidc.auth-server-url=none
# Not using Dev service in test, but rather
org.kie.kogito.testcontainers.quarkus.KeycloakQuarkusTestResource
quarkus.keycloak.devservices.enabled=false
-
-# UI WebPage
-kogito.data-index.ui.path=ui
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]