Skip to content

Websocket connection fails with /websocket Stomp Endpoint [SPR-11058] #15685

@spring-projects-issues

Description

@spring-projects-issues

Gunnar Hillert opened SPR-11058 and commented

With the recommendation typically being to only have one websocket endpoint for an application, it may not make sense to give the websocket endpoint an application-specific moniker. People may just choose to name it /websocket.

That particular name, though, causes issues. The problem is that with an endpoint /websocket the websocket connection fails.

The problem, can be easily recreated with the Portfolio sample application: https://github.com/rstoyanchev/spring-websocket-portfolio

In class WebSocketConfig

@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
@ComponentScan(basePackages="org.springframework.samples")
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry.addEndpoint("/websocket").withSockJS();
	}

change

registry.addEndpoint("/portfolio").withSockJS();

to

registry.addEndpoint("/websocket").withSockJS();

(And change the respective html page to point to the new endpoint.)

With that change the browser console prints the following error:

WebSocket connection to 'ws://localhost:8080/spring-websocket-portfolio/websocket/845/dh8fva7z/websocket' failed: Unexpected response code: 200

The Portfolio application than falls back to long-polling. Interestingly when doing a non-Stomp endpoint (just plain websocket), an endpoint named websocket seems doable.


Affects: 4.0 RC1

Referenced from: commits 2a6c1f7

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions