use of io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions in project vertx-web by vert-x3.
the class WebExamples method example44.
public void example44(Vertx vertx) {
Router router = Router.router(vertx);
SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
sockJSHandler.socketHandler(sockJSSocket -> {
// Just echo the data back
sockJSSocket.handler(sockJSSocket::write);
});
router.route("/myapp/*").handler(sockJSHandler);
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions 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);
});
}));
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions in project vertx-web by vert-x3.
the class SockJSHandlerImpl method installTestApplications.
public static void installTestApplications(Router router, Vertx vertx) {
// These applications are required by the SockJS protocol and QUnit tests
router.route("/echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> sock.handler(sock::write)));
router.route("/close/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(SockJSSocket::close));
router.route("/disabled_websocket_echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096).addDisabledTransport("WEBSOCKET")).socketHandler(sock -> sock.handler(sock::write)));
router.route("/ticker/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> {
long timerID = vertx.setPeriodic(1000, tid -> sock.write(buffer("tick!")));
sock.endHandler(v -> vertx.cancelTimer(timerID));
}));
router.route("/amplify/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(sock -> sock.handler(data -> {
String str = data.toString();
int n = Integer.valueOf(str);
if (n < 0 || n > 19) {
n = 1;
}
int num = (int) Math.pow(2, n);
Buffer buff = buffer(num);
for (int i = 0; i < num; i++) {
buff.appendByte((byte) 'x');
}
sock.write(buff);
})));
router.route("/broadcast/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096)).socketHandler(new Handler<SockJSSocket>() {
Set<String> connections = new HashSet<>();
public void handle(SockJSSocket sock) {
connections.add(sock.writeHandlerID());
sock.handler(buffer -> {
for (String actorID : connections) {
vertx.eventBus().publish(actorID, buffer);
}
});
sock.endHandler(v -> connections.remove(sock.writeHandlerID()));
}
}));
router.route("/cookie_needed_echo/*").handler(SockJSHandler.create(vertx, new SockJSHandlerOptions().setMaxBytesStreaming(4096).setInsertJSESSIONID(true)).socketHandler(sock -> sock.handler(sock::write)));
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions 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.SockJSHandlerOptions in project api-framework by vinscom.
the class SockJSHandlerInstance method start.
@StartService
public void start() {
// Eventbus handle
SockJSHandlerOptions sockJSHandlerOptions = (new SockJSHandlerOptions()).addDisabledTransport(Transport.EVENT_SOURCE.toString()).addDisabledTransport(Transport.HTML_FILE.toString()).addDisabledTransport(Transport.JSON_P.toString()).addDisabledTransport(Transport.XHR.toString()).setInsertJSESSIONID(false);
mSockJSHandler = SockJSHandler.create(getVertx(), sockJSHandlerOptions).bridge(getBridgeOptions(), getBridgeEventHandler());
}
Aggregations