Able to proxy websocket requests to external services with spring cloud gateway.
Unable to proxy websocket requests to external services with spring cloud gateway.
- Java 11
- Websocat cli websocket tool
-
Open terminal and navigate to
not-working-external-websocket
-
Run gateway service
./mvnw clean spring-boot:run
-
Repeat Step one
-
Attempt to establish websocket connection with this command:
websocat 'ws://localhost:8869/websocket/echo' -H 'Pragma: no-cache' -H 'Origin: http://localhost:8869' -H 'Accept-Language: en-US,en;q=0.9' -H 'Sec-WebSocket-Key: vBAeZp3K1b+6iCx6rQSlew==' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36 OPR/67.0.3575.53' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits' -H 'Cache-Control: no-cache' -H 'Connection: Upgrade' -H 'Sec-WebSocket-Version: 13'
-
Type
foo
and hit enter -
Type
bar
and hit enter
foo
foo
bar
bar
foo
bar
-
Make sure the code with the fix is published to maven local and the
pom.xml
has the correct version with the local changes in theworking-external-websocket
project. -
Open terminal and navigate to
working-external-websocket
-
Run gateway service
./mvnw clean spring-boot:run
-
Repeat Step one
-
Attempt to establish websocket connection with this command:
websocat 'ws://localhost:8870/websocket/echo' -H 'Pragma: no-cache' -H 'Origin: http://localhost:8870' -H 'Accept-Language: en-US,en;q=0.9' -H 'Sec-WebSocket-Key: vBAeZp3K1b+6iCx6rQSlew==' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36 OPR/67.0.3575.53' -H 'Upgrade: websocket' -H 'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits' -H 'Cache-Control: no-cache' -H 'Connection: Upgrade' -H 'Sec-WebSocket-Version: 13'
-
Type
foo
and hit enter -
Type
bar
and hit enter
foo
foo
bar
bar
foo
foo
bar
bar