use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.
the class WebExamples method example46.
public void example46(Vertx vertx) {
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
// Let through any messages sent to 'demo.orderMgr' from the client
PermittedOptions inboundPermitted1 = new PermittedOptions().setAddress("demo.orderMgr");
// Allow calls to the address 'demo.persistor' from the client as
// long as the messages have an action field with value 'find'
// and a collection field with value 'albums'
PermittedOptions inboundPermitted2 = new PermittedOptions().setAddress("demo.persistor").setMatch(new JsonObject().put("action", "find").put("collection", "albums"));
// Allow through any message with a field `wibble` with value `foo`.
PermittedOptions inboundPermitted3 = new PermittedOptions().setMatch(new JsonObject().put("wibble", "foo"));
// First let's define what we're going to allow from server -> client
// Let through any messages coming from address 'ticker.mystock'
PermittedOptions outboundPermitted1 = new PermittedOptions().setAddress("ticker.mystock");
// Let through any messages from addresses starting with "news."
// (e.g. news.europe, news.usa, etc)
PermittedOptions outboundPermitted2 = new PermittedOptions().setAddressRegex("news\\..+");
// Let's define what we're going to allow from client -> server
SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted1).addInboundPermitted(inboundPermitted1).addInboundPermitted(inboundPermitted3).addOutboundPermitted(outboundPermitted1).addOutboundPermitted(outboundPermitted2);
// mount the bridge on the router
router.mountSubRouter("/eventbus", sockJSHandler.bridge(options));
}
use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.
the class WebExamples method example45.
public void example45(Vertx vertx) {
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
SockJSBridgeOptions options = new SockJSBridgeOptions();
// mount the bridge on the router
router.mountSubRouter("/eventbus", sockJSHandler.bridge(options));
}
use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.
the class WebExamples method example47.
public void example47() {
// 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");
SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted);
}
use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions in project vertx-web by vert-x3.
the class WebExamples method example48.
public void example48(Vertx vertx, AuthenticationProvider 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);
// Now set up some basic auth handling:
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
AuthenticationHandler basicAuthHandler = BasicAuthHandler.create(authProvider);
router.route("/eventbus/*").handler(basicAuthHandler);
// mount the bridge on the router
router.mountSubRouter("/eventbus", sockJSHandler.bridge(new SockJSBridgeOptions().addInboundPermitted(inboundPermitted)));
}
use of io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions 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);
SockJSBridgeOptions options = new SockJSBridgeOptions().addInboundPermitted(inboundPermitted).setPingTimeout(5000);
// mount the bridge on the router
router.mountSubRouter("/eventbus", sockJSHandler.bridge(options, be -> {
if (be.type() == BridgeEventType.SOCKET_IDLE) {
// Do some custom handling...
}
be.complete(true);
}));
}
Aggregations