Search in sources :

Example 11 with SockJSHandler

use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.

the class WebExamples method example43.

public void example43(Vertx vertx) {
    Router router = Router.router(vertx);
    SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
    router.route("/myapp/*").handler(sockJSHandler);
}
Also used : SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 12 with SockJSHandler

use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.

the class WebExamples method example48.

public void example48(Vertx vertx, AuthProvider authProvider) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderService' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
    // But only if the user is logged in and has the authority "place_orders"
    inboundPermitted.setRequiredAuthority("place_orders");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    sockJSHandler.bridge(new BridgeOptions().addInboundPermitted(inboundPermitted));
    // Now set up some basic auth handling:
    router.route().handler(CookieHandler.create());
    router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
    AuthHandler basicAuthHandler = BasicAuthHandler.create(authProvider);
    router.route("/eventbus/*").handler(basicAuthHandler);
    router.route("/eventbus/*").handler(sockJSHandler);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 13 with SockJSHandler

use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.

the class WebExamples method example49.

public void example49(Vertx vertx) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderMgr' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.someService");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);
    sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.RECEIVE) {
            if (be.getRawMessage().getString("body").equals("armadillos")) {
                // Reject it
                be.complete(false);
                return;
            }
        }
        be.complete(true);
    });
    router.route("/eventbus/*").handler(sockJSHandler);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 14 with SockJSHandler

use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.

the class WebExamples method example48_1.

public void example48_1(Vertx vertx) {
    Router router = Router.router(vertx);
    // Let through any messages sent to 'demo.orderService' from the client
    PermittedOptions inboundPermitted = new PermittedOptions().setAddress("demo.orderService");
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted);
    sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.PUBLISH || be.type() == BridgeEventType.SEND) {
            // Add some headers
            JsonObject headers = new JsonObject().put("header1", "val").put("header2", "val2");
            JsonObject rawMessage = be.getRawMessage();
            rawMessage.put("headers", headers);
            be.setRawMessage(rawMessage);
        }
        be.complete(true);
    });
    router.route("/eventbus/*").handler(sockJSHandler);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.bridge.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 15 with SockJSHandler

use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.

the class WebExamples method handleSocketIdle.

public void handleSocketIdle(Vertx vertx, PermittedOptions inboundPermitted) {
    Router router = Router.router(vertx);
    // Initialize SockJS handler
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions().addInboundPermitted(inboundPermitted).setPingTimeout(5000);
    sockJSHandler.bridge(options, be -> {
        if (be.type() == BridgeEventType.SOCKET_IDLE) {
        // Do some custom handling...
        }
        be.complete(true);
    });
    router.route("/eventbus/*").handler(sockJSHandler);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Aggregations

SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)15 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)13 Router (io.vertx.ext.web.Router)7 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)7 JsonObject (io.vertx.core.json.JsonObject)6 EventBus (io.vertx.core.eventbus.EventBus)5 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)4 SockJSHandlerOptions (io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions)2 ProcessorServiceImpl (io.vertx.examples.service.impl.ProcessorServiceImpl)1