From 1e16ae88e36a02bae391fceb8c855e21ad07cca3 Mon Sep 17 00:00:00 2001 From: rajadilipkolli Date: Tue, 7 Feb 2017 00:12:41 +0530 Subject: [PATCH 1/5] upgrade to latest available jars and fix deprecated, unused imports --- pom.xml | 602 +++++++++--------- .../samples/mvc/form/FormControllerTests.java | 229 ++++--- .../mvc/redirect/RedirectControllerTests.java | 70 +- .../mvc/response/ResponseControllerTests.java | 131 ++-- .../SimpleControllerRevisitedTests.java | 44 +- 5 files changed, 537 insertions(+), 539 deletions(-) diff --git a/pom.xml b/pom.xml index f3bae982b..127445420 100644 --- a/pom.xml +++ b/pom.xml @@ -1,301 +1,301 @@ - - - 4.0.0 - org.springframework.samples - spring-mvc-showcase - spring-mvc-showcase - war - 1.0.0-BUILD-SNAPSHOT - - 1.7 - 4.2.2.RELEASE - 4.0.1.RELEASE - 1.8.1 - 1.7.12 - - - - - org.springframework - spring-context - ${org.springframework-version} - - - - commons-logging - commons-logging - - - - - org.springframework - spring-webmvc - ${org.springframework-version} - - - - org.aspectj - aspectjrt - ${org.aspectj-version} - - - - - org.slf4j - slf4j-api - ${org.slf4j-version} - - - org.slf4j - jcl-over-slf4j - ${org.slf4j-version} - runtime - - - org.slf4j - slf4j-log4j12 - ${org.slf4j-version} - runtime - - - log4j - log4j - 1.2.16 - runtime - - - - - javax.inject - javax.inject - 1 - - - - - org.apache.tomcat - tomcat-servlet-api - 7.0.30 - provided - - - javax.servlet.jsp - jsp-api - 2.1 - provided - - - javax.servlet.jsp.jstl - jstl-api - 1.2 - - - javax.servlet - servlet-api - - - - - org.glassfish.web - jstl-impl - 1.2 - - - javax.servlet - servlet-api - - - - - - - com.fasterxml.jackson.core - jackson-databind - 2.5.3 - - - - - com.rometools - rome - 1.5.0 - - - - - javax.validation - validation-api - 1.0.0.GA - - - org.hibernate - hibernate-validator - 4.1.0.Final - - - - - joda-time - joda-time - 2.3 - - - - - commons-fileupload - commons-fileupload - 1.2.2 - - - commons-io - commons-io - 2.0.1 - - - - - org.springframework.security - spring-security-web - ${org.springframework.security-version} - - - - - org.springframework - spring-test - ${org.springframework-version} - test - - - junit - junit - 4.11 - test - - - xmlunit - xmlunit - 1.2 - test - - - com.jayway.jsonpath - json-path - 0.8.1 - test - - - org.hamcrest - hamcrest-library - 1.3 - test - - - - - - org.springframework.maven.snapshot - Spring Maven Snapshot Repository - http://repo.spring.io/snapshot - false - true - - - - org.springframework.maven.milestone - Spring Maven Milestone Repository - http://repo.spring.io/milestone - false - - - - ${project.artifactId} - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - ${java-version} - ${java-version} - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12 - - - **/*Tests.java - - - **/Abstract*.java - - junit:junit - -Xmx512m - - - - org.apache.maven.plugins - maven-dependency-plugin - - - install - install - - sources - - - - - - org.codehaus.mojo - aspectj-maven-plugin - - 1.2 - - - - org.aspectj - aspectjrt - ${org.aspectj-version} - - - org.aspectj - aspectjtools - ${org.aspectj-version} - - - - - - compile - test-compile - - - - - true - ${java-version} - ${java-version} - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.2 - - - org.eclipse.jetty - jetty-maven-plugin - 9.0.6.v20130930 - - - /${project.artifactId} - - - - - - + + + 4.0.0 + org.springframework.samples + spring-mvc-showcase + spring-mvc-showcase + war + 1.0.0-BUILD-SNAPSHOT + + 1.7 + 4.3.6.RELEASE + 4.2.1.RELEASE + 1.8.9 + 1.7.22 + + + + + org.springframework + spring-context + ${org.springframework-version} + + + + commons-logging + commons-logging + + + + + org.springframework + spring-webmvc + ${org.springframework-version} + + + + org.aspectj + aspectjrt + ${org.aspectj-version} + + + + + org.slf4j + slf4j-api + ${org.slf4j-version} + + + org.slf4j + jcl-over-slf4j + ${org.slf4j-version} + runtime + + + org.slf4j + slf4j-log4j12 + ${org.slf4j-version} + runtime + + + log4j + log4j + 1.2.17 + runtime + + + + + javax.inject + javax.inject + 1 + + + + + org.apache.tomcat + tomcat-servlet-api + 7.0.30 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + javax.servlet.jsp.jstl + jstl-api + 1.2 + + + javax.servlet + servlet-api + + + + + org.glassfish.web + jstl-impl + 1.2 + + + javax.servlet + servlet-api + + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.8.6 + + + + + com.rometools + rome + 1.7.1 + + + + + javax.validation + validation-api + 1.0.0.GA + + + org.hibernate + hibernate-validator + 4.1.0.Final + + + + + joda-time + joda-time + 2.9.7 + + + + + commons-fileupload + commons-fileupload + 1.3.2 + + + commons-io + commons-io + 2.5 + + + + + org.springframework.security + spring-security-web + ${org.springframework.security-version} + + + + + org.springframework + spring-test + ${org.springframework-version} + test + + + junit + junit + 4.12 + test + + + xmlunit + xmlunit + 1.6 + test + + + com.jayway.jsonpath + json-path + 2.2.0 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + + + + org.springframework.maven.snapshot + Spring Maven Snapshot Repository + http://repo.spring.io/snapshot + false + true + + + + org.springframework.maven.milestone + Spring Maven Milestone Repository + http://repo.spring.io/milestone + false + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${java-version} + ${java-version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + + **/*Tests.java + + + **/Abstract*.java + + junit:junit + -Xmx512m + + + + org.apache.maven.plugins + maven-dependency-plugin + + + install + install + + sources + + + + + + org.codehaus.mojo + aspectj-maven-plugin + + 1.2 + + + + org.aspectj + aspectjrt + ${org.aspectj-version} + + + org.aspectj + aspectjtools + ${org.aspectj-version} + + + + + + compile + test-compile + + + + + true + ${java-version} + ${java-version} + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + + org.eclipse.jetty + jetty-maven-plugin + 9.0.6.v20130930 + + + /${project.artifactId} + + + + + + diff --git a/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java b/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java index c919e7159..aab9009af 100644 --- a/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java @@ -1,115 +1,114 @@ -package org.springframework.samples.mvc.form; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.flash; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -public class FormControllerTests { - - private MockMvc mockMvc; - - @Before - public void setup() throws Exception { - - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/WEB-INF/"); - viewResolver.setSuffix(".jsp"); - - this.mockMvc = standaloneSetup(new FormController()).setViewResolvers(viewResolver).build(); - } - - @Test - public void submitSuccess() throws Exception { - String timezone = getTimezone(1941, 12, 16); - this.mockMvc.perform( - post("/form") - .param("name", "Joe") - .param("age", "56") - .param("birthDate", "1941-12-16") - .param("phone", "(347) 888-1234") - .param("currency", "$123.33") - .param("percent", "89%") - .param("inquiry", "comment") - .param("inquiryDetails", "what is?") - .param("additionalInfo[mvc]", "true") - .param("_additionalInfo[mvc]", "on") - .param("additionalInfo[java]", "true") - .param("_additionalInfo[java]", "on") - .param("subscribeNewsletter", "false")) - .andDo(print()) - .andExpect(status().isMovedTemporarily()) - .andExpect(redirectedUrl("/form")) - .andExpect(flash().attribute("message", - "Form submitted successfully. Bound properties name='Joe', age=56, " + - "birthDate=Tue Dec 16 00:00:00 " + timezone + " 1941, phone='(347) 888-1234', " + - "currency=123.33, percent=0.89, inquiry=comment, inquiryDetails='what is?'," + - " subscribeNewsletter=false, additionalInfo={java=true, mvc=true}")); - } - - @Test - public void submitSuccessAjax() throws Exception { - String timezone = getTimezone(1941, 12, 16); - this.mockMvc.perform( - post("/form") - .header("X-Requested-With", "XMLHttpRequest") - .param("name", "Joe") - .param("age", "56") - .param("birthDate", "1941-12-16") - .param("phone", "(347) 888-1234") - .param("currency", "$123.33") - .param("percent", "89%") - .param("inquiry", "comment") - .param("inquiryDetails", "what is?") - .param("additionalInfo[mvc]", "true") - .param("_additionalInfo[mvc]", "on") - .param("additionalInfo[java]", "true") - .param("_additionalInfo[java]", "on") - .param("subscribeNewsletter", "false")) - .andExpect(status().isOk()) - .andExpect(view().name("form")) - .andExpect(model().hasNoErrors()) - .andExpect(model().attribute("message", - "Form submitted successfully. Bound properties name='Joe', age=56, " + - "birthDate=Tue Dec 16 00:00:00 " + timezone + " 1941, phone='(347) 888-1234', " + - "currency=123.33, percent=0.89, inquiry=comment, inquiryDetails='what is?'," + - " subscribeNewsletter=false, additionalInfo={java=true, mvc=true}")); - } - - @Test - public void submitError() throws Exception { - this.mockMvc.perform( - post("/form")) - .andExpect(status().isOk()) - .andExpect(view().name("form")) - .andExpect(model().errorCount(2)) - .andExpect(model().attributeHasFieldErrors("formBean", "name", "age")); - } - - private String getTimezone(int year, int month, int day) - { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, year); - calendar.set(Calendar.MONTH, month); - calendar.set(Calendar.DAY_OF_MONTH, day); - Date date = calendar.getTime(); - TimeZone timezone = TimeZone.getDefault(); - boolean inDaylight = timezone.inDaylightTime(date); - return timezone.getDisplayName(inDaylight, TimeZone.SHORT); - } - -} +package org.springframework.samples.mvc.form; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.flash; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +public class FormControllerTests { + + private MockMvc mockMvc; + + @Before + public void setup() throws Exception { + + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/WEB-INF/"); + viewResolver.setSuffix(".jsp"); + + this.mockMvc = standaloneSetup(new FormController()).setViewResolvers(viewResolver).build(); + } + + @Test + public void submitSuccess() throws Exception { + String timezone = getTimezone(1941, 12, 16); + this.mockMvc.perform( + post("/form") + .param("name", "Joe") + .param("age", "56") + .param("birthDate", "1941-12-16") + .param("phone", "(347) 888-1234") + .param("currency", "$123.33") + .param("percent", "89%") + .param("inquiry", "comment") + .param("inquiryDetails", "what is?") + .param("additionalInfo[mvc]", "true") + .param("_additionalInfo[mvc]", "on") + .param("additionalInfo[java]", "true") + .param("_additionalInfo[java]", "on") + .param("subscribeNewsletter", "false")) + .andDo(print()) + .andExpect(status().isFound()) + .andExpect(redirectedUrl("/form")) + .andExpect(flash().attribute("message", + "Form submitted successfully. Bound properties name='Joe', age=56, " + + "birthDate=Tue Dec 16 00:00:00 " + timezone + " 1941, phone='(347) 888-1234', " + + "currency=123.33, percent=0.89, inquiry=comment, inquiryDetails='what is?'," + + " subscribeNewsletter=false, additionalInfo={java=true, mvc=true}")); + } + + @Test + public void submitSuccessAjax() throws Exception { + String timezone = getTimezone(1941, 12, 16); + this.mockMvc.perform( + post("/form") + .header("X-Requested-With", "XMLHttpRequest") + .param("name", "Joe") + .param("age", "56") + .param("birthDate", "1941-12-16") + .param("phone", "(347) 888-1234") + .param("currency", "$123.33") + .param("percent", "89%") + .param("inquiry", "comment") + .param("inquiryDetails", "what is?") + .param("additionalInfo[mvc]", "true") + .param("_additionalInfo[mvc]", "on") + .param("additionalInfo[java]", "true") + .param("_additionalInfo[java]", "on") + .param("subscribeNewsletter", "false")) + .andExpect(status().isOk()) + .andExpect(view().name("form")) + .andExpect(model().hasNoErrors()) + .andExpect(model().attribute("message", + "Form submitted successfully. Bound properties name='Joe', age=56, " + + "birthDate=Tue Dec 16 00:00:00 " + timezone + " 1941, phone='(347) 888-1234', " + + "currency=123.33, percent=0.89, inquiry=comment, inquiryDetails='what is?'," + + " subscribeNewsletter=false, additionalInfo={java=true, mvc=true}")); + } + + @Test + public void submitError() throws Exception { + this.mockMvc.perform( + post("/form")) + .andExpect(status().isOk()) + .andExpect(view().name("form")) + .andExpect(model().errorCount(2)) + .andExpect(model().attributeHasFieldErrors("formBean", "name", "age")); + } + + private String getTimezone(int year, int month, int day) + { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month); + calendar.set(Calendar.DAY_OF_MONTH, day); + Date date = calendar.getTime(); + TimeZone timezone = TimeZone.getDefault(); + boolean inDaylight = timezone.inDaylightTime(date); + return timezone.getDisplayName(inDaylight, TimeZone.SHORT); + } + +} diff --git a/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java b/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java index cd710cf65..041ef172c 100644 --- a/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java @@ -1,35 +1,35 @@ -package org.springframework.samples.mvc.redirect; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.test.web.servlet.MockMvc; - -public class RedirectControllerTests { - - private MockMvc mockMvc; - - @Before - public void setup() throws Exception { - this.mockMvc = standaloneSetup(new RedirectController(new DefaultFormattingConversionService())) - .alwaysExpect(status().isMovedTemporarily()).build(); - } - - @Test - public void uriTemplate() throws Exception { - this.mockMvc.perform(get("/redirect/uriTemplate")) - .andExpect(redirectedUrl("/redirect/a123?date=12%2F31%2F11")); - } - - @Test - public void uriComponentsBuilder() throws Exception { - this.mockMvc.perform(get("/redirect/uriComponentsBuilder")) - .andExpect(redirectedUrl("/redirect/a123?date=12/31/11")); - } - -} +package org.springframework.samples.mvc.redirect; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.format.support.DefaultFormattingConversionService; +import org.springframework.test.web.servlet.MockMvc; + +public class RedirectControllerTests { + + private MockMvc mockMvc; + + @Before + public void setup() throws Exception { + this.mockMvc = standaloneSetup(new RedirectController(new DefaultFormattingConversionService())) + .alwaysExpect(status().isFound()).build(); + } + + @Test + public void uriTemplate() throws Exception { + this.mockMvc.perform(get("/redirect/uriTemplate")) + .andExpect(redirectedUrl("/redirect/a123?date=12%2F31%2F11")); + } + + @Test + public void uriComponentsBuilder() throws Exception { + this.mockMvc.perform(get("/redirect/uriComponentsBuilder")) + .andExpect(redirectedUrl("/redirect/a123?date=12/31/11")); + } + +} diff --git a/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java b/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java index 0cf136244..83b364992 100644 --- a/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java @@ -1,66 +1,65 @@ -package org.springframework.samples.mvc.response; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - -import java.nio.charset.Charset; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -public class ResponseControllerTests { - - private MockMvc mockMvc; - - @Before - public void setup() throws Exception { - this.mockMvc = standaloneSetup(new ResponseController()).build(); - } - - @Test - public void responseBody() throws Exception { - this.mockMvc.perform(get("/response/annotation")) - .andExpect(status().isOk()) - .andExpect(content().string("The String ResponseBody")); - } - - @Test - public void responseCharsetAccept() throws Exception { - this.mockMvc.perform( - get("/response/charset/accept") - .accept(new MediaType("text", "plain", Charset.forName("UTF-8")))) - .andExpect(status().isOk()) - .andExpect(content().string( - "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)")); - } - - @Test - public void responseCharsetProduce() throws Exception { - this.mockMvc.perform(get("/response/charset/produce")) - .andExpect(status().isOk()) - .andExpect(content().string( - "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)")); - } - - @Test - public void responseEntityStatus() throws Exception { - this.mockMvc.perform(get("/response/entity/status")) - .andExpect(status().isForbidden()) - .andExpect(content().string( - "The String ResponseBody with custom status code (403 Forbidden)")); - } - - @Test - public void responseEntityHeaders() throws Exception { - this.mockMvc.perform(get("/response/entity/headers")) - .andExpect(status().isOk()) - .andExpect(content().string( - "The String ResponseBody with custom header Content-Type=text/plain")); - } - -} +package org.springframework.samples.mvc.response; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import java.nio.charset.Charset; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +public class ResponseControllerTests { + + private MockMvc mockMvc; + + @Before + public void setup() throws Exception { + this.mockMvc = standaloneSetup(new ResponseController()).build(); + } + + @Test + public void responseBody() throws Exception { + this.mockMvc.perform(get("/response/annotation")) + .andExpect(status().isOk()) + .andExpect(content().string("The String ResponseBody")); + } + + @Test + public void responseCharsetAccept() throws Exception { + this.mockMvc.perform( + get("/response/charset/accept") + .accept(new MediaType("text", "plain", Charset.forName("UTF-8")))) + .andExpect(status().isOk()) + .andExpect(content().string( + "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)")); + } + + @Test + public void responseCharsetProduce() throws Exception { + this.mockMvc.perform(get("/response/charset/produce")) + .andExpect(status().isOk()) + .andExpect(content().string( + "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)")); + } + + @Test + public void responseEntityStatus() throws Exception { + this.mockMvc.perform(get("/response/entity/status")) + .andExpect(status().isForbidden()) + .andExpect(content().string( + "The String ResponseBody with custom status code (403 Forbidden)")); + } + + @Test + public void responseEntityHeaders() throws Exception { + this.mockMvc.perform(get("/response/entity/headers")) + .andExpect(status().isOk()) + .andExpect(content().string( + "The String ResponseBody with custom header Content-Type=text/plain")); + } + +} diff --git a/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java b/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java index de0ec0622..4814b7932 100644 --- a/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java +++ b/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java @@ -1,22 +1,22 @@ -package org.springframework.samples.mvc.simple; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - -import org.junit.Test; -import org.springframework.http.MediaType; - -public class SimpleControllerRevisitedTests { - - @Test - public void simple() throws Exception { - standaloneSetup(new SimpleControllerRevisited()).build() - .perform(get("/simple/revisited").accept(MediaType.TEXT_PLAIN)) - .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain")) - .andExpect(content().string("Hello world revisited!")); - } - -} +package org.springframework.samples.mvc.simple; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; + +import org.junit.Test; +import org.springframework.http.MediaType; + +public class SimpleControllerRevisitedTests { + + @Test + public void simple() throws Exception { + standaloneSetup(new SimpleControllerRevisited()).build() + .perform(get("/simple/revisited").accept(MediaType.TEXT_PLAIN)) + .andExpect(status().isOk()) + .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) + .andExpect(content().string("Hello world revisited!")); + } + +} From da185d4622d1c9b40899e349dcf448c0e6149da2 Mon Sep 17 00:00:00 2001 From: rajadilipkolli Date: Fri, 17 Feb 2017 01:30:38 +0530 Subject: [PATCH 2/5] Converts from spring to spring-boot application --- pom.xml | 264 +++--------------- .../samples/mvc/Application.java | 26 ++ .../samples/mvc/config/WebConfig.java | 84 ++++++ .../mvc/redirect/RedirectController.java | 92 +++--- src/main/resources/application.properties | 10 + src/main/resources/log4j.xml | 42 --- .../WEB-INF/spring/appServlet/controllers.xml | 15 - .../spring/appServlet/servlet-context.xml | 49 ---- .../webapp/WEB-INF/spring/root-context.xml | 23 -- src/main/webapp/WEB-INF/web.xml | 49 ---- .../mvc/AbstractContextControllerTests.java | 30 +- src/test/resources/log4j.xml | 41 --- 12 files changed, 221 insertions(+), 504 deletions(-) create mode 100644 src/main/java/org/springframework/samples/mvc/Application.java create mode 100644 src/main/java/org/springframework/samples/mvc/config/WebConfig.java create mode 100644 src/main/resources/application.properties delete mode 100644 src/main/resources/log4j.xml delete mode 100644 src/main/webapp/WEB-INF/spring/appServlet/controllers.xml delete mode 100644 src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml delete mode 100644 src/main/webapp/WEB-INF/spring/root-context.xml delete mode 100644 src/main/webapp/WEB-INF/web.xml delete mode 100644 src/test/resources/log4j.xml diff --git a/pom.xml b/pom.xml index 127445420..ca27c574d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,139 +7,38 @@ spring-mvc-showcase war 1.0.0-BUILD-SNAPSHOT + + + org.springframework.boot + spring-boot-dependencies + 1.5.1.RELEASE + + - 1.7 - 4.3.6.RELEASE - 4.2.1.RELEASE - 1.8.9 - 1.7.22 + 1.8 + UTF-8 + false - org.springframework - spring-context - ${org.springframework-version} - - - - commons-logging - commons-logging - - - - - org.springframework - spring-webmvc - ${org.springframework-version} - - - - org.aspectj - aspectjrt - ${org.aspectj-version} - - - - - org.slf4j - slf4j-api - ${org.slf4j-version} - - - org.slf4j - jcl-over-slf4j - ${org.slf4j-version} - runtime - - - org.slf4j - slf4j-log4j12 - ${org.slf4j-version} - runtime - - - log4j - log4j - 1.2.17 - runtime - - - - - javax.inject - javax.inject - 1 + org.springframework.boot + spring-boot-starter-web - - - org.apache.tomcat - tomcat-servlet-api - 7.0.30 - provided + org.springframework.boot + spring-boot-starter-aop - javax.servlet.jsp - jsp-api - 2.1 - provided + org.springframework.boot + spring-boot-starter-security - - javax.servlet.jsp.jstl - jstl-api - 1.2 - - - javax.servlet - servlet-api - - - - - org.glassfish.web - jstl-impl - 1.2 - - - javax.servlet - servlet-api - - - - - - - com.fasterxml.jackson.core - jackson-databind - 2.8.6 - - com.rometools rome 1.7.1 - - - - javax.validation - validation-api - 1.0.0.GA - - - org.hibernate - hibernate-validator - 4.1.0.Final - - - - - joda-time - joda-time - 2.9.7 - @@ -153,78 +52,57 @@ 2.5 - + - org.springframework.security - spring-security-web - ${org.springframework.security-version} + joda-time + joda-time - - + + - org.springframework - spring-test - ${org.springframework-version} - test + org.apache.tomcat.embed + tomcat-embed-jasper - junit - junit - 4.12 - test + javax.servlet + jstl + - xmlunit - xmlunit - 1.6 - test + org.springframework.boot + spring-boot-devtools + true + - com.jayway.jsonpath - json-path - 2.2.0 + org.springframework.boot + spring-boot-starter-test test - org.hamcrest - hamcrest-library - 1.3 + xmlunit + xmlunit + 1.2 test - - - - org.springframework.maven.snapshot - Spring Maven Snapshot Repository - http://repo.spring.io/snapshot - false - true - - - - org.springframework.maven.milestone - Spring Maven Milestone Repository - http://repo.spring.io/milestone - false - - ${project.artifactId} + + org.springframework.boot + spring-boot-maven-plugin + org.apache.maven.plugins maven-compiler-plugin - 2.3.2 - ${java-version} - ${java-version} + ${java.version} + ${java.version} - org.apache.maven.plugins maven-surefire-plugin - 2.12 **/*Tests.java @@ -236,66 +114,6 @@ -Xmx512m - - org.apache.maven.plugins - maven-dependency-plugin - - - install - install - - sources - - - - - - org.codehaus.mojo - aspectj-maven-plugin - - 1.2 - - - - org.aspectj - aspectjrt - ${org.aspectj-version} - - - org.aspectj - aspectjtools - ${org.aspectj-version} - - - - - - compile - test-compile - - - - - true - ${java-version} - ${java-version} - - - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.2 - - - org.eclipse.jetty - jetty-maven-plugin - 9.0.6.v20130930 - - - /${project.artifactId} - - - diff --git a/src/main/java/org/springframework/samples/mvc/Application.java b/src/main/java/org/springframework/samples/mvc/Application.java new file mode 100644 index 000000000..6c4ad8f3a --- /dev/null +++ b/src/main/java/org/springframework/samples/mvc/Application.java @@ -0,0 +1,26 @@ +package org.springframework.samples.mvc; + +import org.springframework.boot.Banner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@EnableAsync +public class Application extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return configureApplication(builder); + } + + public static void main(String[] args) { + configureApplication(new SpringApplicationBuilder()).run(args); + } + + private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) { + return builder.sources(Application.class).bannerMode(Banner.Mode.OFF); + } + +} diff --git a/src/main/java/org/springframework/samples/mvc/config/WebConfig.java b/src/main/java/org/springframework/samples/mvc/config/WebConfig.java new file mode 100644 index 000000000..c44add95f --- /dev/null +++ b/src/main/java/org/springframework/samples/mvc/config/WebConfig.java @@ -0,0 +1,84 @@ +package org.springframework.samples.mvc.config; + +import java.util.List; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.samples.mvc.async.TimeoutCallableProcessingInterceptor; +import org.springframework.samples.mvc.convert.MaskFormatAnnotationFormatterFactory; +import org.springframework.samples.mvc.data.custom.CustomArgumentResolver; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; +import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.util.UrlPathHelper; + +@Configuration +@EnableScheduling +public class WebConfig extends WebMvcConfigurerAdapter +{ + /* In order to enable Spring MVC Matrix Variables */ + @Override + public void configurePathMatch(PathMatchConfigurer configurer) + { + UrlPathHelper urlPathHelper = new UrlPathHelper(); + urlPathHelper.setRemoveSemicolonContent(false); + configurer.setUrlPathHelper(urlPathHelper); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) + { + registry.addViewController("/home").setViewName("home"); + registry.addRedirectViewController("/", "/home"); + super.addViewControllers(registry); + } + + @Override + public void addArgumentResolvers( + List argumentResolvers) + { + // equivalent to + argumentResolvers.add(new CustomArgumentResolver()); + } + + @Override + public void configureAsyncSupport(AsyncSupportConfigurer configurer) + { + super.configureAsyncSupport(configurer); + configurer.registerCallableInterceptors(timeoutInterceptor()); + } + + /* + * Only needed because we install custom converters to support the examples in the + * org.springframewok.samples.mvc.convert package + */ + @Override + public void addFormatters(FormatterRegistry registry) + { + registry.addFormatterForFieldAnnotation( + new MaskFormatAnnotationFormatterFactory()); + } + + @Bean + public TimeoutCallableProcessingInterceptor timeoutInterceptor() + { + return new TimeoutCallableProcessingInterceptor(); + } + + /* + * Only needed because we require fileupload in the + * org.springframework.samples.mvc.fileupload package + */ + @Bean + public MultipartResolver multipartResolver() + { + return new CommonsMultipartResolver(); + } + +} diff --git a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java index c34470592..66eb808b2 100644 --- a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java +++ b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java @@ -1,47 +1,45 @@ -package org.springframework.samples.mvc.redirect; - -import javax.inject.Inject; - -import org.joda.time.LocalDate; -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import org.springframework.web.util.UriComponents; -import org.springframework.web.util.UriComponentsBuilder; - -@Controller -@RequestMapping("/redirect") -public class RedirectController { - - private final ConversionService conversionService; - - @Inject - public RedirectController(ConversionService conversionService) { - this.conversionService = conversionService; - } - - @RequestMapping(value="/uriTemplate", method=RequestMethod.GET) - public String uriTemplate(RedirectAttributes redirectAttrs) { - redirectAttrs.addAttribute("account", "a123"); // Used as URI template variable - redirectAttrs.addAttribute("date", new LocalDate(2011, 12, 31)); // Appended as a query parameter - return "redirect:/redirect/{account}"; - } - - @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET) - public String uriComponentsBuilder() { - String date = this.conversionService.convert(new LocalDate(2011, 12, 31), String.class); - UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date) - .build().expand("a123").encode(); - return "redirect:" + redirectUri.toUriString(); - } - - @RequestMapping(value="/{account}", method=RequestMethod.GET) - public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) { - return "redirect/redirectResults"; - } - -} +package org.springframework.samples.mvc.redirect; + +import java.time.LocalDate; + +import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; + +@Controller +@RequestMapping("/redirect") +public class RedirectController { + + private final ConversionService conversionService; + + public RedirectController(ConversionService conversionService) { + this.conversionService = conversionService; + } + + @RequestMapping(value="/uriTemplate", method=RequestMethod.GET) + public String uriTemplate(RedirectAttributes redirectAttrs) { + redirectAttrs.addAttribute("account", "a123"); // Used as URI template variable + redirectAttrs.addAttribute("date", LocalDate.of(2011, 12, 31)); // Appended as a query parameter + return "redirect:/redirect/{account}"; + } + + @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET) + public String uriComponentsBuilder() { + String date = this.conversionService.convert(LocalDate.of(2011, 12, 31), String.class); + UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date) + .build().expand("a123").encode(); + return "redirect:" + redirectUri.toUriString(); + } + + @RequestMapping(value="/{account}", method=RequestMethod.GET) + public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) { + return "redirect/redirectResults"; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 000000000..c8648a877 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,10 @@ +spring.mvc.view.prefix=/WEB-INF/views/ +spring.mvc.view.suffix=.jsp +spring.mvc.async.request-timeout=3000 + +security.user.password=password + +logging.level.org.springframework.samples=debug +logging.level.org.springframework.http=debug +logging.level.org.springframework.web=debug +logging.level.root=warn \ No newline at end of file diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml deleted file mode 100644 index 5439a479f..000000000 --- a/src/main/resources/log4j.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml b/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml deleted file mode 100644 index 56dba6e8c..000000000 --- a/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml deleted file mode 100644 index eb46e018b..000000000 --- a/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml deleted file mode 100644 index 2c734abb4..000000000 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index d30ed1778..000000000 --- a/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - contextConfigLocation - /WEB-INF/spring/root-context.xml - - - - - org.springframework.web.context.ContextLoaderListener - - - - csrfFilter - org.springframework.web.filter.DelegatingFilterProxy - true - - - csrfFilter - /* - - - - - appServlet - org.springframework.web.servlet.DispatcherServlet - - contextConfigLocation - /WEB-INF/spring/appServlet/servlet-context.xml - - 1 - true - - - - appServlet - / - - - - - - - - \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java index c2116dac8..463c6edda 100644 --- a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java @@ -1,15 +1,15 @@ -package org.springframework.samples.mvc; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.context.WebApplicationContext; - -@WebAppConfiguration -@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml") -public class AbstractContextControllerTests { - - @Autowired - protected WebApplicationContext wac; - -} +package org.springframework.samples.mvc; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.web.context.WebApplicationContext; + +@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) +//@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml") +public class AbstractContextControllerTests { + + @Autowired + protected WebApplicationContext wac; + +} diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml deleted file mode 100644 index 7620a1676..000000000 --- a/src/test/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 742886720904312e93705c0a1696abb68f641e0c Mon Sep 17 00:00:00 2001 From: rajadilipkolli Date: Fri, 17 Feb 2017 01:42:56 +0530 Subject: [PATCH 3/5] Fix JUNIT Testcases --- .../samples/mvc/async/CallableControllerTests.java | 4 ++-- .../samples/mvc/async/DeferredResultControllerTests.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java b/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java index 085801768..5484657cf 100644 --- a/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java @@ -37,7 +37,7 @@ public void responseBody() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) + .andExpect(content().contentType("text/plain;charset=UTF-8")) .andExpect(content().string("Callable result")); } @@ -64,7 +64,7 @@ public void exception() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) + .andExpect(content().contentType("text/plain;charset=UTF-8")) .andExpect(content().string("Handled exception: Callable error")); } diff --git a/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java b/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java index 3753add81..1fd83bb56 100644 --- a/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java @@ -39,7 +39,7 @@ public void responseBody() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) + .andExpect(content().contentType("text/plain;charset=UTF-8")) .andExpect(content().string("Deferred result")); } @@ -67,7 +67,7 @@ public void exception() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) + .andExpect(content().contentType("text/plain;charset=UTF-8")) .andExpect(content().string("Handled exception: DeferredResult error")); } From 0d88c86a6dd364c25d57c09cd225265bba7acd34 Mon Sep 17 00:00:00 2001 From: rajadilipkolli Date: Fri, 17 Feb 2017 01:55:27 +0530 Subject: [PATCH 4/5] Fix xmlunit version with master and removed unused annotation --- pom.xml | 4 ++-- .../java/org/springframework/samples/mvc/Application.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index ca27c574d..975de3093 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ joda-time - + org.apache.tomcat.embed tomcat-embed-jasper @@ -82,7 +82,7 @@ xmlunit xmlunit - 1.2 + 1.6 test diff --git a/src/main/java/org/springframework/samples/mvc/Application.java b/src/main/java/org/springframework/samples/mvc/Application.java index 6c4ad8f3a..d05c72b0d 100644 --- a/src/main/java/org/springframework/samples/mvc/Application.java +++ b/src/main/java/org/springframework/samples/mvc/Application.java @@ -4,10 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.scheduling.annotation.EnableAsync; @SpringBootApplication -@EnableAsync public class Application extends SpringBootServletInitializer { @Override From 09dcd9c88a7b9b703f0b7e8a90191775b0944302 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 17 Feb 2017 01:59:29 +0530 Subject: [PATCH 5/5] Revert "Springboot mvc showcase" --- pom.xml | 264 +++++++++++++++--- .../samples/mvc/Application.java | 24 -- .../samples/mvc/config/WebConfig.java | 84 ------ .../mvc/redirect/RedirectController.java | 92 +++--- src/main/resources/application.properties | 10 - src/main/resources/log4j.xml | 42 +++ .../WEB-INF/spring/appServlet/controllers.xml | 15 + .../spring/appServlet/servlet-context.xml | 49 ++++ .../webapp/WEB-INF/spring/root-context.xml | 23 ++ src/main/webapp/WEB-INF/web.xml | 49 ++++ .../mvc/AbstractContextControllerTests.java | 30 +- .../mvc/async/CallableControllerTests.java | 4 +- .../async/DeferredResultControllerTests.java | 4 +- src/test/resources/log4j.xml | 41 +++ 14 files changed, 508 insertions(+), 223 deletions(-) delete mode 100644 src/main/java/org/springframework/samples/mvc/Application.java delete mode 100644 src/main/java/org/springframework/samples/mvc/config/WebConfig.java delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/log4j.xml create mode 100644 src/main/webapp/WEB-INF/spring/appServlet/controllers.xml create mode 100644 src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml create mode 100644 src/main/webapp/WEB-INF/spring/root-context.xml create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/test/resources/log4j.xml diff --git a/pom.xml b/pom.xml index 975de3093..127445420 100644 --- a/pom.xml +++ b/pom.xml @@ -7,38 +7,139 @@ spring-mvc-showcase war 1.0.0-BUILD-SNAPSHOT - - - org.springframework.boot - spring-boot-dependencies - 1.5.1.RELEASE - - - 1.8 - UTF-8 - false + 1.7 + 4.3.6.RELEASE + 4.2.1.RELEASE + 1.8.9 + 1.7.22 - org.springframework.boot - spring-boot-starter-web + org.springframework + spring-context + ${org.springframework-version} + + + + commons-logging + commons-logging + + + + + org.springframework + spring-webmvc + ${org.springframework-version} + + + + org.aspectj + aspectjrt + ${org.aspectj-version} + + + + + org.slf4j + slf4j-api + ${org.slf4j-version} + + + org.slf4j + jcl-over-slf4j + ${org.slf4j-version} + runtime + + + org.slf4j + slf4j-log4j12 + ${org.slf4j-version} + runtime + + + log4j + log4j + 1.2.17 + runtime + + + + + javax.inject + javax.inject + 1 + + - org.springframework.boot - spring-boot-starter-aop + org.apache.tomcat + tomcat-servlet-api + 7.0.30 + provided - org.springframework.boot - spring-boot-starter-security + javax.servlet.jsp + jsp-api + 2.1 + provided + + javax.servlet.jsp.jstl + jstl-api + 1.2 + + + javax.servlet + servlet-api + + + + + org.glassfish.web + jstl-impl + 1.2 + + + javax.servlet + servlet-api + + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.8.6 + + com.rometools rome 1.7.1 + + + + javax.validation + validation-api + 1.0.0.GA + + + org.hibernate + hibernate-validator + 4.1.0.Final + + + + + joda-time + joda-time + 2.9.7 + @@ -52,57 +153,78 @@ 2.5 - + - joda-time - joda-time + org.springframework.security + spring-security-web + ${org.springframework.security-version} - - + + - org.apache.tomcat.embed - tomcat-embed-jasper + org.springframework + spring-test + ${org.springframework-version} + test - javax.servlet - jstl + junit + junit + 4.12 + test - - org.springframework.boot - spring-boot-devtools - true + xmlunit + xmlunit + 1.6 + test - - org.springframework.boot - spring-boot-starter-test + com.jayway.jsonpath + json-path + 2.2.0 test - xmlunit - xmlunit - 1.6 + org.hamcrest + hamcrest-library + 1.3 test + + + + org.springframework.maven.snapshot + Spring Maven Snapshot Repository + http://repo.spring.io/snapshot + false + true + + + + org.springframework.maven.milestone + Spring Maven Milestone Repository + http://repo.spring.io/milestone + false + + ${project.artifactId} - - org.springframework.boot - spring-boot-maven-plugin - org.apache.maven.plugins maven-compiler-plugin + 2.3.2 - ${java.version} - ${java.version} + ${java-version} + ${java-version} + org.apache.maven.plugins maven-surefire-plugin + 2.12 **/*Tests.java @@ -114,6 +236,66 @@ -Xmx512m + + org.apache.maven.plugins + maven-dependency-plugin + + + install + install + + sources + + + + + + org.codehaus.mojo + aspectj-maven-plugin + + 1.2 + + + + org.aspectj + aspectjrt + ${org.aspectj-version} + + + org.aspectj + aspectjtools + ${org.aspectj-version} + + + + + + compile + test-compile + + + + + true + ${java-version} + ${java-version} + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + + org.eclipse.jetty + jetty-maven-plugin + 9.0.6.v20130930 + + + /${project.artifactId} + + + diff --git a/src/main/java/org/springframework/samples/mvc/Application.java b/src/main/java/org/springframework/samples/mvc/Application.java deleted file mode 100644 index d05c72b0d..000000000 --- a/src/main/java/org/springframework/samples/mvc/Application.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.springframework.samples.mvc; - -import org.springframework.boot.Banner; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; - -@SpringBootApplication -public class Application extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { - return configureApplication(builder); - } - - public static void main(String[] args) { - configureApplication(new SpringApplicationBuilder()).run(args); - } - - private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) { - return builder.sources(Application.class).bannerMode(Banner.Mode.OFF); - } - -} diff --git a/src/main/java/org/springframework/samples/mvc/config/WebConfig.java b/src/main/java/org/springframework/samples/mvc/config/WebConfig.java deleted file mode 100644 index c44add95f..000000000 --- a/src/main/java/org/springframework/samples/mvc/config/WebConfig.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.springframework.samples.mvc.config; - -import java.util.List; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.format.FormatterRegistry; -import org.springframework.samples.mvc.async.TimeoutCallableProcessingInterceptor; -import org.springframework.samples.mvc.convert.MaskFormatAnnotationFormatterFactory; -import org.springframework.samples.mvc.data.custom.CustomArgumentResolver; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.multipart.MultipartResolver; -import org.springframework.web.multipart.commons.CommonsMultipartResolver; -import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; -import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.springframework.web.util.UrlPathHelper; - -@Configuration -@EnableScheduling -public class WebConfig extends WebMvcConfigurerAdapter -{ - /* In order to enable Spring MVC Matrix Variables */ - @Override - public void configurePathMatch(PathMatchConfigurer configurer) - { - UrlPathHelper urlPathHelper = new UrlPathHelper(); - urlPathHelper.setRemoveSemicolonContent(false); - configurer.setUrlPathHelper(urlPathHelper); - } - - @Override - public void addViewControllers(ViewControllerRegistry registry) - { - registry.addViewController("/home").setViewName("home"); - registry.addRedirectViewController("/", "/home"); - super.addViewControllers(registry); - } - - @Override - public void addArgumentResolvers( - List argumentResolvers) - { - // equivalent to - argumentResolvers.add(new CustomArgumentResolver()); - } - - @Override - public void configureAsyncSupport(AsyncSupportConfigurer configurer) - { - super.configureAsyncSupport(configurer); - configurer.registerCallableInterceptors(timeoutInterceptor()); - } - - /* - * Only needed because we install custom converters to support the examples in the - * org.springframewok.samples.mvc.convert package - */ - @Override - public void addFormatters(FormatterRegistry registry) - { - registry.addFormatterForFieldAnnotation( - new MaskFormatAnnotationFormatterFactory()); - } - - @Bean - public TimeoutCallableProcessingInterceptor timeoutInterceptor() - { - return new TimeoutCallableProcessingInterceptor(); - } - - /* - * Only needed because we require fileupload in the - * org.springframework.samples.mvc.fileupload package - */ - @Bean - public MultipartResolver multipartResolver() - { - return new CommonsMultipartResolver(); - } - -} diff --git a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java index 66eb808b2..c34470592 100644 --- a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java +++ b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java @@ -1,45 +1,47 @@ -package org.springframework.samples.mvc.redirect; - -import java.time.LocalDate; - -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; -import org.springframework.web.util.UriComponents; -import org.springframework.web.util.UriComponentsBuilder; - -@Controller -@RequestMapping("/redirect") -public class RedirectController { - - private final ConversionService conversionService; - - public RedirectController(ConversionService conversionService) { - this.conversionService = conversionService; - } - - @RequestMapping(value="/uriTemplate", method=RequestMethod.GET) - public String uriTemplate(RedirectAttributes redirectAttrs) { - redirectAttrs.addAttribute("account", "a123"); // Used as URI template variable - redirectAttrs.addAttribute("date", LocalDate.of(2011, 12, 31)); // Appended as a query parameter - return "redirect:/redirect/{account}"; - } - - @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET) - public String uriComponentsBuilder() { - String date = this.conversionService.convert(LocalDate.of(2011, 12, 31), String.class); - UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date) - .build().expand("a123").encode(); - return "redirect:" + redirectUri.toUriString(); - } - - @RequestMapping(value="/{account}", method=RequestMethod.GET) - public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) { - return "redirect/redirectResults"; - } - -} +package org.springframework.samples.mvc.redirect; + +import javax.inject.Inject; + +import org.joda.time.LocalDate; +import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; + +@Controller +@RequestMapping("/redirect") +public class RedirectController { + + private final ConversionService conversionService; + + @Inject + public RedirectController(ConversionService conversionService) { + this.conversionService = conversionService; + } + + @RequestMapping(value="/uriTemplate", method=RequestMethod.GET) + public String uriTemplate(RedirectAttributes redirectAttrs) { + redirectAttrs.addAttribute("account", "a123"); // Used as URI template variable + redirectAttrs.addAttribute("date", new LocalDate(2011, 12, 31)); // Appended as a query parameter + return "redirect:/redirect/{account}"; + } + + @RequestMapping(value="/uriComponentsBuilder", method=RequestMethod.GET) + public String uriComponentsBuilder() { + String date = this.conversionService.convert(new LocalDate(2011, 12, 31), String.class); + UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date) + .build().expand("a123").encode(); + return "redirect:" + redirectUri.toUriString(); + } + + @RequestMapping(value="/{account}", method=RequestMethod.GET) + public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) { + return "redirect/redirectResults"; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index c8648a877..000000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,10 +0,0 @@ -spring.mvc.view.prefix=/WEB-INF/views/ -spring.mvc.view.suffix=.jsp -spring.mvc.async.request-timeout=3000 - -security.user.password=password - -logging.level.org.springframework.samples=debug -logging.level.org.springframework.http=debug -logging.level.org.springframework.web=debug -logging.level.root=warn \ No newline at end of file diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml new file mode 100644 index 000000000..5439a479f --- /dev/null +++ b/src/main/resources/log4j.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml b/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml new file mode 100644 index 000000000..56dba6e8c --- /dev/null +++ b/src/main/webapp/WEB-INF/spring/appServlet/controllers.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml new file mode 100644 index 000000000..eb46e018b --- /dev/null +++ b/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml new file mode 100644 index 000000000..2c734abb4 --- /dev/null +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..d30ed1778 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,49 @@ + + + + + contextConfigLocation + /WEB-INF/spring/root-context.xml + + + + + org.springframework.web.context.ContextLoaderListener + + + + csrfFilter + org.springframework.web.filter.DelegatingFilterProxy + true + + + csrfFilter + /* + + + + + appServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + /WEB-INF/spring/appServlet/servlet-context.xml + + 1 + true + + + + appServlet + / + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java index 463c6edda..c2116dac8 100644 --- a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java @@ -1,15 +1,15 @@ -package org.springframework.samples.mvc; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.web.context.WebApplicationContext; - -@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) -//@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml") -public class AbstractContextControllerTests { - - @Autowired - protected WebApplicationContext wac; - -} +package org.springframework.samples.mvc; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.context.WebApplicationContext; + +@WebAppConfiguration +@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml") +public class AbstractContextControllerTests { + + @Autowired + protected WebApplicationContext wac; + +} diff --git a/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java b/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java index 5484657cf..085801768 100644 --- a/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/async/CallableControllerTests.java @@ -37,7 +37,7 @@ public void responseBody() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=UTF-8")) + .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) .andExpect(content().string("Callable result")); } @@ -64,7 +64,7 @@ public void exception() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=UTF-8")) + .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) .andExpect(content().string("Handled exception: Callable error")); } diff --git a/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java b/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java index 1fd83bb56..3753add81 100644 --- a/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/async/DeferredResultControllerTests.java @@ -39,7 +39,7 @@ public void responseBody() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=UTF-8")) + .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) .andExpect(content().string("Deferred result")); } @@ -67,7 +67,7 @@ public void exception() throws Exception { this.mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) - .andExpect(content().contentType("text/plain;charset=UTF-8")) + .andExpect(content().contentType("text/plain;charset=ISO-8859-1")) .andExpect(content().string("Handled exception: DeferredResult error")); } diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml new file mode 100644 index 000000000..7620a1676 --- /dev/null +++ b/src/test/resources/log4j.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +