Search in sources :

Example 16 with BridgeOptions

use of io.vertx.ext.web.handler.sockjs.BridgeOptions 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 17 with BridgeOptions

use of io.vertx.ext.web.handler.sockjs.BridgeOptions 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 18 with BridgeOptions

use of io.vertx.ext.web.handler.sockjs.BridgeOptions 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 19 with BridgeOptions

use of io.vertx.ext.web.handler.sockjs.BridgeOptions 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)

Example 20 with BridgeOptions

use of io.vertx.ext.web.handler.sockjs.BridgeOptions in project vertx-openshift-it by cescoffier.

the class GreetingServiceVerticle method getSockJsHandler.

private Handler<RoutingContext> getSockJsHandler() {
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions();
    options.addInboundPermitted(new PermittedOptions().setAddress("circuit-breaker"));
    options.addOutboundPermitted(new PermittedOptions().setAddress("circuit-breaker"));
    return sockJSHandler.bridge(options);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) SockJSHandler(io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)

Aggregations

BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)20 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)14 Router (io.vertx.ext.web.Router)12 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)12 JsonObject (io.vertx.core.json.JsonObject)9 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)6 EventBus (io.vertx.core.eventbus.EventBus)5 HttpServer (io.vertx.core.http.HttpServer)2 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Runner (io.vertx.example.util.Runner)1 ProcessorServiceImpl (io.vertx.examples.service.impl.ProcessorServiceImpl)1 AuthProvider (io.vertx.ext.auth.AuthProvider)1 BridgeEventType (io.vertx.ext.bridge.BridgeEventType)1 MetricsService (io.vertx.ext.dropwizard.MetricsService)1 StaticHandler (io.vertx.ext.web.handler.StaticHandler)1 SockJSHandler (io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)1 Random (java.util.Random)1