INT-4044: Fix WebSocketStompSessionManager API
JIRA: https://jira.spring.io/browse/INT-4044 The wrong method `WebSocketStompClient.connect()` has been used before because of `Object` vararg. * Fix to the proper method invocation * Modify `StompInboundChannelAdapterWebSocketIntegrationTests` with `origin` handshake header to prove the fix
This commit is contained in:
@@ -27,6 +27,8 @@ import org.springframework.web.socket.messaging.WebSocketStompClient;
|
|||||||
* The {@link WebSocketStompClient} based {@link AbstractStompSessionManager} implementation.
|
* The {@link WebSocketStompClient} based {@link AbstractStompSessionManager} implementation.
|
||||||
*
|
*
|
||||||
* @author Artem Bilan
|
* @author Artem Bilan
|
||||||
|
* @author Sean Mills
|
||||||
|
*
|
||||||
* @see WebSocketStompClient
|
* @see WebSocketStompClient
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
@@ -51,8 +53,8 @@ public class WebSocketStompSessionManager extends AbstractStompSessionManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
|
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
|
||||||
return ((WebSocketStompClient) this.stompClient).connect(this.url, handler, this.handshakeHeaders,
|
return ((WebSocketStompClient) this.stompClient).connect(this.url, this.handshakeHeaders, getConnectHeaders(),
|
||||||
getConnectHeaders(), this.uriVariables);
|
handler, this.uriVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
import org.springframework.integration.channel.QueueChannel;
|
import org.springframework.integration.channel.QueueChannel;
|
||||||
import org.springframework.integration.config.EnableIntegration;
|
import org.springframework.integration.config.EnableIntegration;
|
||||||
import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer;
|
import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer;
|
||||||
@@ -70,6 +72,8 @@ import org.springframework.test.annotation.DirtiesContext;
|
|||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.WebSocketHttpHeaders;
|
||||||
import org.springframework.web.socket.client.WebSocketClient;
|
import org.springframework.web.socket.client.WebSocketClient;
|
||||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
||||||
@@ -77,6 +81,7 @@ import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBr
|
|||||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||||
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
|
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
|
||||||
import org.springframework.web.socket.messaging.WebSocketStompClient;
|
import org.springframework.web.socket.messaging.WebSocketStompClient;
|
||||||
|
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||||
import org.springframework.web.socket.sockjs.client.SockJsClient;
|
import org.springframework.web.socket.sockjs.client.SockJsClient;
|
||||||
@@ -264,6 +269,9 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju
|
|||||||
new WebSocketStompSessionManager(stompClient, server().getWsBaseUrl() + "/ws");
|
new WebSocketStompSessionManager(stompClient, server().getWsBaseUrl() + "/ws");
|
||||||
webSocketStompSessionManager.setAutoReceipt(true);
|
webSocketStompSessionManager.setAutoReceipt(true);
|
||||||
webSocketStompSessionManager.setRecoveryInterval(1000);
|
webSocketStompSessionManager.setRecoveryInterval(1000);
|
||||||
|
WebSocketHttpHeaders handshakeHeaders = new WebSocketHttpHeaders();
|
||||||
|
handshakeHeaders.setOrigin("http://foo.com");
|
||||||
|
webSocketStompSessionManager.setHandshakeHeaders(handshakeHeaders);
|
||||||
StompHeaders stompHeaders = new StompHeaders();
|
StompHeaders stompHeaders = new StompHeaders();
|
||||||
stompHeaders.setHeartbeat(new long[] {10000, 10000});
|
stompHeaders.setHeartbeat(new long[] {10000, 10000});
|
||||||
webSocketStompSessionManager.setConnectHeaders(stompHeaders);
|
webSocketStompSessionManager.setConnectHeaders(stompHeaders);
|
||||||
@@ -318,13 +326,31 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||||
registry.addEndpoint("/ws").setHandshakeHandler(handshakeHandler()).withSockJS();
|
registry.addEndpoint("/ws")
|
||||||
|
.setHandshakeHandler(handshakeHandler())
|
||||||
|
.setAllowedOrigins("http://foo.com")
|
||||||
|
.addInterceptors(new HandshakeInterceptor() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
|
||||||
|
WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||||
|
return request.getHeaders().getOrigin() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response,
|
||||||
|
WebSocketHandler wsHandler, Exception exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.withSockJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureMessageBroker(MessageBrokerRegistry configurer) {
|
public void configureMessageBroker(MessageBrokerRegistry configurer) {
|
||||||
configurer.setApplicationDestinationPrefixes("/app");
|
configurer.setApplicationDestinationPrefixes("/app")
|
||||||
configurer.enableSimpleBroker("/topic", "/queue");
|
.enableSimpleBroker("/topic", "/queue");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way
|
//TODO SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way
|
||||||
|
|||||||
Reference in New Issue
Block a user