Skip to content

Commit af3edc4

Browse files
Dassi orleandomaibin
authored andcommitted
BAEL-1273: Display RSS feed with spring mvc (AbstractRssFeedView) (eugenp#3490)
* BAEL-1216: improve tests * BAEL-1448: Update Spring 5 articles to use the release version * Setting up the Maven Wrapper on a maven project * Add Maven Wrapper on spring-boot module * simple add * BAEL-976: Update spring version * BAEL-1273: Display RSS feed with spring mvc (AbstractRssFeedView)
1 parent 3459d3a commit af3edc4

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

‎spring-boot/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@
167167
<groupId>org.apache.activemq</groupId>
168168
<artifactId>artemis-server</artifactId>
169169
</dependency>
170+
171+
<dependency>
172+
<groupId>com.rometools</groupId>
173+
<artifactId>rome</artifactId>
174+
<version>${rome.version}</version>
175+
</dependency>
170176
</dependencies>
171177

172178
<build>
@@ -276,6 +282,7 @@
276282
<tomee-servlet-api.version>8.5.11</tomee-servlet-api.version>
277283
<h2.version>1.4.194</h2.version>
278284
<togglz.version>2.4.1.Final</togglz.version>
285+
<rome.version>1.9.0</rome.version>
279286
</properties>
280287

281288
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.baeldung.rss;
2+
3+
import com.rometools.rome.feed.rss.Channel;
4+
import com.rometools.rome.feed.rss.Description;
5+
import com.rometools.rome.feed.rss.Item;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
8+
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
import java.util.ArrayList;
12+
import java.util.Date;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@Service("articleFeedView")
17+
public class ArticleFeedView extends AbstractRssFeedView {
18+
19+
protected Channel newFeed() {
20+
Channel channel = new Channel("rss_2.0");
21+
channel.setLink("http://localhost:8080/rss");
22+
channel.setTitle("Article Feed");
23+
channel.setDescription("Article Feed Description");
24+
channel.setPubDate(new Date());
25+
return channel;
26+
}
27+
28+
@Override
29+
protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception {
30+
List list = new ArrayList<Item>();
31+
32+
Item item1 = new Item();
33+
item1.setLink("http://www.baeldung.com/netty-exception-handling");
34+
item1.setTitle("Exceptions in Netty");
35+
Description description1 = new Description();
36+
description1.setValue("In this quick article, we’ll be looking at exception handling in Netty.");
37+
item1.setDescription(description1);
38+
item1.setPubDate(new Date());
39+
item1.setAuthor("Carlos");
40+
41+
Item item2 = new Item();
42+
item2.setLink("http://www.baeldung.com/cockroachdb-java");
43+
item2.setTitle("Guide to CockroachDB in Java");
44+
Description description2 = new Description();
45+
description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java.");
46+
item2.setDescription(description2);
47+
item2.setPubDate(new Date());
48+
item2.setAuthor("Baeldung");
49+
50+
list.add(item1);
51+
list.add(item2);
52+
return list;
53+
}
54+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.rss;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
7+
@Controller
8+
@RequestMapping(value = "/rss", produces = "application/*")
9+
public class ArticleRssController {
10+
11+
@RequestMapping(method = RequestMethod.GET)
12+
public String articleFeed() {
13+
return "articleFeedView";
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.rss;
2+
3+
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
4+
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class CustomContainer implements EmbeddedServletContainerCustomizer {
9+
10+
@Override
11+
public void customize(ConfigurableEmbeddedServletContainer container) {
12+
container.setPort(8080);
13+
container.setContextPath("");
14+
}
15+
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.rss;
2+
3+
import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.ComponentScan;
7+
8+
import javax.annotation.security.RolesAllowed;
9+
10+
@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
11+
@ComponentScan(basePackages = "com.baeldung.rss")
12+
public class RssApp {
13+
14+
@RolesAllowed("*")
15+
public static void main(String[] args) {
16+
System.setProperty("security.basic.enabled", "false");
17+
SpringApplication.run(RssApp.class, args);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)