private boolean checkMaxHandlers(SockJSSocket sock, SockInfo info) { if (info.handlerCount < maxHandlersPerSocket) { return true; } else { log.warn("Refusing to register as max_handlers_per_socket reached already"); replyError(sock, "max_handlers_reached"); return false; } }
private void internalHandleSendOrPub(SockJSSocket sock, boolean send, JsonObject msg) { checkCallHook(() -> new BridgeEventImpl(send ? BridgeEventType.SEND : BridgeEventType.PUBLISH, msg, sock), () -> { String address = msg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } doSendOrPub(send, sock, address, msg); }, () -> replyError(sock, "rejected")); }
private void internalHandleUnregister(SockJSSocket sock, JsonObject rawMsg, Map<String, MessageConsumer> registrations) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.UNREGISTER, rawMsg, sock), () -> { String address = rawMsg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } Match match = checkMatches(false, address, null); if (match.doesMatch) { MessageConsumer reg = registrations.remove(address); if (reg != null) { reg.unregister(); SockInfo info = sockInfos.get(sock); info.handlerCount--; } } else { if (log.isDebugEnabled()) { log.debug("Cannot unregister handler for address " + address + " because there is no inbound match"); } replyError(sock, "access_denied"); } }, () -> replyError(sock, "rejected")); }
msg = new JsonObject(data.toString()); } catch (DecodeException e) { replyError(sock, "invalid_json"); return; replyError(sock, "missing_type"); return; String address = msg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; default: log.error("Invalid type in incoming message: " + type); replyError(sock, "invalid_type");
replyError(sock, "invalid_reply_address"); return; checkAndSend(send, address, body, headers, sock, replyAddress, null); } else { replyError(sock, "access_denied"); if (debug) { log.debug("Inbound message for address " + address + " rejected because is not authorised"); replyError(sock, "auth_error"); log.error("Error in performing authorisation", res.cause()); } else { replyError(sock, "not_logged_in"); if (debug) { log.debug("Inbound message for address " + address + replyError(sock, "access_denied"); if (debug) { log.debug("Inbound message for address " + address + " rejected because there is no match");
final String address = rawMsg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } else if (address.length() > maxAddressLength) { log.warn("Refusing to register as address length > max_address_length"); replyError(sock, "max_address_length_reached"); return; log.debug("Cannot register handler for address " + address + " because there is no inbound match"); replyError(sock, "access_denied"); }, () -> replyError(sock, "rejected"));
public void handle(final SockJSSocket sock) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_CREATED, null, sock), () -> { Map<String, MessageConsumer> registrations = new HashMap<>(); sock.endHandler(v -> handleSocketClosed(sock, registrations)); sock.handler(data -> handleSocketData(sock, data, registrations)); // Start a checker to check for pings PingInfo pingInfo = new PingInfo(); pingInfo.timerID = vertx.setPeriodic(pingTimeout, id -> { if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout) { // Trigger an event to allow custom behavior before disconnecting client. checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_IDLE, null, sock), // We didn't receive a ping in time so close the socket ((SockJSSocketBase) sock)::closeAfterSessionExpired, () -> replyError(sock, "rejected")); } }); SockInfo sockInfo = new SockInfo(); sockInfo.pingInfo = pingInfo; sockInfos.put(sock, sockInfo); }, sock::close); }
private boolean checkMaxHandlers(SockJSSocket sock, SockInfo info) { if (info.handlerCount < maxHandlersPerSocket) { return true; } else { log.warn("Refusing to register as max_handlers_per_socket reached already"); replyError(sock, "max_handlers_reached"); return false; } }
private void internalHandleSendOrPub(SockJSSocket sock, boolean send, JsonObject msg) { checkCallHook(() -> new BridgeEventImpl(send ? BridgeEventType.SEND : BridgeEventType.PUBLISH, msg, sock), () -> { String address = msg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } doSendOrPub(send, sock, address, msg); }, () -> replyError(sock, "rejected")); }
private void internalHandleUnregister(SockJSSocket sock, JsonObject rawMsg, Map<String, MessageConsumer> registrations) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.UNREGISTER, rawMsg, sock), () -> { String address = rawMsg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } Match match = checkMatches(false, address, null); if (match.doesMatch) { MessageConsumer reg = registrations.remove(address); if (reg != null) { reg.unregister(); SockInfo info = sockInfos.get(sock); info.handlerCount--; } } else { if (log.isDebugEnabled()) { log.debug("Cannot unregister handler for address " + address + " because there is no inbound match"); } replyError(sock, "access_denied"); } }, () -> replyError(sock, "rejected")); }
msg = new JsonObject(data.toString()); } catch (DecodeException e) { replyError(sock, "invalid_json"); return; replyError(sock, "missing_type"); return; String address = msg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; default: log.error("Invalid type in incoming message: " + type); replyError(sock, "invalid_type");
replyError(sock, "invalid_reply_address"); return; checkAndSend(send, address, body, headers, sock, replyAddress, null); } else { replyError(sock, "access_denied"); if (debug) { log.debug("Inbound message for address " + address + " rejected because is not authorised"); replyError(sock, "auth_error"); log.error("Error in performing authorisation", res.cause()); } else { replyError(sock, "not_logged_in"); if (debug) { log.debug("Inbound message for address " + address + replyError(sock, "access_denied"); if (debug) { log.debug("Inbound message for address " + address + " rejected because there is no match");
final String address = rawMsg.getString("address"); if (address == null) { replyError(sock, "missing_address"); return; } else if (address.length() > maxAddressLength) { log.warn("Refusing to register as address length > max_address_length"); replyError(sock, "max_address_length_reached"); return; log.debug("Cannot register handler for address " + address + " because there is no inbound match"); replyError(sock, "access_denied"); }, () -> replyError(sock, "rejected"));
public void handle(final SockJSSocket sock) { checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_CREATED, null, sock), () -> { Map<String, MessageConsumer> registrations = new HashMap<>(); sock.endHandler(v -> handleSocketClosed(sock, registrations)); sock.handler(data -> handleSocketData(sock, data, registrations)); // Start a checker to check for pings PingInfo pingInfo = new PingInfo(); pingInfo.timerID = vertx.setPeriodic(pingTimeout, id -> { if (System.currentTimeMillis() - pingInfo.lastPing >= pingTimeout) { // Trigger an event to allow custom behavior before disconnecting client. checkCallHook(() -> new BridgeEventImpl(BridgeEventType.SOCKET_IDLE, null, sock), // We didn't receive a ping in time so close the socket ((SockJSSocketBase) sock)::closeAfterSessionExpired, () -> replyError(sock, "rejected")); } }); SockInfo sockInfo = new SockInfo(); sockInfo.pingInfo = pingInfo; sockInfos.put(sock, sockInfo); }, sock::close); }