-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
208 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...n/deployment/src/main/java/io/quarkiverse/temporal/deployment/devui/TemporalUiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkiverse.temporal.deployment.devui; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
import io.smallrye.config.ConfigMapping; | ||
|
||
@ConfigMapping(prefix = "quarkus.temporal.ui") | ||
@ConfigRoot(phase = ConfigPhase.BUILD_TIME) | ||
public interface TemporalUiConfig { | ||
|
||
/** | ||
* The url of the Temporal UI. | ||
*/ | ||
Optional<String> url(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
extension/runtime/src/main/java/io/quarkiverse/temporal/devui/TemporalUiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkiverse.temporal.devui; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.ext.web.RoutingContext; | ||
import io.vertx.ext.web.client.HttpRequest; | ||
import io.vertx.ext.web.client.WebClient; | ||
|
||
@Recorder | ||
public class TemporalUiProxy { | ||
|
||
private static final Logger log = Logger.getLogger(TemporalUiProxy.class); | ||
|
||
public Handler<RoutingContext> handler(Supplier<Vertx> vertx) { | ||
final var portOptional = ConfigProvider.getConfig().getOptionalValue("quarkus.temporal.ui.port", Integer.class); | ||
final var client = WebClient.create(vertx.get()); | ||
|
||
return new Handler<RoutingContext>() { | ||
@Override | ||
public void handle(RoutingContext event) { | ||
if (!portOptional.isPresent()) { | ||
event.response().setStatusCode(404).end(); | ||
return; | ||
} | ||
|
||
final Integer port = portOptional.get(); | ||
final HttpRequest<Buffer> r = client.request(event.request().method(), port, "localhost", | ||
event.request().uri()); | ||
|
||
// copy all headers | ||
event.request().headers().forEach(h -> r.putHeader(h.getKey(), h.getValue())); | ||
|
||
if ("websocket".equals(event.request().getHeader("upgrade"))) { | ||
// handle WebSocket request | ||
event.request().toWebSocket().onComplete(ws -> { | ||
if (ws.succeeded()) { | ||
event.request().resume(); | ||
ws.result().handler(buff -> { | ||
event.response().write(buff); | ||
}); | ||
} else { | ||
log.error("WebSocket failed", ws.cause()); | ||
} | ||
}); | ||
} else { | ||
// handle normal request | ||
r.sendBuffer(event.body().buffer()).andThen(resp -> { | ||
event.response().setStatusCode(resp.result().statusCode()); | ||
resp.result().headers().forEach(h -> event.response().putHeader(h.getKey(), h.getValue())); | ||
event.response().end(resp.result().bodyAsBuffer()); | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
} |