下面列出了org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor#org.springframework.messaging.converter.StringMessageConverter 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);
Method method = this.getClass().getDeclaredMethod("getData");
this.subscribeEventReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getDataAndSendTo");
this.subscribeEventSendToReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handle");
this.messageMappingReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getJsonView");
this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
int port = SocketUtils.findAvailableTcpPort(61613);
this.activeMQBroker = new BrokerService();
this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
this.activeMQBroker.setStartAsync(false);
this.activeMQBroker.setPersistent(false);
this.activeMQBroker.setUseJmx(false);
this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.start();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
this.client = new ReactorNettyTcpStompClient("127.0.0.1", port);
this.client.setMessageConverter(new StringMessageConverter());
this.client.setTaskScheduler(taskScheduler);
}
@Test
public void configureMessageConvertersCustomAndDefault() {
final MessageConverter testConverter = mock(MessageConverter.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
messageConverters.add(testConverter);
return true;
}
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
@Before
public void setup() throws Exception {
this.resolver = new PayloadMethodArgumentResolver(new StringMessageConverter(), testValidator());
Method payloadMethod = PayloadMethodArgumentResolverTests.class.getDeclaredMethod(
"handleMessage", String.class, String.class, Locale.class,
String.class, String.class, String.class, String.class);
this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0);
this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1);
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
this.wac = new AnnotationConfigWebApplicationContext();
this.wac.register(TestConfig.class);
this.wac.refresh();
this.server = new TomcatWebSocketTestServer();
this.server.setup();
this.server.deployConfig(this.wac);
this.server.start();
WebSocketClient webSocketClient = new StandardWebSocketClient();
this.stompClient = new WebSocketStompClient(webSocketClient);
this.stompClient.setMessageConverter(new StringMessageConverter());
}
@Before
public void before() throws Exception {
log.info("=============================={}.{}==============================",
this.getClass().getSimpleName(),
this.testName.getMethodName());
String brokerStomp = "ws://localhost:" + this.listenPort + "/weevent-broker/stomp";
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
this.stompClient = new WebSocketStompClient(new StandardWebSocketClient());
// MappingJackson2MessageConverter
stompClient.setMessageConverter(new StringMessageConverter());
stompClient.setTaskScheduler(taskScheduler); // for heartbeats
this.header.setDestination(topic);
this.header.set("eventId", WeEvent.OFFSET_LAST);
this.header.set("groupId", WeEvent.DEFAULT_GROUP_ID);
this.failure = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
this.stompSession = this.stompClient.connect(brokerStomp, new MyStompSessionHandler(latch, this.failure)).get();
latch.await();
this.stompSession.setAutoReceipt(true);
}
/**
* Create an instance of SimpAnnotationMethodMessageHandler with the given
* message channels and broker messaging template.
* @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
* @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
* @param brokerTemplate a messaging template to send application messages to the broker
*/
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {
Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
Assert.notNull(brokerTemplate, "brokerTemplate must not be null");
this.clientInboundChannel = clientInboundChannel;
this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
this.brokerTemplate = brokerTemplate;
Collection<MessageConverter> converters = new ArrayList<>();
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
this.messageConverter = new CompositeMessageConverter(converters);
}
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);
Method method = this.getClass().getDeclaredMethod("getData");
this.subscribeEventReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getDataAndSendTo");
this.subscribeEventSendToReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handle");
this.messageMappingReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getJsonView");
this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
int port = SocketUtils.findAvailableTcpPort(61613);
this.activeMQBroker = new BrokerService();
this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
this.activeMQBroker.setStartAsync(false);
this.activeMQBroker.setPersistent(false);
this.activeMQBroker.setUseJmx(false);
this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.start();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
this.client = new ReactorNettyTcpStompClient("127.0.0.1", port);
this.client.setMessageConverter(new StringMessageConverter());
this.client.setTaskScheduler(taskScheduler);
}
@Test
public void configureMessageConvertersCustomAndDefault() {
final MessageConverter testConverter = mock(MessageConverter.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
messageConverters.add(testConverter);
return true;
}
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
@Before
public void setup() throws Exception {
this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator());
Method payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod(
"handleMessage", String.class, String.class, Locale.class,
String.class, String.class, String.class, String.class);
this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0);
this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1);
this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
this.wac = new AnnotationConfigWebApplicationContext();
this.wac.register(TestConfig.class);
this.wac.refresh();
this.server = new TomcatWebSocketTestServer();
this.server.setup();
this.server.deployConfig(this.wac);
this.server.start();
WebSocketClient webSocketClient = new StandardWebSocketClient();
this.stompClient = new WebSocketStompClient(webSocketClient);
this.stompClient.setMessageConverter(new StringMessageConverter());
}
public RocketMQMessageConverter() {
List<MessageConverter> messageConverters = new ArrayList<>();
ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter();
byteArrayMessageConverter.setContentTypeResolver(null);
messageConverters.add(byteArrayMessageConverter);
messageConverters.add(new StringMessageConverter());
if (JACKSON_PRESENT) {
messageConverters.add(new MappingJackson2MessageConverter());
}
if (FASTJSON_PRESENT) {
try {
messageConverters.add(
(MessageConverter)ClassUtils.forName(
"com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter",
ClassUtils.getDefaultClassLoader()).newInstance());
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
//ignore this exception
}
}
messageConverter = new CompositeMessageConverter(messageConverters);
}
/**
* Create an instance of SimpAnnotationMethodMessageHandler with the given
* message channels and broker messaging template.
* @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
* @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
* @param brokerTemplate a messaging template to send application messages to the broker
*/
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {
Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
Assert.notNull(brokerTemplate, "brokerTemplate must not be null");
this.clientInboundChannel = clientInboundChannel;
this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
this.brokerTemplate = brokerTemplate;
Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
this.messageConverter = new CompositeMessageConverter(converters);
}
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
messagingTemplate.setMessageConverter(new StringMessageConverter());
this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);
SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);
Method method = this.getClass().getDeclaredMethod("getData");
this.subscribeEventReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getDataAndSendTo");
this.subscribeEventSendToReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("handle");
this.messageMappingReturnType = new MethodParameter(method, -1);
method = this.getClass().getDeclaredMethod("getJsonView");
this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
int port = SocketUtils.findAvailableTcpPort(61613);
this.activeMQBroker = new BrokerService();
this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
this.activeMQBroker.setStartAsync(false);
this.activeMQBroker.setPersistent(false);
this.activeMQBroker.setUseJmx(false);
this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
this.activeMQBroker.start();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
this.client = new Reactor2TcpStompClient("127.0.0.1", port);
this.client.setMessageConverter(new StringMessageConverter());
this.client.setTaskScheduler(taskScheduler);
}
@Test
public void configureMessageConvertersCustomAndDefault() {
final MessageConverter testConverter = mock(MessageConverter.class);
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
@Override
protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
messageConverters.add(testConverter);
return true;
}
};
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
assertThat(iterator.next(), Matchers.is(testConverter));
assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
@Before
public void setUp() throws Exception {
logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
this.wac = new AnnotationConfigWebApplicationContext();
this.wac.register(TestConfig.class);
this.wac.refresh();
this.server = new TomcatWebSocketTestServer();
this.server.setup();
this.server.deployConfig(this.wac);
this.server.start();
WebSocketClient webSocketClient = new StandardWebSocketClient();
this.stompClient = new WebSocketStompClient(webSocketClient);
this.stompClient.setMessageConverter(new StringMessageConverter());
}
@Override
protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
getCustomArgumentResolvers());
resolvers.add(new HeaderMethodArgumentResolver(null, null));
resolvers.add(new SqsHeadersMethodArgumentResolver());
resolvers.add(new NotificationSubjectArgumentResolver());
resolvers.add(new AcknowledgmentHandlerMethodArgumentResolver(ACKNOWLEDGMENT));
resolvers.add(new VisibilityHandlerMethodArgumentResolver(VISIBILITY));
CompositeMessageConverter compositeMessageConverter = createPayloadArgumentCompositeConverter();
resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter));
resolvers.add(new MessageMethodArgumentResolver(
this.messageConverters.isEmpty() ? new StringMessageConverter()
: new CompositeMessageConverter(this.messageConverters)));
resolvers.add(new PayloadArgumentResolver(compositeMessageConverter,
new NoOpValidator()));
return resolvers;
}
protected void initMessageConverter(MessageConverter messageConverter) {
StringMessageConverter stringMessageConverter = new StringMessageConverter();
stringMessageConverter.setSerializedPayloadClass(String.class);
List<MessageConverter> messageConverters = new ArrayList<>();
messageConverters.add(stringMessageConverter);
if (messageConverter != null) {
messageConverters.add(messageConverter);
}
else {
MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
messageConverters.add(mappingJackson2MessageConverter);
}
setMessageConverter(new CompositeMessageConverter(messageConverters));
}
@Test
void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception {
// Arrange
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
jsonObject.put("Type", "Notification");
jsonObject.put("Subject", "Hello");
jsonObject.put("Message", "World");
String payload = jsonObject.toString();
// Act
Object notificationRequest = new NotificationRequestConverter(
new StringMessageConverter()).fromMessage(
MessageBuilder.withPayload(payload).build(), String.class);
// Assert
assertThat(NotificationRequestConverter.NotificationRequest.class
.isInstance(notificationRequest)).isTrue();
assertThat(
((NotificationRequestConverter.NotificationRequest) notificationRequest)
.getSubject()).isEqualTo("Hello");
assertThat(
((NotificationRequestConverter.NotificationRequest) notificationRequest)
.getMessage()).isEqualTo("World");
}
@Test
void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception {
// Arrange
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
jsonObject.put("Type", "Notification");
jsonObject.put("Message", "World");
String payload = jsonObject.toString();
// Act
Object notificationRequest = new NotificationRequestConverter(
new StringMessageConverter()).fromMessage(
MessageBuilder.withPayload(payload).build(), String.class);
// Assert
assertThat(NotificationRequestConverter.NotificationRequest.class
.isInstance(notificationRequest)).isTrue();
assertThat(
((NotificationRequestConverter.NotificationRequest) notificationRequest)
.getMessage()).isEqualTo("World");
}
@Test
void fromMessage_withNumberAttribute_shouldReturnMessage() throws Exception {
// Arrange
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
jsonObject.put("Type", "Notification");
jsonObject.put("Message", "World");
ObjectNode messageAttributes = JsonNodeFactory.instance.objectNode();
messageAttributes.set("number-attribute", JsonNodeFactory.instance.objectNode()
.put("Value", "30").put("Type", "Number.long"));
jsonObject.set("MessageAttributes", messageAttributes);
String payload = jsonObject.toString();
// Act
Object notificationRequest = new NotificationRequestConverter(
new StringMessageConverter()).fromMessage(
MessageBuilder.withPayload(payload).build(), String.class);
// Assert
assertThat(notificationRequest).isNotNull();
}
@Test
void testWrongTypeSupplied() throws Exception {
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
jsonObject.put("Type", "Subscription");
jsonObject.put("Message", "Hello World!");
String payload = jsonObject.toString();
assertThatThrownBy(
() -> new NotificationRequestConverter(new StringMessageConverter())
.fromMessage(MessageBuilder.withPayload(payload).build(),
String.class))
.isInstanceOf(MessageConversionException.class)
.hasMessageContaining(
"is not a valid notification");
}
@Test
void supportsParameter_withNotificationMessageMethodParameter_shouldReturnTrue()
throws Exception {
// Arrange
NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
new StringMessageConverter());
Method methodWithNotificationMessageArgument = this.getClass()
.getDeclaredMethod("methodWithNotificationMessageArgument", String.class);
MethodParameter methodParameter = new MethodParameter(
methodWithNotificationMessageArgument, 0);
// Act
boolean result = notificationMessageArgumentResolver
.supportsParameter(methodParameter);
// Assert
assertThat(result).isTrue();
}
@Test
void supportsParameter_withWrongMethodParameter_shouldReturnFalse() throws Exception {
// Arrange
NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
new StringMessageConverter());
Method methodWithMissingAnnotation = this.getClass()
.getDeclaredMethod("methodWithMissingAnnotation", String.class);
MethodParameter methodParameter = new MethodParameter(methodWithMissingAnnotation,
0);
// Act
boolean result = notificationMessageArgumentResolver
.supportsParameter(methodParameter);
// Assert
assertThat(result).isFalse();
}
@Test
void supportsParameter_withNonStringParameterType_shouldReturnTrue()
throws Exception {
// Arrange
NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
new StringMessageConverter());
Method methodWithWrongParameterType = this.getClass()
.getDeclaredMethod("methodWithWrongParameterType", Long.class);
MethodParameter methodParameter = new MethodParameter(
methodWithWrongParameterType, 0);
// Act
boolean result = notificationMessageArgumentResolver
.supportsParameter(methodParameter);
// Assert
assertThat(result).isTrue();
}
@Test
void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage()
throws Exception {
// Arrange
NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
new StringMessageConverter());
Method methodWithNotificationMessageArgument = this.getClass()
.getDeclaredMethod("methodWithNotificationMessageArgument", String.class);
MethodParameter methodParameter = new MethodParameter(
methodWithNotificationMessageArgument, 0);
ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
jsonObject.put("Type", "Notification");
jsonObject.put("Message", "Hello World!");
String payload = jsonObject.toString();
Message<String> message = MessageBuilder.withPayload(payload).build();
// Act
Object result = notificationMessageArgumentResolver
.resolveArgument(methodParameter, message);
// Assert
assertThat(String.class.isInstance(result)).isTrue();
assertThat(result).isEqualTo("Hello World!");
}
private List<MessageConverter> getMessageConverters(
boolean addDefault, List<MessageConverter> messageConverters) {
List<MessageConverter> messageConverterList = new ArrayList<>();
StringMessageConverter stringMessageConverter = new StringMessageConverter();
stringMessageConverter.setSerializedPayloadClass(String.class);
messageConverterList.add(stringMessageConverter);
if (addDefault) {
messageConverterList.add(new GenericMessageConverter());
}
messageConverterList.addAll(messageConverters);
return messageConverterList;
}
/**
* Create an instance of SimpAnnotationMethodMessageHandler with the given
* message channels and broker messaging template.
* @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
* @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
* @param brokerTemplate a messaging template to send application messages to the broker
*/
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {
Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
Assert.notNull(brokerTemplate, "brokerTemplate must not be null");
this.clientInboundChannel = clientInboundChannel;
this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
this.brokerTemplate = brokerTemplate;
Collection<MessageConverter> converters = new ArrayList<>();
converters.add(new StringMessageConverter());
converters.add(new ByteArrayMessageConverter());
this.messageConverter = new CompositeMessageConverter(converters);
}