io.quarkus.devui.runtime.DevUIWebSocket Maven / Gradle / Ivy
The newest version!
package io.quarkus.devui.runtime;
import jakarta.enterprise.inject.spi.CDI;
import org.jboss.logging.Logger;
import io.quarkus.devui.runtime.comms.JsonRpcRouter;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.http.ServerWebSocket;
import io.vertx.ext.web.RoutingContext;
/**
* This is the main entry point for Dev UI Json RPC communication
*/
public class DevUIWebSocket implements Handler {
private static final Logger LOG = Logger.getLogger(DevUIWebSocket.class.getName());
@Override
public void handle(RoutingContext event) {
if (WEBSOCKET.equalsIgnoreCase(event.request().getHeader(UPGRADE)) && !event.request().isEnded()) {
event.request().toWebSocket(new Handler>() {
@Override
public void handle(AsyncResult event) {
if (event.succeeded()) {
ServerWebSocket socket = event.result();
addSocket(socket);
} else {
LOG.debug("Failed to connect to dev ui communication server", event.cause());
}
}
});
return;
}
event.next();
}
private void addSocket(ServerWebSocket session) {
try {
JsonRpcRouter jsonRpcRouter = CDI.current().select(JsonRpcRouter.class).get();
jsonRpcRouter.addSocket(session);
} catch (IllegalStateException ise) {
LOG.debug("Failed to connect to dev ui communication server, " + ise.getMessage());
}
}
private static final String UPGRADE = "Upgrade";
private static final String WEBSOCKET = "websocket";
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy