barrett-rob / java-websocket-reverse-proxy

Java implementation of a websocket reverse proxy
MIT License
50 stars 13 forks source link

websocket proxy using sprint-boot gets disconnects with error text_partial_writing #2

Open chethankpc opened 3 years ago

chethankpc commented 3 years ago

I am using this web-proxy code to have reverse websocket proxy using spring-boot, it works during initial connection after that I get this below error

I am using this web-proxy code to have reverse websocket proxy using spring-boot, it works during initial connection after that I get this below error

` java.lang.illegalstateexception: the remote endpoint was in state [text_partial_writing] which is an invalid state for called method at

org.apache.tomcat.websocket.wsremoteendpointimplbase$statemachine.checkstate(wsremoteendpointimplbase.java:1234) at org.apache.tomcat.websocket.wsremoteendpointimplbase$statemachine.textpartialstart(wsremoteendpointimplbase.java:1191) at org.apache.tomcat.websocket.wsremoteendpointimplbase.sendpartialstring(wsremoteendpointimplbase.java:222) at org.apache.tomcat.websocket.wsremoteendpointbasic.sendtext(wsremoteendpointbasic.java:49) at org.springframework.web.socket.adapter.standard.standardwebsocketsession.sendtextmessage(standardwebsocketsession.java:215) at org.springframework.web.socket.adapter.abstractwebsocketsession.sendmessage(abstractwebsocketsession.java:106) at com.javainuse.websocket.config.nexthop.sendmessagetonexthop(nexthop.java:61) at com.javainuse.websocket.config.websocketproxyserverhandler.handlemessage(websocketproxyserverhandler.java:33) at org.springframework.web.socket.handler.websockethandlerdecorator.handlemessage(websockethandlerdecorator.java:75) at org.springframework.web.socket.handler.loggingwebsockethandlerdecorator.handlemessage(loggingwebsockethandlerdecorator.java:56) at org.springframework.web.socket.handler.exceptionwebsockethandlerdecorator.handlemessage(exceptionwebsockethandlerdecorator.java:58) at org.springframework.web.socket.adapter.standard.standardwebsockethandleradapter.handletextmessage(standardwebsockethandleradapter.java:114) at org.springframework.web.socket.adapter.standard.standardwebsockethandleradapter.access$000(standardwebsockethandleradapter.java:43) at org.springframework.web.socket.adapter.standard.standardwebsockethandleradapter$3.onmessage(standardwebsockethandleradapter.java:85) at org.springframework.web.socket.adapter.standard.standardwebsockethandleradapter$3.onmessage(standardwebsockethandleradapter.java:82) at org.apache.tomcat.websocket.wsframebase.sendmessagetext(wsframebase.java:395) at org.apache.tomcat.websocket.server.wsframeserver.sendmessagetext(wsframeserver.java:119) `

I added synchronized block here for sendMessage but still getting the same error at this line

Is there a other java websocket proxy code ?

I tried to use spring-cloud-gateway but it is not compatible with spring-starter-web(i can not remove web due to spring MVC dependency in the code)

I added synchronized block sendMessage but still getting the same error at https://github.com/barrett-rob/java-websocket-reverse-proxy/blob/master/src/main/java/com/jwrp/javawebsocketreverseproxy/NextHop.java#L65

Davide-Martins commented 3 years ago

Hello chethankpc!

I have the same issue... Did you manage to solve the problem?

chethankpc commented 3 years ago

I solved using spring-cloud-gateway only, I tweaked my architecture. Now spring cloud gateway is the front service , I have configured the routers based on the urls and protocol

Davide-Martins commented 3 years ago

Yes spring-cloud-gateway is more robust. However I don't have enough time to do that rework.

OK thank you for your response.

Davide-Martins commented 3 years ago

Hello chethankpc!

I'm also tweaking my architecture with spring cloud gateway and everything is working fine except for websockets. Do you have any sample (java code or application.yml) to setup the forwarding of websocket connections? Or in other words, how to configure the routes to make spring cloud gateway acting as a reverse proxy for websockets ?

Thank you in advance for your response.

Davide-Martins commented 3 years ago

OK I think my issue is not in understanding how spring cloud gateway works but rather why my route predicate is not matched.

Thanks anyway.