I have a micro-services application where I need to use WebSockets for one of the features. The browser connects to the API gateway, which then needs to forward the WebSocket request to the appropriate micro-service. To implement this, Spring's StandardWebSocketClient
is used in the API gateway. The API gateway acts as a proxy for WebSocket requests.
My application uses OAuth for authentication, so when the WebSocket request is proxied in the API gateway, I need to pass on the OAuth2 token as well. When the StandardWebSocketClient
issues the CONNECT
request using Tomcat, I get a BufferOverflowException
, because the bearer token does not seem to fit into the buffer used by Tomcat.
By looking at the Tomcat source code, the buffer size seems to be limited to 4096 bytes. See: https://github.com/apache/tomcat/blob/8fd5d6273099c504e1739080c07cf4d33cff89bf/java/org/apache/tomcat/websocket/WsWebSocketContainer.java#L717
Is there a workaround to overcome this limitation somehow?