PDA

View Full Version : RSS and ATOM version support



zpyoung
Jun 5th, 2012, 09:23 PM
What is the safe way to support the different RSS and ATOM version? In the below sample I have included media types to support. This seems to be working when I provide different RSS or ATOM feeds.


// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();

// Configure the SyndFeed message converter.
SyndFeedHttpMessageConverter syndFeedConverter = new SyndFeedHttpMessageConverter();

List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_XML);
mediaTypes.add(MediaType.APPLICATION_ATOM_XML);

syndFeedConverter.setSupportedMediaTypes(mediaType s);


// Add the SyndFeed message converter to the RestTemplate instance
restTemplate.getMessageConverters().add(syndFeedCo nverter);

// Initiate the request and return the results
SyndFeed feed = restTemplate.getForObject(url, SyndFeed.class);

Roy Clarkson
Jun 6th, 2012, 10:32 AM
The code you provided is correct usage of the SyndFeedHttpMessageConverter. application/rss+xml, and application/atom+xml are the default media (mime) types associated with this converter. You don't need to set these manually, unless you need to support a different type, as you are doing in your code.