use of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method simpValidatorInjected.
@Test
public void simpValidatorInjected() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
SimpAnnotationMethodMessageHandler messageHandler = context.getBean(SimpAnnotationMethodMessageHandler.class);
assertThat(messageHandler.getValidator()).isNotNull();
}
use of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method brokerChannelUsedByAnnotatedMethod.
@Test
public void brokerChannelUsedByAnnotatedMethod() {
ApplicationContext context = loadConfig(SimpleBrokerConfig.class);
TestChannel channel = context.getBean("brokerChannel", TestChannel.class);
SimpAnnotationMethodMessageHandler messageHandler = context.getBean(SimpAnnotationMethodMessageHandler.class);
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setSessionId("sess1");
headers.setSessionAttributes(new ConcurrentHashMap<>());
headers.setDestination("/foo");
Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
messageHandler.handleMessage(message);
message = channel.messages.get(0);
headers = StompHeaderAccessor.wrap(message);
assertThat(headers.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
assertThat(headers.getDestination()).isEqualTo("/bar");
assertThat(new String((byte[]) message.getPayload())).isEqualTo("bar");
}
use of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler in project spring-framework by spring-projects.
the class TestValidator method customArgumentAndReturnValueTypes.
@Test
public void customArgumentAndReturnValueTypes() {
loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");
SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
List<HandlerMethodArgumentResolver> customResolvers = handler.getCustomArgumentResolvers();
assertThat(customResolvers.size()).isEqualTo(2);
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(0))).isTrue();
assertThat(handler.getArgumentResolvers().contains(customResolvers.get(1))).isTrue();
List<HandlerMethodReturnValueHandler> customHandlers = handler.getCustomReturnValueHandlers();
assertThat(customHandlers.size()).isEqualTo(2);
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(0))).isTrue();
assertThat(handler.getReturnValueHandlers().contains(customHandlers.get(1))).isTrue();
}
use of org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler in project spring-framework by spring-projects.
the class TestValidator method annotationMethodMessageHandler.
@Test
public void annotationMethodMessageHandler() {
loadBeanDefinitions("websocket-config-broker-simple.xml");
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
assertThat(annotationMethodMessageHandler).isNotNull();
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
assertThat(messageConverter).isNotNull();
assertThat(messageConverter instanceof CompositeMessageConverter).isTrue();
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertThat(compositeMessageConverter).isNotNull();
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertThat(simpMessagingTemplate).isNotNull();
assertThat(simpMessagingTemplate.getUserDestinationPrefix()).isEqualTo("/personal/");
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
Object pathMatcher = handlerAccessor.getPropertyValue("pathMatcher");
String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator");
assertThat(pathSeparator).isEqualTo(".");
}
Aggregations