I am trying to register websocket dynamically.For instance, i have registered '/sampleEndpoint' at runtime so ServerWebSocketContainer will register it and start publishing data on that endpoint. But now if i do the same process during application initialization time in PostConstruct than i am unable to connect to '/sampleEndpoint' but have to append '/websocket' at the end so url become '/sampleEndpoint/websocket' when connecting from client side. Why we are getting different endpoints at different situations?
I have attached github url to the code.
Well, that's how that SockJS option works: https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#websocket-fallback.
If you client is not SockJS, then you have to add that /websocket
sub-path.
Not sure though why it doesn't work for dynamically registered endpoints...
In the case of @PostConstruct
it is not dynamic: we still do the stuff within configuration phase of the application context, so it is able to add our endpoint into a static HandlerMapping
. The dynamic nature is applied a bit later, when all the @PostConstruct
have done their logic. You don't need to start that flow registration manually though since the auto-startup phase has not passed yet withing @PostConstruct
handling.
Re. IntegrationDynamicWebSocketHandlerMapping
: it sounds more like a bug and I need to investigate more. I guess you still use there that SockJS option and it has to be applied for dynamic endpoint as well.
Thank you for your patience! I'll investigate and fix it ASAP.
UPDATE
The fix is here: https://github.com/spring-projects/spring-integration/pull/3581.