Search in sources :

Example 1 with SockJSSocket

use of io.vertx.ext.web.handler.sockjs.SockJSSocket 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)));
}
Also used : SockJSSocket(io.vertx.ext.web.handler.sockjs.SockJSSocket) Iterator(java.util.Iterator) MessageDigest(java.security.MessageDigest) Date(java.util.Date) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) Router(io.vertx.ext.web.Router) SimpleDateFormat(java.text.SimpleDateFormat) Set(java.util.Set) RoutingContext(io.vertx.ext.web.RoutingContext) BridgeEvent(io.vertx.ext.web.handler.sockjs.BridgeEvent) LoggerFactory(io.vertx.core.logging.LoggerFactory) ArrayList(java.util.ArrayList) Transport(io.vertx.ext.web.handler.sockjs.Transport) HashSet(java.util.HashSet) List(java.util.List) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) Buffer(io.vertx.core.buffer.Buffer) LocalMap(io.vertx.core.shareddata.LocalMap) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) Buffer(io.vertx.core.buffer.Buffer) SockJSHandlerOptions(io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions) Set(java.util.Set) HashSet(java.util.HashSet) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler) Handler(io.vertx.core.Handler) SockJSSocket(io.vertx.ext.web.handler.sockjs.SockJSSocket)

Aggregations

Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpServer (io.vertx.core.http.HttpServer)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 LocalMap (io.vertx.core.shareddata.LocalMap)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 BridgeEvent (io.vertx.ext.web.handler.sockjs.BridgeEvent)1 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)1 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)1 SockJSHandlerOptions (io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions)1 SockJSSocket (io.vertx.ext.web.handler.sockjs.SockJSSocket)1 Transport (io.vertx.ext.web.handler.sockjs.Transport)1 MessageDigest (java.security.MessageDigest)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1