I\'m playing around with the new (as of version 4.2) java STOMP client support. My starting point is the getting started guide (Using WebSocket to build an interactive web appl
The following configuration works:
RequestUpgradeStrategy upgradeStrategy = new TomcatRequestUpgradeStrategy();
registry.addEndpoint("/hello")
.withSockJS();
registry.addEndpoint("/hello")
.setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy))
.setAllowedOrigins("*");
Not sure if this is by design (i.e. two endpoints with the same path)?
A better solution based on Brian-Clozel's feedback is to use the java SockJsClient as a transport when configuring the WebSocketStompClient:
List<Transport> transports = new ArrayList<>(1);
transports.add(new WebSocketTransport( new StandardWebSocketClient()) );
WebSocketClient transport = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
which allows the use of only one endpoint to which the java and javascript clients can both connect:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/hello").withSockJS();
}
As stated in the reference documentation: when enabling SockJS, multiple transports are configured for you. First, the client sends a "GET /info"
request to know about supported transports and then sends a request depending on its capabilities:
"http://host:port/myApp/myEndpoint/{server-id}/{session-id}/{transport}"
Now you don't need to duplicate your configuration for you "/hello"
endpoint. You'd rather directly use the websocket endpoint, or better, use the Java SockJS client with a websocket transport. See the complete example in the reference documentation.
You can check the http filter(such as shiro filter) or HandlerInterceptor.