BAEL-1285: Update Jackson articles (#3623)

* 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

* BAEL-1285: Update Jackson articles

* BAEL-1273: implement both MVC and Rest approach to serve RSS content
This commit is contained in:
Dassi orleando 2018-02-09 22:25:13 +01:00 committed by maibin
parent 65267041c3
commit d4522c7c16
6 changed files with 85 additions and 9 deletions

1
.gitignore vendored
View File

@ -43,3 +43,4 @@ spring-call-getters-using-reflection/.mvn/wrapper/maven-wrapper.properties
spring-check-if-a-property-is-null/.mvn/wrapper/maven-wrapper.properties
*.springBeans
20171220-JMeter.csv

View File

@ -129,7 +129,7 @@
<properties>
<!-- marshalling -->
<jackson.version>2.9.2</jackson.version>
<jackson.version>2.9.4</jackson.version>
<!-- util -->
<guava.version>19.0</guava.version>

View File

@ -297,7 +297,7 @@
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
<thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
<jackson.version>2.8.5</jackson.version>
<jackson.version>2.9.4</jackson.version>
<!-- persistence -->
<hibernate.version>5.2.5.Final</hibernate.version>

View File

@ -1,14 +1,21 @@
package com.baeldung.spring.configuration;
import com.baeldung.spring.controller.rss.ArticleRssFeedViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.accept.ContentNegotiationManager;
import java.util.List;
import java.util.ArrayList;
@Configuration
@EnableWebMvc
@ -21,11 +28,19 @@ class ApplicationConfiguration implements WebMvcConfigurer {
}
@Bean
public InternalResourceViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setPrefix("/WEB-INF/views/");
bean.setSuffix(".jsp");
return bean;
public ContentNegotiatingViewResolver viewResolver(ContentNegotiationManager cnManager) {
ContentNegotiatingViewResolver cnvResolver = new ContentNegotiatingViewResolver();
cnvResolver.setContentNegotiationManager(cnManager);
List<ViewResolver> resolvers = new ArrayList<>();
InternalResourceViewResolver bean = new InternalResourceViewResolver("/WEB-INF/views/",".jsp");
ArticleRssFeedViewResolver articleRssFeedViewResolver = new ArticleRssFeedViewResolver();
resolvers.add(bean);
resolvers.add(articleRssFeedViewResolver);
cnvResolver.setViewResolvers(resolvers);
return cnvResolver;
}
@Bean

View File

@ -1,14 +1,59 @@
package com.baeldung.spring.controller.rss;
import com.rometools.rome.feed.synd.*;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedOutput;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
public class ArticleRssController {
@GetMapping(value = "/rss", produces = "application/*")
public String articleFeed() {
@GetMapping(value = "/rssMvc")
public String articleMvcFeed() {
return "articleFeedView";
}
@GetMapping(value = "/rssRest", produces = "application/rss+xml")
@ResponseBody
public String articleRestFeed() throws FeedException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setLink("http://localhost:8080/spring-mvc-simple/rss");
feed.setTitle("Article Feed");
feed.setDescription("Article Feed Description");
feed.setPublishedDate(new Date());
List list = new ArrayList<SyndEntry>();
SyndEntry item1 = new SyndEntryImpl();
item1.setLink("http://www.baeldung.com/netty-exception-handling");
item1.setTitle("Exceptions in Netty");
SyndContent description1 = new SyndContentImpl();
description1.setValue("In this quick article, well be looking at exception handling in Netty.");
item1.setDescription(description1);
item1.setPublishedDate(new Date());
item1.setAuthor("Carlos");
SyndEntry item2 = new SyndEntryImpl();
item2.setLink("http://www.baeldung.com/cockroachdb-java");
item2.setTitle("Guide to CockroachDB in Java");
SyndContent description2 = new SyndContentImpl();
description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java.");
item2.setDescription(description2);
item2.setPublishedDate(new Date());
item2.setAuthor("Baeldung");
list.add(item1);
list.add(item2);
feed.setEntries(list);
return new SyndFeedOutput().outputString(feed);
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.spring.controller.rss;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import java.util.Locale;
public class ArticleRssFeedViewResolver implements ViewResolver {
@Override
public View resolveViewName(String s, Locale locale) throws Exception {
ArticleFeedView articleFeedView = new ArticleFeedView();
return articleFeedView;
}
}