BAEL-1273: move code to another module (#3532)
* 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) * Move RSS feed with Spring MVC from spring-boot to spring-mvc-simple
This commit is contained in:
parent
70b81ca807
commit
f9649c0926
|
@ -30,6 +30,7 @@
|
|||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||
<junit.platform.version>1.0.2</junit.platform.version>
|
||||
<rome.version>1.9.0</rome.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -115,6 +116,11 @@
|
|||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rometools</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>${rome.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.baeldung.spring.controller.rss;
|
||||
|
||||
import com.rometools.rome.feed.rss.Channel;
|
||||
import com.rometools.rome.feed.rss.Description;
|
||||
import com.rometools.rome.feed.rss.Item;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("articleFeedView")
|
||||
public class ArticleFeedView extends AbstractRssFeedView {
|
||||
|
||||
protected Channel newFeed() {
|
||||
Channel channel = new Channel("rss_2.0");
|
||||
channel.setLink("http://localhost:8080/spring-mvc-simple/rss");
|
||||
channel.setTitle("Article Feed");
|
||||
channel.setDescription("Article Feed Description");
|
||||
channel.setPubDate(new Date());
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception {
|
||||
List list = new ArrayList<Item>();
|
||||
|
||||
Item item1 = new Item();
|
||||
item1.setLink("http://www.baeldung.com/netty-exception-handling");
|
||||
item1.setTitle("Exceptions in Netty");
|
||||
Description description1 = new Description();
|
||||
description1.setValue("In this quick article, we’ll be looking at exception handling in Netty.");
|
||||
item1.setDescription(description1);
|
||||
item1.setPubDate(new Date());
|
||||
item1.setAuthor("Carlos");
|
||||
|
||||
Item item2 = new Item();
|
||||
item2.setLink("http://www.baeldung.com/cockroachdb-java");
|
||||
item2.setTitle("Guide to CockroachDB in Java");
|
||||
Description description2 = new Description();
|
||||
description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java.");
|
||||
item2.setDescription(description2);
|
||||
item2.setPubDate(new Date());
|
||||
item2.setAuthor("Baeldung");
|
||||
|
||||
list.add(item1);
|
||||
list.add(item2);
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.spring.controller.rss;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class ArticleRssController {
|
||||
|
||||
@GetMapping(value = "/rss", produces = "application/*")
|
||||
public String articleFeed() {
|
||||
return "articleFeedView";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue