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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations