private void testReject(WebsocketVersion version, Integer rejectionStatus, int expectedRejectionStatus) throws Exception { String path = "/some/path"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { assertEquals(path, ws.path()); if (rejectionStatus != null) { ws.reject(rejectionStatus); } else { ws.reject(); } }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version). exceptionHandler(t -> { assertTrue(t instanceof WebsocketRejectedException); assertEquals(expectedRejectionStatus, ((WebsocketRejectedException)t).getStatus()); testComplete(); }). handler(ws -> fail("Should not be called")); }); await(); }
/** * Like {@link io.vertx.rxjava.core.http.ServerWebSocket#reject} but with a <code>status</code>. * @param status */ public void reject(int status) { delegate.reject(status); }
/** * Like {@link io.vertx.rxjava.core.http.ServerWebSocket#reject} but with a <code>status</code>. * @param status */ public void reject(int status) { delegate.reject(status); }
/** * Reject the WebSocket. * <p> * Calling this method from the websocket handler when it is first passed to you gives you the opportunity to reject * the websocket, which will cause the websocket handshake to fail by returning * a response code. * <p> * You might use this method, if for example you only want to accept WebSockets with a particular path. */ public void reject() { delegate.reject(); }
/** * Reject the WebSocket. * <p> * Calling this method from the websocket handler when it is first passed to you gives you the opportunity to reject * the websocket, which will cause the websocket handshake to fail by returning * a response code. * <p> * You might use this method, if for example you only want to accept WebSockets with a particular path. */ public void reject() { delegate.reject(); }
private void testReject(WebsocketVersion version, Integer rejectionStatus, int expectedRejectionStatus) throws Exception { String path = "/some/path"; server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).websocketHandler(ws -> { assertEquals(path, ws.path()); if (rejectionStatus != null) { ws.reject(rejectionStatus); } else { ws.reject(); } }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocketStream(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version). exceptionHandler(t -> { assertTrue(t instanceof WebsocketRejectedException); assertEquals(expectedRejectionStatus, ((WebsocketRejectedException)t).getStatus()); testComplete(); }). handler(ws -> fail("Should not be called")); }); await(); }
noMatchHandler.handle(new Match(null, ws)); } else { ws.reject();
@Override public void start() throws Exception { vertx.createHttpServer() .requestHandler(req -> { req.response().end(); }) .websocketHandler(ws -> { if (ws.path().equals("/leaderboard")) { onLeaderBoard(ws); } else if (ws.path().equals("/scoreboard")) { onScoreBoard(ws); } else { ws.reject(); } }).listen(config().getInteger("boardPort", 9004), ar -> { System.out.println("Boards HTTP server started on port " + ar.result().actualPort()); }); }
@Override public void start() throws Exception { httpServer = vertx.createHttpServer(); httpServer .websocketHandler(websocketHandler -> { if (!websocketHandler.path().equals("/vertx/hot")) { websocketHandler.reject(); return; } MessageConsumer<JsonObject> consumer = vertx.eventBus().consumer(TOPIC); consumer.handler(m -> websocketHandler.writeFinalTextFrame(m.body().toString())); websocketHandler.closeHandler((v) -> consumer.unregister()); } ) .listen(notificationPort); logger.info("notification websocket started on: http://localhost:{}", notificationPort); }
default: LOGGER.warn(format("Connection to web socket %1$s not supported", ws.path())); ws.reject();
break; default: socket.reject();
LOGGER.error("Receiving a web socket connection on an invalid path (" + socket.path() + "), the path is " + "configured to " + options.getWebsocketPath() + ". Rejecting connection"); socket.reject(); return;