vertx-stomp icon indicating copy to clipboard operation
vertx-stomp copied to clipboard

WebSocket writes are binary only

Open freynder opened this issue 1 year ago • 2 comments

I'm trying to send a JSON payload with websocket transport from server to client. The message is always sent as binary, even though the payload is text. This may cause compatibility issues with other libraries that expect text payloads for content type application/json, such as Krossbow. At least we should be able to specify the desired payload type.

I traced the call stack to StompServerWebSocketConnectionImpl::write which calls socket.writeBinaryMessage, I don't see any possiblity to enforce sending as text.

freynder avatar Apr 11 '23 08:04 freynder

@freynder are you interested in contributing an improvement ?

vietj avatar Apr 11 '23 12:04 vietj

@vietj I'm interested, but looks like this is not a small task and may require core breaking changes as well (to support on the receiving side):

  • receiveFrame function in WebSocketImplBase.java: treats TEXT, BINARY and CONTINUATION types the same, and dispatch only the binary data Buffer to the handler. So we lose the frame type at this point + continuations cannot be aggregated anymore. This should be changed so we aggregate continuations and only send on completion, an object that still contains the type. Do you agree on this?

An alternative is to only concentrate on the sending part. That part should be rather simple and less invasive.

freynder avatar Apr 12 '23 06:04 freynder