-
Sub-task
-
Resolution: Unresolved
-
Major
-
2.17.0.Final
It would be good to be able to add methods to a Websocket Client or Server endpoint with the following command :
websocket-add-method --named processOpen --method ON_OPEN
This would add the processOpen method to the existing server endpoint :
@ServerEndpoint("/abc") public class MyServerEndpoint { @OnOpen public void processOpen(Session session) { }
There are four method type :
- ON_OPEN
- ON_CLOSE
- ON_ERROR
- ON_MESSAGE
The method signature of ON_OPEN, ON_CLOSE and ON_ERROR are set and cannot be changed :
@OnOpen public void onOpen(Session session) { } @OnClose public void onClose(CloseReason closeReason) { } @OnError public void onError(Throwable t) { }
The method signature of ON_MESSAGE can be customized. By default, the message can be of type String. So the following command :
websocket-add-method --named processMsg --method ON_MESSAGE
This would add the processMsg method of type String to the existing server endpoint :
@ServerEndpoint("/abc") public class MyServerEndpoint { @OnMessage public void processMsg(String message, Session client) { }
We could change the type of the message with :
websocket-add-method --named processMsg --method ON_MESSAGE --type MyMessage
This would add the processMsg method of type MyMessage :
@ServerEndpoint("/abc") public class MyServerEndpoint { @OnMessage public void processMsg(MyMessage message, Session client) { }