Add default ContentTypeResolver initialization

Previously AbstractMessageConverter did not have a ContentTypeResolver
configured by default. However the Java config and XML namespace in
spring-messaging and spring-websocket always configured one.

This change ensures every AbstractMessageConverter is configured with an
instance of DefaultContentTypeResolver by default. This makes sense since
all the resolver does is make an attempt to find a content type to use
for matching. If it can't it returns null and it's up to the converter
to decide whether it can convert or not.

Issue: SPR-11462
This commit is contained in:
Rossen Stoyanchev
2014-02-27 17:10:15 -05:00
parent 801237aec1
commit 0da1eefd74
4 changed files with 9 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,6 @@ public class MappingJackson2MessageConverterTests {
@Before
public void setup() {
this.converter = new MappingJackson2MessageConverter();
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
}
@Test

View File

@@ -46,7 +46,6 @@ public class MessageConverterTests {
@Before
public void setup() {
this.converter = new TestMessageConverter();
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
}
@Test
@@ -81,12 +80,9 @@ public class MessageConverterTests {
@Test
public void supportsMimeTypeNoneConfigured() {
Message<String> message = MessageBuilder.withPayload(
"ABC").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
this.converter = new TestMessageConverter(Collections.<MimeType>emptyList());
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
assertEquals("success-from", this.converter.fromMessage(message, String.class));
}
@@ -94,7 +90,6 @@ public class MessageConverterTests {
@Test
public void canConvertFromStrictContentTypeMatch() {
this.converter = new TestMessageConverter(Arrays.asList(MimeTypeUtils.TEXT_PLAIN));
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
this.converter.setStrictContentTypeMatch(true);
Message<String> message = MessageBuilder.withPayload("ABC").build();
@@ -110,7 +105,6 @@ public class MessageConverterTests {
public void setStrictContentTypeMatchWithNoSupportedMimeTypes() {
Message<String> message = MessageBuilder.withPayload("ABC").build();
this.converter = new TestMessageConverter(Collections.<MimeType>emptyList());
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
this.converter.setStrictContentTypeMatch(true);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@ public class StringMessageConverterTests {
@Before
public void setUp() {
this.converter = new StringMessageConverter();
this.converter.setContentTypeResolver(new DefaultContentTypeResolver());
}