diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index 581334e7bc8..8513f1a40d8 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -102,6 +102,16 @@ public abstract class MimeTypeUtils { */ public final static String APPLICATION_OCTET_STREAM_VALUE = "application/octet-stream"; + /** + * Public constant mime type for {@code application/rss+xml}. + */ + public final static MimeType APPLICATION_RSS_XML; + + /** + * A String equivalent of {@link MimeTypeUtils#APPLICATION_RSS_XML}. + */ + public final static String APPLICATION_RSS_XML_VALUE = "application/rss+xml"; + /** * Public constant mime type for {@code application/xhtml+xml}. * */ @@ -199,6 +209,7 @@ public abstract class MimeTypeUtils { APPLICATION_FORM_URLENCODED = MimeType.valueOf(APPLICATION_FORM_URLENCODED_VALUE); APPLICATION_JSON = MimeType.valueOf(APPLICATION_JSON_VALUE); APPLICATION_OCTET_STREAM = MimeType.valueOf(APPLICATION_OCTET_STREAM_VALUE); + APPLICATION_RSS_XML = MimeType.valueOf(APPLICATION_RSS_XML_VALUE); APPLICATION_XHTML_XML = MimeType.valueOf(APPLICATION_XHTML_XML_VALUE); APPLICATION_XML = MimeType.valueOf(APPLICATION_XML_VALUE); IMAGE_GIF = MimeType.valueOf(IMAGE_GIF_VALUE); diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 29343f7a96b..bd309e679f9 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -124,6 +124,16 @@ public class MediaType extends MimeType implements Serializable { */ public final static String APPLICATION_PDF_VALUE = "application/pdf"; + /** + * Public constant media type for {@code application/rss+xml}. + */ + public final static MediaType APPLICATION_RSS_XML; + + /** + * A String equivalent of {@link MediaType#APPLICATION_RSS_XML}. + */ + public final static String APPLICATION_RSS_XML_VALUE = "application/rss+xml"; + /** * Public constant media type for {@code application/xhtml+xml}. */ @@ -249,6 +259,7 @@ public class MediaType extends MimeType implements Serializable { APPLICATION_JSON_UTF8 = valueOf(APPLICATION_JSON_UTF8_VALUE); APPLICATION_OCTET_STREAM = valueOf(APPLICATION_OCTET_STREAM_VALUE); APPLICATION_PDF = valueOf(APPLICATION_PDF_VALUE); + APPLICATION_RSS_XML = valueOf(APPLICATION_RSS_XML_VALUE); APPLICATION_XHTML_XML = valueOf(APPLICATION_XHTML_XML_VALUE); APPLICATION_XML = valueOf(APPLICATION_XML_VALUE); IMAGE_GIF = valueOf(IMAGE_GIF_VALUE); diff --git a/spring-web/src/main/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverter.java index 9e7b897e6a9..3e639760037 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/feed/RssChannelHttpMessageConverter.java @@ -38,7 +38,7 @@ import org.springframework.http.MediaType; public class RssChannelHttpMessageConverter extends AbstractWireFeedHttpMessageConverter { public RssChannelHttpMessageConverter() { - super(new MediaType("application", "rss+xml")); + super(MediaType.APPLICATION_RSS_XML); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java index 8e2cddcd6be..6db238e051c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java @@ -433,7 +433,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { Properties props = new Properties(); if (romePresent) { props.put("atom", MediaType.APPLICATION_ATOM_XML_VALUE); - props.put("rss", "application/rss+xml"); + props.put("rss", MediaType.APPLICATION_RSS_XML_VALUE); } if (jaxb2Present || jackson2XmlPresent) { props.put("xml", MediaType.APPLICATION_XML_VALUE); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 331af0ebec1..3c27aa5ee77 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -385,7 +385,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv Map map = new HashMap<>(4); if (romePresent) { map.put("atom", MediaType.APPLICATION_ATOM_XML); - map.put("rss", MediaType.valueOf("application/rss+xml")); + map.put("rss", MediaType.APPLICATION_RSS_XML); } if (jaxb2Present || jackson2XmlPresent) { map.put("xml", MediaType.APPLICATION_XML); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/AbstractRssFeedView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/AbstractRssFeedView.java index a390e087b30..5cb5522fa94 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/AbstractRssFeedView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/feed/AbstractRssFeedView.java @@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletResponse; import com.rometools.rome.feed.rss.Channel; import com.rometools.rome.feed.rss.Item; +import org.springframework.util.MimeTypeUtils; + /** * Abstract superclass for RSS Feed views, using the * ROME package. @@ -46,7 +48,7 @@ import com.rometools.rome.feed.rss.Item; public abstract class AbstractRssFeedView extends AbstractFeedView { public AbstractRssFeedView() { - setContentType("application/rss+xml"); + setContentType(MimeTypeUtils.APPLICATION_RSS_XML_VALUE); } /**