Search in sources :

Example 1 with Transport

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);
        });
    }));
}
Also used : Transport(io.vertx.ext.web.handler.sockjs.Transport) Arrays(java.util.Arrays) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) StaticHandler(io.vertx.ext.web.handler.StaticHandler) AbstractVerticle(io.vertx.core.AbstractVerticle) BridgeEventType(io.vertx.ext.bridge.BridgeEventType) HttpHeaders(io.vertx.core.http.HttpHeaders) Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with Transport

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);
        }
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonPath(io.restassured.path.json.JsonPath) Transport(io.vertx.ext.web.handler.sockjs.Transport) Route(io.fabric8.openshift.api.model.Route) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) Test(org.junit.Test)

Example 3 with Transport

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());
}
Also used : Transport(io.vertx.ext.web.handler.sockjs.Transport)

Aggregations

Transport (io.vertx.ext.web.handler.sockjs.Transport)3 JsonObject (io.vertx.core.json.JsonObject)2 Route (io.fabric8.openshift.api.model.Route)1 JsonPath (io.restassured.path.json.JsonPath)1 AbstractVerticle (io.vertx.core.AbstractVerticle)1 HttpHeaders (io.vertx.core.http.HttpHeaders)1 BridgeEventType (io.vertx.ext.bridge.BridgeEventType)1 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)1 Router (io.vertx.ext.web.Router)1 StaticHandler (io.vertx.ext.web.handler.StaticHandler)1 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)1 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)1 SockJSHandlerOptions (io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions)1 Kube.urlForRoute (io.vertx.it.openshift.utils.Kube.urlForRoute)1 Arrays (java.util.Arrays)1 Test (org.junit.Test)1