|
1 | 1 | package com.baeldung.spring.controller.rss; |
2 | 2 |
|
| 3 | +import com.rometools.rome.feed.synd.*; |
| 4 | +import com.rometools.rome.io.FeedException; |
| 5 | +import com.rometools.rome.io.SyndFeedOutput; |
3 | 6 | import org.springframework.stereotype.Controller; |
4 | 7 | import org.springframework.web.bind.annotation.GetMapping; |
| 8 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 9 | + |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.Date; |
| 12 | +import java.util.List; |
5 | 13 |
|
6 | 14 | @Controller |
7 | 15 | public class ArticleRssController { |
8 | 16 |
|
9 | | - @GetMapping(value = "/rss", produces = "application/*") |
10 | | - public String articleFeed() { |
| 17 | + @GetMapping(value = "/rssMvc") |
| 18 | + public String articleMvcFeed() { |
11 | 19 | return "articleFeedView"; |
12 | 20 | } |
13 | 21 |
|
| 22 | + @GetMapping(value = "/rssRest", produces = "application/rss+xml") |
| 23 | + @ResponseBody |
| 24 | + public String articleRestFeed() throws FeedException { |
| 25 | + SyndFeed feed = new SyndFeedImpl(); |
| 26 | + feed.setFeedType("rss_2.0"); |
| 27 | + feed.setLink("http://localhost:8080/spring-mvc-simple/rss"); |
| 28 | + feed.setTitle("Article Feed"); |
| 29 | + feed.setDescription("Article Feed Description"); |
| 30 | + feed.setPublishedDate(new Date()); |
| 31 | + |
| 32 | + List list = new ArrayList<SyndEntry>(); |
| 33 | + |
| 34 | + SyndEntry item1 = new SyndEntryImpl(); |
| 35 | + item1.setLink("http://www.baeldung.com/netty-exception-handling"); |
| 36 | + item1.setTitle("Exceptions in Netty"); |
| 37 | + SyndContent description1 = new SyndContentImpl(); |
| 38 | + description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); |
| 39 | + item1.setDescription(description1); |
| 40 | + item1.setPublishedDate(new Date()); |
| 41 | + item1.setAuthor("Carlos"); |
| 42 | + |
| 43 | + SyndEntry item2 = new SyndEntryImpl(); |
| 44 | + item2.setLink("http://www.baeldung.com/cockroachdb-java"); |
| 45 | + item2.setTitle("Guide to CockroachDB in Java"); |
| 46 | + SyndContent description2 = new SyndContentImpl(); |
| 47 | + description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); |
| 48 | + item2.setDescription(description2); |
| 49 | + item2.setPublishedDate(new Date()); |
| 50 | + item2.setAuthor("Baeldung"); |
| 51 | + |
| 52 | + list.add(item1); |
| 53 | + list.add(item2); |
| 54 | + feed.setEntries(list); |
| 55 | + |
| 56 | + return new SyndFeedOutput().outputString(feed); |
| 57 | + } |
| 58 | + |
14 | 59 | } |
0 commit comments