Search in sources :

Example 6 with StringMessageConverter

use of org.springframework.messaging.converter.StringMessageConverter in project spring-framework by spring-projects.

the class SubscriptionMethodReturnValueHandlerTests method setup.

@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);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) Before(org.junit.Before)

Example 7 with StringMessageConverter

use of org.springframework.messaging.converter.StringMessageConverter in project spring-framework by spring-projects.

the class TestMessagePostProcessor method convertAndSendPayloadAndMutableHeadersToDestination.

@Test
public void convertAndSendPayloadAndMutableHeadersToDestination() {
    MessageHeaderAccessor accessor = new MessageHeaderAccessor();
    accessor.setHeader("foo", "bar");
    accessor.setLeaveMutable(true);
    MessageHeaders messageHeaders = accessor.getMessageHeaders();
    this.template.setMessageConverter(new StringMessageConverter());
    this.template.convertAndSend("somewhere", "payload", messageHeaders);
    MessageHeaders actual = this.template.message.getHeaders();
    assertSame(messageHeaders, actual);
    assertEquals(new MimeType("text", "plain", StandardCharsets.UTF_8), actual.get(MessageHeaders.CONTENT_TYPE));
    assertEquals("bar", actual.get("foo"));
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) MessageHeaders(org.springframework.messaging.MessageHeaders) MimeType(org.springframework.util.MimeType) Test(org.junit.Test)

Example 8 with StringMessageConverter

use of org.springframework.messaging.converter.StringMessageConverter in project spring-framework by spring-projects.

the class PayloadArgumentResolverTests method supportsParameter.

@Test
public void supportsParameter() throws Exception {
    assertTrue(this.resolver.supportsParameter(this.paramAnnotated));
    assertTrue(this.resolver.supportsParameter(this.paramNotAnnotated));
    PayloadArgumentResolver strictResolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator(), false);
    assertTrue(strictResolver.supportsParameter(this.paramAnnotated));
    assertFalse(strictResolver.supportsParameter(this.paramNotAnnotated));
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) Test(org.junit.Test)

Example 9 with StringMessageConverter

use of org.springframework.messaging.converter.StringMessageConverter in project spring-framework by spring-projects.

the class PayloadArgumentResolverTests method setup.

@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);
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) LocalVariableTableParameterNameDiscoverer(org.springframework.core.LocalVariableTableParameterNameDiscoverer) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Method(java.lang.reflect.Method) Before(org.junit.Before)

Aggregations

StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)9 Before (org.junit.Before)6 Method (java.lang.reflect.Method)3 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)3 Test (org.junit.Test)2 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)2 SimpMessagingTemplate (org.springframework.messaging.simp.SimpMessagingTemplate)2 ArrayList (java.util.ArrayList)1 BrokerService (org.apache.activemq.broker.BrokerService)1 Bean (org.springframework.context.annotation.Bean)1 LocalVariableTableParameterNameDiscoverer (org.springframework.core.LocalVariableTableParameterNameDiscoverer)1 MethodParameter (org.springframework.core.MethodParameter)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 ByteArrayMessageConverter (org.springframework.messaging.converter.ByteArrayMessageConverter)1 CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)1 MessageConverter (org.springframework.messaging.converter.MessageConverter)1 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1 MimeType (org.springframework.util.MimeType)1 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)1