BAEL-1273: Display RSS feed with spring mvc (AbstractRssFeedView) (#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)
This commit is contained in:
parent
3459d3ad47
commit
af3edc477d
|
@ -167,6 +167,12 @@
|
|||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.rometools</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>${rome.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -276,6 +282,7 @@
|
|||
<tomee-servlet-api.version>8.5.11</tomee-servlet-api.version>
|
||||
<h2.version>1.4.194</h2.version>
|
||||
<togglz.version>2.4.1.Final</togglz.version>
|
||||
<rome.version>1.9.0</rome.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,54 @@
|
|||
package com.baeldung.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/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,16 @@
|
|||
package com.baeldung.rss;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/rss", produces = "application/*")
|
||||
public class ArticleRssController {
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String articleFeed() {
|
||||
return "articleFeedView";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.rss;
|
||||
|
||||
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CustomContainer implements EmbeddedServletContainerCustomizer {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.setPort(8080);
|
||||
container.setContextPath("");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.rss;
|
||||
|
||||
import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
|
||||
@SpringBootApplication(exclude = MySQLAutoconfiguration.class)
|
||||
@ComponentScan(basePackages = "com.baeldung.rss")
|
||||
public class RssApp {
|
||||
|
||||
@RolesAllowed("*")
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("security.basic.enabled", "false");
|
||||
SpringApplication.run(RssApp.class, args);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue