Skip to content

Commit

Permalink
goo
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Dec 18, 2023
1 parent bf53906 commit 685623a
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public ResourceNotFoundHandler(String httpRoot, List<RouteDescription> routes,

@Override
public void handle(RoutingContext routingContext) {
String path = routingContext.normalizedPath();

System.out.println(">>>>>>>>>>>>>>>>>> path = " + path);

TemplateHtmlBuilder builder = new TemplateHtmlBuilder("404 - Resource Not Found", "", "No resources discovered");
builder.resourcesStart("Reactive Routes");
builder.resourceStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import io.quarkus.devui.deployment.jsonrpc.DevUIDatabindCodec;
import io.quarkus.devui.runtime.DevUICORSFilter;
import io.quarkus.devui.runtime.DevUIRecorder;
import io.quarkus.devui.runtime.VertxRouteInfoService;
import io.quarkus.devui.runtime.comms.JsonRpcRouter;
import io.quarkus.devui.runtime.jsonrpc.JsonRpcMethod;
import io.quarkus.devui.runtime.jsonrpc.JsonRpcMethodName;
Expand Down Expand Up @@ -207,7 +208,7 @@ void registerDevUiHandlers(
Handler<RoutingContext> endpointInfoHandler = recorder.endpointInfoHandler(basepath);

routeProducer.produce(
nonApplicationRootPathBuildItem.routeBuilder().route(DEVUI + SLASH + "endpoints.json")
nonApplicationRootPathBuildItem.routeBuilder().route(DEVUI + SLASH + "endpoints" + SLASH + "*")
.handler(endpointInfoHandler)
.build());

Expand Down Expand Up @@ -237,7 +238,7 @@ void registerDevUiHandlers(
// Redirect naked to welcome if there is no index.html
if (!hasOwnIndexHtml()) {
routeProducer.produce(httpRootPathBuildItem.routeBuilder()
.orderedRoute("/", FilterBuildItem.CORS + 1)
.orderedRoute("/", 20500 + 1)
.handler(recorder.redirect(contextRoot, "welcome"))
.build());
}
Expand All @@ -263,6 +264,7 @@ void additionalBean(BuildProducer<AdditionalBeanBuildItem> additionalBeanProduce

additionalBeanProducer.produce(AdditionalBeanBuildItem.builder()
.addBeanClass(JsonRpcRouter.class)
.addBeanClass(VertxRouteInfoService.class)
.setUnremovable().build());

// Make sure all JsonRPC Providers is in the index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ InternalPageBuildItem createEndpointsPage(NonApplicationRootPathBuildItem nonApp
.icon("font-awesome-solid:plug")
.componentLink("qwc-endpoints.js"));

endpointsPage.addPage(Page.webComponentPageBuilder()
.namespace("devui-endpoints")
.title("Routes")
.icon("font-awesome-solid:route")
.componentLink("qwc-routes.js"));

return endpointsPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class QwcEndpoints extends LitElement {
}

async load() {
const response = await fetch(basepath + "/endpoints.json");
const response = await fetch(basepath + "/endpoints/endpoints.json");
const data = await response.json();
this._info = data;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { LitElement, html, css} from 'lit';
import { basepath } from 'devui-data';
import '@vaadin/progress-bar';
import '@vaadin/grid';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

/**
* This component show all available routes
*/
export class QwcRoutes extends LitElement {

static styles = css`
.infogrid {
width: 99%;
height: 99%;
}
a {
cursor: pointer;
color: var(--lumo-body-text-color);
}
a:link {
text-decoration: none;
color: var(--lumo-body-text-color);
}
a:visited {
text-decoration: none;
color: var(--lumo-body-text-color);
}
a:active {
text-decoration: none;
color: var(--lumo-body-text-color);
}
a:hover {
color: var(--quarkus-red);
}
`;

static properties = {
_routes: {state: true},
}

constructor() {
super();
this._routes = null;
}

async connectedCallback() {
super.connectedCallback();
await this.load();
}

async load() {
const response = await fetch(basepath + "/endpoints/routes.json");
const data = await response.json();
this._routes = data;
}

render() {
if (this._routes) {
return html`<vaadin-grid .items="${this._routes}" class="infogrid">
<vaadin-grid-sort-column resizable
header='Handler'
path="contextHandlers"
${columnBodyRenderer(this._contextHandlersRenderer, [])}>>
</vaadin-grid-sort-column>
<vaadin-grid-sort-column resizable
header="Order"
path="order">
</vaadin-grid-sort-column>
<vaadin-grid-sort-column resizable
header="Path"
path="path">
</vaadin-grid-sort-column>
</vaadin-grid>`;
}else{
return html`
<div style="color: var(--lumo-secondary-text-color);width: 95%;" >
<div>Fetching routes...</div>
<vaadin-progress-bar indeterminate></vaadin-progress-bar>
</div>
`;
}
}

_contextHandlersRenderer(route){
const regex1 = /([^$]+)*/;
const match1 = route.contextHandlers.match(regex1);
let className1 = match1 ? match1[1] : route.contextHandlers;
if(className1.startsWith("[")){
className1 = className1.substring(1);
}

return html`<code>${className1}</code>`;
}

}
customElements.define('qwc-routes', QwcRoutes);
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.util.List;
import java.util.Map;

import jakarta.enterprise.inject.spi.CDI;

import io.vertx.core.Handler;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

Expand Down Expand Up @@ -45,13 +48,20 @@ public void handle(RoutingContext event) {
String path = normalizedPath.substring(0, si);
String fileName = normalizedPath.substring(si);
if (path.startsWith(basePath) && fileName.equals("endpoints.json")) {

event.response()
.setStatusCode(STATUS)
.setStatusMessage(OK)
.putHeader(CONTENT_TYPE, "application/json")
.end(Json.encodePrettily(getContent()));

} else if (path.startsWith(basePath) && fileName.equals("routes.json")) {
VertxRouteInfoService vertxRouteInfoService = CDI.current().select(VertxRouteInfoService.class).get();
JsonArray info = vertxRouteInfoService.getInfo();
event.response()
.setStatusCode(STATUS)
.setStatusMessage(OK)
.putHeader(CONTENT_TYPE, "application/json")
.end(Json.encodePrettily(info));
} else {
event.next();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.devui.runtime;

import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.impl.RouteImpl;

@ApplicationScoped
public class VertxRouteInfoService {

private Router router;

public void init(@Observes Router router, Vertx vertx) {
this.router = router;
}

public JsonArray getInfo() {
JsonArray allRoutes = new JsonArray();
for (Route r : router.getRoutes()) {
String ts = ((RouteImpl) r).toString();
int begin = ts.lastIndexOf("{") + 1;
int end = ts.indexOf("}");
ts = ts.substring(begin, end);

String fields[] = ts.split(",");
Map<String, Object> routeMap = new HashMap<>();
for (String field : fields) {
String kv[] = field.split("=");
String key = kv[0];
String value = "";
if (kv.length > 1) {
value = kv[1];
}
routeMap.put(key.trim(), value.trim());
}
allRoutes.add(new JsonObject(routeMap));
}
return allRoutes;
}
}

0 comments on commit 685623a

Please sign in to comment.