Java Code Examples for org.springframework.messaging.converter.MappingJackson2MessageConverter

The following examples show how to use org.springframework.messaging.converter.MappingJackson2MessageConverter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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);
}
 
Example 2
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	given(this.brokerChannel.send(any())).willReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 3
@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));
}
 
Example 4
Source Project: WeEvent   Source File: Stomp.java    License: Apache License 2.0 6 votes vote down vote up
private void testOverSockJS() throws InterruptedException {
    // sock js transport
    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());

    SockJsClient sockjsClient = new SockJsClient(transports);
    WebSocketStompClient stompClient = new WebSocketStompClient(sockjsClient);

    // StringMessageConverter
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(taskScheduler); // for heartbeats

    stompClient.connect(brokerSockJS, getSockJSSessionHandlerAdapter());

    Thread.sleep(100000L);
}
 
Example 5
@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);
}
 
Example 6
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 7
@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));
}
 
Example 8
Source Project: rocketmq-spring   Source File: RocketMQMessageConverter.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 9
Source Project: java-specialagent   Source File: SpringWebSocketITest.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public CommandLineRunner commandLineRunner() {
  return new CommandLineRunner() {
    @Override
    public void run(final String ... args) throws Exception {
      final String url = "ws://localhost:8080/test-websocket";

      final WebSocketStompClient stompClient = new WebSocketStompClient(new SockJsClient(createTransportClient()));
      stompClient.setMessageConverter(new MappingJackson2MessageConverter());

      final StompSession stompSession = stompClient.connect(url, new StompSessionHandlerAdapter() {
      }).get(10, TimeUnit.SECONDS);

      stompSession.subscribe(SUBSCRIBE_GREETINGS_ENDPOINT, new GreetingStompFrameHandler());
      stompSession.send(SEND_HELLO_MESSAGE_ENDPOINT, "Hello");
    }
  };
}
 
Example 10
Source Project: spring-boot-websocket-client   Source File: ServiceClient.java    License: MIT License 6 votes vote down vote up
public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);

    new Scanner(System.in).nextLine(); //Don't close immediately.
}
 
Example 11
@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);
}
 
Example 12
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 13
@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));
}
 
Example 14
Source Project: spring-cloud-aws   Source File: SqsConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
public SqsConfiguration(
		ObjectProvider<SimpleMessageListenerContainerFactory> simpleMessageListenerContainerFactory,
		ObjectProvider<QueueMessageHandlerFactory> queueMessageHandlerFactory,
		BeanFactory beanFactory,
		ObjectProvider<ResourceIdResolver> resourceIdResolver,
		ObjectProvider<MappingJackson2MessageConverter> mappingJackson2MessageConverter,
		ObjectProvider<ObjectMapper> objectMapper) {
	this.simpleMessageListenerContainerFactory = simpleMessageListenerContainerFactory
			.getIfAvailable(SimpleMessageListenerContainerFactory::new);
	this.queueMessageHandlerFactory = queueMessageHandlerFactory
			.getIfAvailable(QueueMessageHandlerFactory::new);
	this.beanFactory = beanFactory;
	this.resourceIdResolver = resourceIdResolver.getIfAvailable();
	this.mappingJackson2MessageConverter = mappingJackson2MessageConverter
			.getIfAvailable();
	this.objectMapper = objectMapper.getIfAvailable();
}
 
Example 15
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));
	}
 
Example 16
Source Project: spring-cloud-aws   Source File: QueueMessageHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void receiveMessage_methodWithMessageAsParameter_parameterIsConverted() {
	new ApplicationContextRunner()
			.withConfiguration(UserConfigurations
					.of(QueueMessageHandlerWithJacksonMappingConfiguration.class))
			.withBean(IncomingMessageHandlerWithMessageParameter.class)
			.run((context) -> {
				DummyKeyValueHolder messagePayload = new DummyKeyValueHolder("myKey",
						"A value");
				MappingJackson2MessageConverter jsonMapper = context
						.getBean(MappingJackson2MessageConverter.class);
				Message<?> message = jsonMapper.toMessage(messagePayload,
						new MessageHeaders(Collections.singletonMap(
								QueueMessageHandler.LOGICAL_RESOURCE_ID,
								"testQueue")));

				MessageHandler messageHandler = context.getBean(MessageHandler.class);
				messageHandler.handleMessage(message);

				IncomingMessageHandlerWithMessageParameter messageListener = context
						.getBean(IncomingMessageHandlerWithMessageParameter.class);
				assertThat(messageListener.getLastReceivedMessage()).isNotNull();
				assertThat(messageListener.getLastReceivedMessage().getPayload())
						.isEqualTo(messagePayload);
			});
}
 
Example 17
Source Project: spring-cloud-aws   Source File: SqsConfigurationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void configuration_withObjectMapper_shouldSetObjectMapperOnQueueMessageHandler()
		throws Exception {
	// Arrange & Act
	AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
			ConfigurationWithObjectMapper.class);
	QueueMessageHandler queueMessageHandler = applicationContext
			.getBean(QueueMessageHandler.class);
	ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper.class);
	List<MessageConverter> converters = (List<MessageConverter>) ReflectionTestUtils
			.getField(queueMessageHandler, "messageConverters");
	MappingJackson2MessageConverter mappingJackson2MessageConverter = (MappingJackson2MessageConverter) converters
			.get(0);

	// Assert
	assertThat(mappingJackson2MessageConverter.getObjectMapper())
			.isEqualTo(objectMapper);
}
 
Example 18
protected MappingJackson2MessageConverter createJacksonConverter() {
	DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
	resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
	MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
	converter.setContentTypeResolver(resolver);
	return converter;
}
 
Example 19
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
	this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
}
 
Example 20
@Test
public void configureMessageConvertersDefault() {
	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	List<MessageConverter> converters = compositeConverter.getConverters();
	assertThat(converters.size(), Matchers.is(3));
	assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));

	ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
	assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
}
 
Example 21
@Test // SPR-16486
public void resolveWithJacksonConverter() throws Exception {
	Message<String> inMessage = MessageBuilder.withPayload("{\"foo\":\"bar\"}").build();
	MethodParameter parameter = new MethodParameter(this.method, 5);

	this.resolver = new MessageMethodArgumentResolver(new MappingJackson2MessageConverter());
	Object actual = this.resolver.resolveArgument(parameter, inMessage);

	assertTrue(actual instanceof Message);
	Message<?> outMessage = (Message<?>) actual;
	assertTrue(outMessage.getPayload() instanceof Foo);
	assertEquals("bar", ((Foo) outMessage.getPayload()).getFoo());
}
 
Example 22
Source Project: spring-analysis-note   Source File: MessageSendingTemplateTests.java    License: MIT License 5 votes vote down vote up
@Test(expected = MessageConversionException.class)
public void convertAndSendNoMatchingConverter() {

	MessageConverter converter = new CompositeMessageConverter(
			Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter()));
	this.template.setMessageConverter(converter);

	this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
	this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers));
}
 
Example 23
@Override
protected MappingJackson2MessageConverter createJacksonConverter() {
	MappingJackson2MessageConverter messageConverter = super.createJacksonConverter();
	// Use Jackson builder in order to have JSR-310 and Joda-Time modules registered automatically
	Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
	ApplicationContext applicationContext = getApplicationContext();
	if (applicationContext != null) {
		builder.applicationContext(applicationContext);
	}
	messageConverter.setObjectMapper(builder.build());
	return messageConverter;
}
 
Example 24
private RuntimeBeanReference registerMessageConverter(
		Element element, ParserContext context, @Nullable Object source) {

	Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
	ManagedList<Object> converters = new ManagedList<>();
	if (convertersElement != null) {
		converters.setSource(source);
		for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
			Object object = context.getDelegate().parsePropertySubElement(beanElement, null);
			converters.add(object);
		}
	}
	if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
		converters.setSource(source);
		converters.add(new RootBeanDefinition(StringMessageConverter.class));
		converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));
		if (jackson2Present) {
			RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class);
			RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class);
			resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON);
			jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef);
			// Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically
			GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition();
			jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class);
			jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			jacksonFactoryDef.setSource(source);
			jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef);
			converters.add(jacksonConverterDef);
		}
	}
	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, converters);
	RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cargs, null);
	String name = MESSAGE_CONVERTER_BEAN_NAME;
	registerBeanDefByName(name, messageConverterDef, context, source);
	return new RuntimeBeanReference(name);
}
 
Example 25
Source Project: code   Source File: GreetingIntegrationTests.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	this.sockJsClient = new SockJsClient(transports);

	this.stompClient = new WebSocketStompClient(sockJsClient);
	this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
Example 26
protected MappingJackson2MessageConverter createJacksonConverter() {
	DefaultContentTypeResolver resolver = new DefaultContentTypeResolver();
	resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
	MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
	converter.setContentTypeResolver(resolver);
	return converter;
}
 
Example 27
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
	this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
}
 
Example 28
@Test
public void configureMessageConvertersDefault() {
	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	List<MessageConverter> converters = compositeConverter.getConverters();
	assertThat(converters.size(), Matchers.is(3));
	assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));

	ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
	assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
}
 
Example 29
@Test // SPR-16486
public void resolveWithJacksonConverter() throws Exception {
	Message<String> inMessage = MessageBuilder.withPayload("{\"foo\":\"bar\"}").build();
	MethodParameter parameter = new MethodParameter(this.method, 5);

	this.resolver = new MessageMethodArgumentResolver(new MappingJackson2MessageConverter());
	Object actual = this.resolver.resolveArgument(parameter, inMessage);

	assertTrue(actual instanceof Message);
	Message<?> outMessage = (Message<?>) actual;
	assertTrue(outMessage.getPayload() instanceof Foo);
	assertEquals("bar", ((Foo) outMessage.getPayload()).getFoo());
}
 
Example 30
@Test(expected = MessageConversionException.class)
public void convertAndSendNoMatchingConverter() {

	MessageConverter converter = new CompositeMessageConverter(
			Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter()));
	this.template.setMessageConverter(converter);

	this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
	this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers));
}