|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012-2023 the original author or authors. |
|
|
|
* Copyright 2012-2024 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure.websocket.servlet; |
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
@ -35,6 +37,7 @@ import org.skyscreamer.jsonassert.JSONAssert; |
|
|
|
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor; |
|
|
|
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor; |
|
|
|
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; |
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; |
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; |
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
|
|
@ -43,10 +46,14 @@ import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactor |
|
|
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; |
|
|
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; |
|
|
|
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.core.task.AsyncTaskExecutor; |
|
|
|
|
|
|
|
import org.springframework.core.task.SimpleAsyncTaskExecutor; |
|
|
|
|
|
|
|
import org.springframework.core.task.TaskExecutor; |
|
|
|
import org.springframework.messaging.converter.CompositeMessageConverter; |
|
|
|
import org.springframework.messaging.converter.CompositeMessageConverter; |
|
|
|
import org.springframework.messaging.converter.MessageConverter; |
|
|
|
import org.springframework.messaging.converter.MessageConverter; |
|
|
|
import org.springframework.messaging.converter.SimpleMessageConverter; |
|
|
|
import org.springframework.messaging.converter.SimpleMessageConverter; |
|
|
|
import org.springframework.messaging.simp.annotation.SubscribeMapping; |
|
|
|
import org.springframework.messaging.simp.annotation.SubscribeMapping; |
|
|
|
|
|
|
|
import org.springframework.messaging.simp.config.ChannelRegistration; |
|
|
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
|
|
|
import org.springframework.messaging.simp.config.MessageBrokerRegistry; |
|
|
|
import org.springframework.messaging.simp.stomp.StompCommand; |
|
|
|
import org.springframework.messaging.simp.stomp.StompCommand; |
|
|
|
import org.springframework.messaging.simp.stomp.StompFrameHandler; |
|
|
|
import org.springframework.messaging.simp.stomp.StompFrameHandler; |
|
|
|
@ -54,6 +61,7 @@ import org.springframework.messaging.simp.stomp.StompHeaders; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSession; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSession; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSessionHandler; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSessionHandler; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; |
|
|
|
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; |
|
|
|
|
|
|
|
import org.springframework.security.util.FieldUtils; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.socket.client.standard.StandardWebSocketClient; |
|
|
|
import org.springframework.web.socket.client.standard.StandardWebSocketClient; |
|
|
|
@ -75,6 +83,7 @@ import static org.assertj.core.api.Assertions.fail; |
|
|
|
* Tests for {@link WebSocketMessagingAutoConfiguration}. |
|
|
|
* Tests for {@link WebSocketMessagingAutoConfiguration}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Andy Wilkinson |
|
|
|
* @author Andy Wilkinson |
|
|
|
|
|
|
|
* @author Lasse Wulff |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class WebSocketMessagingAutoConfigurationTests { |
|
|
|
class WebSocketMessagingAutoConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@ -129,10 +138,34 @@ class WebSocketMessagingAutoConfigurationTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void predefinedThreadExecutorIsSelectedForInboundChannel() throws Throwable { |
|
|
|
|
|
|
|
AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
|
|
|
|
|
|
|
ChannelRegistration registration = new ChannelRegistration(); |
|
|
|
|
|
|
|
WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
|
|
|
|
|
|
|
new ObjectMapper(), |
|
|
|
|
|
|
|
Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
|
|
|
|
|
|
|
configuration.configureClientInboundChannel(registration); |
|
|
|
|
|
|
|
TaskExecutor executor = (TaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
|
|
|
|
|
|
|
assertThat(executor).isEqualTo(expectedExecutor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void predefinedThreadExecutorIsSelectedForOutboundChannel() throws Throwable { |
|
|
|
|
|
|
|
AsyncTaskExecutor expectedExecutor = new SimpleAsyncTaskExecutor(); |
|
|
|
|
|
|
|
ChannelRegistration registration = new ChannelRegistration(); |
|
|
|
|
|
|
|
WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
|
|
|
|
|
|
|
new ObjectMapper(), |
|
|
|
|
|
|
|
Map.of(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME, expectedExecutor)); |
|
|
|
|
|
|
|
configuration.configureClientOutboundChannel(registration); |
|
|
|
|
|
|
|
TaskExecutor executor = (TaskExecutor) FieldUtils.getFieldValue(registration, "executor"); |
|
|
|
|
|
|
|
assertThat(executor).isEqualTo(expectedExecutor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<MessageConverter> getCustomizedConverters() { |
|
|
|
private List<MessageConverter> getCustomizedConverters() { |
|
|
|
List<MessageConverter> customizedConverters = new ArrayList<>(); |
|
|
|
List<MessageConverter> customizedConverters = new ArrayList<>(); |
|
|
|
WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
|
|
|
WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( |
|
|
|
new ObjectMapper()); |
|
|
|
new ObjectMapper(), Collections.emptyMap()); |
|
|
|
configuration.configureMessageConverters(customizedConverters); |
|
|
|
configuration.configureMessageConverters(customizedConverters); |
|
|
|
return customizedConverters; |
|
|
|
return customizedConverters; |
|
|
|
} |
|
|
|
} |
|
|
|
|