Java Code Examples for io.vertx.ext.web.handler.sockjs.SockJSSocket#close()
The following examples show how to use
io.vertx.ext.web.handler.sockjs.SockJSSocket#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SockJSTermHandlerImpl.java From vertx-shell with Apache License 2.0 | 6 votes |
@Override public void handle(SockJSSocket socket) { if (termHandler != null) { SockJSTtyConnection conn = new SockJSTtyConnection(charset, vertx.getOrCreateContext(), socket); socket.handler(buf -> conn.writeToDecoder(buf.toString())); socket.endHandler(v -> { Consumer<Void> closeHandler = conn.getCloseHandler(); if (closeHandler != null) { closeHandler.accept(null); } }); termHandler.handle(new TermImpl(vertx, keymap, conn)); } else { socket.close(); } }
Example 2
Source File: SockJSVisitor.java From nubes with Apache License 2.0 | 5 votes |
private void tryToInvoke(Object instance, Method method, SockJSSocket socket, Buffer msg) { try { method.invoke(instance, getParamValues(method, socket, msg)); } catch (Exception e) { LOG.error("Error while handling websocket", e); socket.close(); } }
Example 3
Source File: LoginChainHandler.java From slime with MIT License | 4 votes |
@Override public boolean handle(BridgeEvent event) throws EventBridgeChainException { boolean isHandle = Boolean.FALSE; if(BridgeEventType.SEND == event.type()) { Vertx vertx = VertxHolder.getVertx(); SockJSSocket sockJSSocket = event.socket(); Map<String, Object> rawMessage = event.getRawMessage().getMap(); String replyAddress = (String) rawMessage.get("replyAddress"); String address = (String) rawMessage.get("address"); if("vertx.basicauthmanager.login".equals(address)) { @SuppressWarnings("unchecked") Map<String, String> credential = (Map<String, String>) rawMessage.get("body"); String userId = credential.get("username"); //String password = credential.get("password"); if(userId == null || "".equals(userId)) { logger.warn("Connection rejected"); sockJSSocket.close(); throw new EventBridgeChainException(true, "No user attached"); } else { boolean exists = WebSocketSessionHolder.exists(userId); if(exists) { throw new EventBridgeChainException(true, "User already registered"); } sockJSSocket.headers().set(WebSocketSessionHolder.USER_KEY, userId); requestLogService.logWebSocketConnection(sockJSSocket); WebSocketSessionHolder.add(userId, sockJSSocket); System.out.println(vertx); System.out.println(vertx.eventBus()); System.out.println(userId); RedisSockjsClient.PUBLISH("topic/chat/user", new JsonObject() .put("userId", userId)); // publish there is a new user coming // vertx.eventBus().publish("topic/chat/user", // new JsonObject() // .put("userId", userId)); // get all online and send back to JsonObject json = new JsonObject() .put("type", "login") // optional .put("address", replyAddress) .put("body", new JsonObject() .put("result", true) .put("list", WebSocketSessionHolder.getUsers())); String data = json.toString(); sockJSSocket.write(Buffer.buffer(data)); isHandle = Boolean.TRUE; } } } return isHandle; }