Skip to content

Commit 4fb665d

Browse files
committed
Upgrade to SF 7.0.7
Fix `StompInboundChannelAdapterWebSocketIntegrationTests` for the latest changes in SF for Web Sockets and STOMP
1 parent 66c79e4 commit 4fb665d

2 files changed

Lines changed: 22 additions & 35 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ext {
105105
springGraphqlVersion = '2.0.2'
106106
springKafkaVersion = '4.0.4'
107107
springSecurityVersion = '7.0.5'
108-
springVersion = '7.0.6'
108+
springVersion = '7.0.7'
109109
springWsVersion = '5.0.1'
110110
testcontainersVersion = '2.0.5'
111111
tomcatVersion = '11.0.21'

spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.integration.stomp.inbound;
1818

19-
import java.util.Collections;
19+
import java.util.List;
2020
import java.util.Map;
2121

2222
import org.junit.jupiter.api.Test;
@@ -30,8 +30,6 @@
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.context.annotation.Configuration;
3232
import org.springframework.http.MediaType;
33-
import org.springframework.http.server.ServerHttpRequest;
34-
import org.springframework.http.server.ServerHttpResponse;
3533
import org.springframework.integration.channel.QueueChannel;
3634
import org.springframework.integration.config.EnableIntegration;
3735
import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer;
@@ -62,7 +60,6 @@
6260
import org.springframework.test.context.ContextConfiguration;
6361
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
6462
import org.springframework.util.MultiValueMap;
65-
import org.springframework.web.socket.WebSocketHandler;
6663
import org.springframework.web.socket.WebSocketHttpHeaders;
6764
import org.springframework.web.socket.client.WebSocketClient;
6865
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
@@ -71,9 +68,9 @@
7168
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
7269
import org.springframework.web.socket.messaging.SessionSubscribeEvent;
7370
import org.springframework.web.socket.messaging.WebSocketStompClient;
74-
import org.springframework.web.socket.server.HandshakeInterceptor;
7571
import org.springframework.web.socket.server.standard.StandardWebSocketUpgradeStrategy;
7672
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
73+
import org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport;
7774
import org.springframework.web.socket.sockjs.client.SockJsClient;
7875
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
7976

@@ -229,7 +226,7 @@ private boolean containsDestination(String destination, SubscriptionRegistry sub
229226

230227
// STOMP Client
231228

232-
@Configuration
229+
@Configuration(proxyBeanMethods = false)
233230
@EnableIntegration
234231
public static class ContextConfiguration {
235232

@@ -240,26 +237,30 @@ public TomcatWebSocketTestServer server() {
240237

241238
@Bean
242239
public WebSocketClient webSocketClient() {
243-
return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient())));
240+
return new SockJsClient(List.of(new RestTemplateXhrTransport(),
241+
new WebSocketTransport(new StandardWebSocketClient())));
244242
}
245243

246244
@Bean
247-
public WebSocketStompClient stompClient(
248-
@Qualifier("taskScheduler") TaskScheduler taskScheduler) {
249-
WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient());
245+
public WebSocketStompClient stompClient(@Qualifier("taskScheduler") TaskScheduler taskScheduler,
246+
WebSocketClient webSocketClient) {
247+
248+
WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient);
250249
webSocketStompClient.setMessageConverter(new JacksonJsonMessageConverter());
251250
webSocketStompClient.setTaskScheduler(taskScheduler);
252251
return webSocketStompClient;
253252
}
254253

255254
@Bean
256-
public StompSessionManager stompSessionManager(WebSocketStompClient stompClient) {
255+
public StompSessionManager stompSessionManager(WebSocketStompClient stompClient,
256+
TomcatWebSocketTestServer server) {
257+
257258
WebSocketStompSessionManager webSocketStompSessionManager =
258-
new WebSocketStompSessionManager(stompClient, server().getWsBaseUrl() + "/ws");
259+
new WebSocketStompSessionManager(stompClient, server.getWsBaseUrl() + "/ws");
259260
webSocketStompSessionManager.setAutoReceipt(true);
260261
webSocketStompSessionManager.setRecoveryInterval(1000);
261262
WebSocketHttpHeaders handshakeHeaders = new WebSocketHttpHeaders();
262-
handshakeHeaders.setOrigin("https://www.example.com/");
263+
handshakeHeaders.setOrigin("https://www.example.com");
263264
webSocketStompSessionManager.setHandshakeHeaders(handshakeHeaders);
264265
StompHeaders stompHeaders = new StompHeaders();
265266
stompHeaders.setHeartbeat(new long[] {10000, 10000});
@@ -278,11 +279,13 @@ public PollableChannel errorChannel() {
278279
}
279280

280281
@Bean
281-
public StompInboundChannelAdapter stompInboundChannelAdapter(StompSessionManager stompSessionFactory) {
282+
public StompInboundChannelAdapter stompInboundChannelAdapter(StompSessionManager stompSessionFactory,
283+
PollableChannel stompInputChannel, PollableChannel errorChannel) {
284+
282285
StompInboundChannelAdapter adapter = new StompInboundChannelAdapter(stompSessionFactory, "/topic/myTopic");
283286
adapter.setPayloadType(Map.class);
284-
adapter.setOutputChannel(stompInputChannel());
285-
adapter.setErrorChannel(errorChannel());
287+
adapter.setOutputChannel(stompInputChannel);
288+
adapter.setErrorChannel(errorChannel);
286289
return adapter;
287290
}
288291

@@ -292,10 +295,10 @@ public PollableChannel stompEvents() {
292295
}
293296

294297
@Bean
295-
public ApplicationListener<ApplicationEvent> stompEventListener() {
298+
public ApplicationListener<ApplicationEvent> stompEventListener(PollableChannel stompEvents) {
296299
ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
297300
producer.setEventTypes(StompIntegrationEvent.class);
298-
producer.setOutputChannel(stompEvents());
301+
producer.setOutputChannel(stompEvents);
299302
return producer;
300303
}
301304

@@ -317,22 +320,6 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
317320
registry.addEndpoint("/ws")
318321
.setHandshakeHandler(handshakeHandler())
319322
.setAllowedOrigins("https://www.example.com")
320-
.addInterceptors(new HandshakeInterceptor() {
321-
322-
@Override
323-
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
324-
WebSocketHandler wsHandler, Map<String, Object> attributes) {
325-
326-
return request.getHeaders().getOrigin() != null;
327-
}
328-
329-
@Override
330-
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response,
331-
WebSocketHandler wsHandler, Exception exception) {
332-
333-
}
334-
335-
})
336323
.withSockJS();
337324
}
338325

0 commit comments

Comments
 (0)