use of io.vertx.ext.web.handler.sockjs.Transport in project vertx-openshift-it by cescoffier.
the class SockVerticle method setupSockJSEventBusHandler.
private void setupSockJSEventBusHandler(Transport usedTransport) {
status.put(usedTransport.toString() + "-EB", false);
status.put(usedTransport.toString() + "-sock", false);
SockJSHandlerOptions handlerOptions = new SockJSHandlerOptions();
Arrays.stream(Transport.values()).filter(t -> usedTransport != t).map(Enum::name).map(handlerOptions::addDisabledTransport);
router.route("/eventbus/" + usedTransport.name() + "/*").handler(SockJSHandler.create(vertx, handlerOptions).bridge(PERMITTED_OPTIONS, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
System.out.println(usedTransport.name() + " socket was created");
}
if (event.type() == BridgeEventType.SEND) {
vertx.eventBus().publish(TO_CLIENT, new JsonObject().put("content", event.getRawMessage()).encode());
}
event.complete(true);
if (event.type() == BridgeEventType.SOCKET_CLOSED) {
System.out.println(usedTransport.name() + " socket was closed");
}
}));
router.route("/sock/" + usedTransport.name() + "/*").handler(SockJSHandler.create(vertx, handlerOptions).socketHandler(socket -> {
socket.handler(content -> {
status.put(content.toString() + "-sock", true);
socket.write(content);
});
}));
}
use of io.vertx.ext.web.handler.sockjs.Transport in project vertx-openshift-it by cescoffier.
the class SockJsIT method checkSockStatuses.
@Test
public void checkSockStatuses() throws InterruptedException {
ensureThat("we can navigate to application ", () -> {
final Route route = client.routes().withName(deploymentAssistant.applicationName()).get();
webDriver.navigate().to(urlForRoute(route));
});
ensureThat("both statuses are updated", () -> {
await().atMost(3, TimeUnit.MINUTES).catchUncaughtExceptions().until(() -> isElementEmpty(EB_STATUS));
await().atMost(3, TimeUnit.MINUTES).catchUncaughtExceptions().until(() -> isElementEmpty(SOCK_STATUS));
});
ensureThat("all transports are working and asserted", () -> {
final JsonPath serverStatus = get("/status").body().jsonPath();
final JsonObject clientSideEbStatus = getJsonById(EB_STATUS);
final JsonObject clientSideSockStatus = getJsonById(SOCK_STATUS);
for (Transport t : Transport.values()) {
softly.assertThat(serverStatus.getBoolean(t + "-EB")).as("Transport " + t + " should be used on server side (on EventBus). ").isTrue();
softly.assertThat(serverStatus.getBoolean(t + "-sock")).as("Transport " + t + " should be used on server side (on SockJS). ").isTrue();
softly.assertThat(clientSideEbStatus.getInteger(t.name())).as("Transport " + t + " should be used on client side (on EventBus). ").isGreaterThan(0);
softly.assertThat(clientSideSockStatus.getInteger(t.name())).as("Transport " + t + " should be used on client side (on SockJS). ").isGreaterThan(0);
}
});
}
use of io.vertx.ext.web.handler.sockjs.Transport in project vertx-openshift-it by cescoffier.
the class SockVerticle method setUpRouter.
private void setUpRouter() {
router = Router.router(vertx);
for (Transport usedTransport : Transport.values()) {
setupSockJSEventBusHandler(usedTransport);
setupSockJSHandler(usedTransport);
}
router.route("/" + STATUS).handler(rc -> rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json").end(status.encodePrettily()));
// Serve the static resources
router.route().handler(StaticHandler.create());
}
Aggregations