diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..a3339d120 --- /dev/null +++ b/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2015-Present Pivotal Software Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/README.md b/README.md index d0f5de48f..1b9da2dbb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# spring-mvc-showcase is no longer actively maintained by VMware, Inc. + Spring MVC Showcase ------------------- Demonstrates the capabilities of the Spring MVC web framework through small, simple examples. @@ -24,27 +26,20 @@ Clone the repository: $ git clone git://github.com/SpringSource/spring-mvc-showcase.git -If this is your first time using Github, review http://help.github.com to learn the basics. +If this is your first time using Github, review https://help.github.com to learn the basics. To run the application: ------------------- From the command line with Maven: $ cd spring-mvc-showcase - $ mvn tomcat7:run [-Dmaven.tomcat.port=] (In case 8080 is busy] - -or - -In your preferred IDE such as SpringSource Tool Suite (STS) or IDEA: - -* Import spring-mvc-showcase as a Maven Project -* Drag-n-drop the project onto the "SpringSource tc Server Developer Edition" or another Servlet 2.5 or > Server to run, such as Tomcat. + $ mvn jetty:run Access the deployed web application at: http://localhost:8080/spring-mvc-showcase/ Note: ------------------- -This showcase originated from a [blog post](http://blog.springsource.com/2010/07/22/spring-mvc-3-showcase/) and was adapted into a SpringOne presentation called [Mastering MVC 3](http://www.infoq.com/presentations/Mastering-Spring-MVC-3). +This showcase originated from a [blog post](https://spring.io/blog/2010/07/22/spring-mvc-3-showcase/) and was adapted into a SpringOne presentation called [Mastering MVC 3](https://www.infoq.com/presentations/Mastering-Spring-MVC-3). A screen cast showing the showcase in action is [available in QuickTime format](http://s3.springsource.org/MVC/mvc-showcase-screencast.mov). diff --git a/pom.xml b/pom.xml index 7268aff9a..900d42021 100644 --- a/pom.xml +++ b/pom.xml @@ -1,38 +1,39 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.springframework.samples spring-mvc-showcase spring-mvc-showcase war 1.0.0-BUILD-SNAPSHOT + - 1.7 - 4.1.0.RELEASE - 3.2.0.RELEASE + 1.8 + 5.0.4.RELEASE 1.8.1 - 1.6.1 + org.springframework spring-context ${org.springframework-version} - - - - commons-logging - commons-logging - - org.springframework spring-webmvc ${org.springframework-version} + + + + org.springframework.security + spring-security-web + 5.0.0.RELEASE + + org.aspectj @@ -42,27 +43,14 @@ - org.slf4j - slf4j-api - ${org.slf4j-version} + org.apache.logging.log4j + log4j-core + LATEST - org.slf4j - jcl-over-slf4j - ${org.slf4j-version} - runtime - - - org.slf4j - slf4j-log4j12 - ${org.slf4j-version} - runtime - - - log4j - log4j - 1.2.16 - runtime + org.apache.logging.log4j + log4j-slf4j-impl + LATEST @@ -72,93 +60,80 @@ 1 - + - org.apache.tomcat - tomcat-servlet-api - 7.0.30 + javax.servlet + javax.servlet-api + 3.1.0 provided javax.servlet.jsp - jsp-api - 2.1 + javax.servlet.jsp-api + 2.3.2-b02 provided - javax.servlet.jsp.jstl - jstl-api - 1.2 - - - javax.servlet - servlet-api - - - - - org.glassfish.web - jstl-impl + javax.servlet + jstl 1.2 - - - javax.servlet - servlet-api - - com.fasterxml.jackson.core jackson-databind - 2.4.1 + 2.9.3 com.rometools rome - 1.5.0 + 1.9.0 javax.validation validation-api - 1.0.0.GA + 2.0.1.Final - org.hibernate + org.hibernate.validator hibernate-validator - 4.1.0.Final + 6.0.7.Final - + + javax.el + javax.el-api + 3.0.1-b04 + + + org.glassfish + javax.el + 3.0.1-b08 + + joda-time joda-time - 2.3 + 2.9.9 commons-fileupload commons-fileupload - 1.2.2 + 1.3.3 commons-io commons-io - 2.0.1 + 2.5 - - - org.springframework.security - spring-security-web - ${org.springframework.security-version} - @@ -170,19 +145,19 @@ junit junit - 4.11 + 4.12 test - xmlunit - xmlunit - 1.2 + org.xmlunit + xmlunit-matchers + 2.5.1 test com.jayway.jsonpath json-path - 0.8.1 + 2.4.0 test @@ -192,39 +167,30 @@ 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 + 3.7.0 ${java-version} ${java-version} + + org.apache.maven.plugins + maven-war-plugin + + false + + org.apache.maven.plugins maven-surefire-plugin - 2.12 + 2.20.1 **/*Tests.java @@ -252,10 +218,8 @@ org.codehaus.mojo aspectj-maven-plugin - - 1.2 + 1.11 - org.aspectj aspectjrt @@ -270,26 +234,22 @@ - compile - test-compile + compile + test-compile true + ${java-version} ${java-version} ${java-version} - - org.apache.tomcat.maven - tomcat7-maven-plugin - 2.2 - org.eclipse.jetty jetty-maven-plugin - 9.0.6.v20130930 + 9.4.8.v20171121 /${project.artifactId} diff --git a/src/main/java/org/springframework/samples/mvc/async/CallableController.java b/src/main/java/org/springframework/samples/mvc/async/CallableController.java index 4ea6ec86a..0fa649434 100644 --- a/src/main/java/org/springframework/samples/mvc/async/CallableController.java +++ b/src/main/java/org/springframework/samples/mvc/async/CallableController.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -15,7 +16,7 @@ public class CallableController { - @RequestMapping("/response-body") + @GetMapping("/response-body") public @ResponseBody Callable callable() { return new Callable() { @@ -27,50 +28,38 @@ public String call() throws Exception { }; } - @RequestMapping("/view") + @GetMapping("/view") public Callable callableWithView(final Model model) { - - return new Callable() { - @Override - public String call() throws Exception { - Thread.sleep(2000); - model.addAttribute("foo", "bar"); - model.addAttribute("fruit", "apple"); - return "views/html"; - } + return () -> { + Thread.sleep(2000); + model.addAttribute("foo", "bar"); + model.addAttribute("fruit", "apple"); + return "views/html"; }; } - @RequestMapping("/exception") + @GetMapping("/exception") public @ResponseBody Callable callableWithException( final @RequestParam(required=false, defaultValue="true") boolean handled) { - return new Callable() { - @Override - public String call() throws Exception { - Thread.sleep(2000); - if (handled) { - // see handleException method further below - throw new IllegalStateException("Callable error"); - } - else { - throw new IllegalArgumentException("Callable error"); - } + return () -> { + Thread.sleep(2000); + if (handled) { + // see handleException method further below + throw new IllegalStateException("Callable error"); + } + else { + throw new IllegalArgumentException("Callable error"); } }; } - @RequestMapping("/custom-timeout-handling") + @GetMapping("/custom-timeout-handling") public @ResponseBody WebAsyncTask callableWithCustomTimeoutHandling() { - - Callable callable = new Callable() { - @Override - public String call() throws Exception { - Thread.sleep(2000); - return "Callable result"; - } + Callable callable = () -> { + Thread.sleep(2000); + return "Callable result"; }; - return new WebAsyncTask(1000, callable); } diff --git a/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java b/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java index 51b8e6d6a..41edfe72b 100644 --- a/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java +++ b/src/main/java/org/springframework/samples/mvc/async/DeferredResultController.java @@ -6,6 +6,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.context.request.async.DeferredResult; @@ -15,41 +16,41 @@ @RequestMapping("/async") public class DeferredResultController { - private final Queue> responseBodyQueue = new ConcurrentLinkedQueue>(); + private final Queue> responseBodyQueue = new ConcurrentLinkedQueue<>(); - private final Queue> mavQueue = new ConcurrentLinkedQueue>(); + private final Queue> mavQueue = new ConcurrentLinkedQueue<>(); - private final Queue> exceptionQueue = new ConcurrentLinkedQueue>(); + private final Queue> exceptionQueue = new ConcurrentLinkedQueue<>(); - @RequestMapping("/deferred-result/response-body") + @GetMapping("/deferred-result/response-body") public @ResponseBody DeferredResult deferredResult() { - DeferredResult result = new DeferredResult(); + DeferredResult result = new DeferredResult<>(); this.responseBodyQueue.add(result); return result; } - @RequestMapping("/deferred-result/model-and-view") + @GetMapping("/deferred-result/model-and-view") public DeferredResult deferredResultWithView() { - DeferredResult result = new DeferredResult(); + DeferredResult result = new DeferredResult<>(); this.mavQueue.add(result); return result; } - @RequestMapping("/deferred-result/exception") + @GetMapping("/deferred-result/exception") public @ResponseBody DeferredResult deferredResultWithException() { - DeferredResult result = new DeferredResult(); + DeferredResult result = new DeferredResult<>(); this.exceptionQueue.add(result); return result; } - @RequestMapping("/deferred-result/timeout-value") + @GetMapping("/deferred-result/timeout-value") public @ResponseBody DeferredResult deferredResultWithTimeoutValue() { // Provide a default result in case of timeout and override the timeout value // set in src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml - return new DeferredResult(1000L, "Deferred result after timeout"); + return new DeferredResult<>(1000L, "Deferred result after timeout"); } @Scheduled(fixedRate=2000) diff --git a/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java b/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java index 5eee8c583..c5440d63c 100644 --- a/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java +++ b/src/main/java/org/springframework/samples/mvc/async/TimeoutCallableProcessingInterceptor.java @@ -8,7 +8,7 @@ public class TimeoutCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter { @Override - public Object handleTimeout(NativeWebRequest request, Callable task) throws Exception { + public Object handleTimeout(NativeWebRequest request, Callable task) { throw new IllegalStateException("[" + task.getClass().getName() + "] timed out"); } diff --git a/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java b/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java new file mode 100644 index 000000000..f0c83853b --- /dev/null +++ b/src/main/java/org/springframework/samples/mvc/config/MvcShowcaseAppInitializer.java @@ -0,0 +1,34 @@ +package org.springframework.samples.mvc.config; + +import javax.servlet.Filter; + +import org.springframework.web.filter.DelegatingFilterProxy; +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +/** + * Initialize the Servlet container. This class is detected by the Servlet + * container on startup. + */ +public class MvcShowcaseAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{ + + @Override + protected Class[] getRootConfigClasses() { + return new Class[] { RootConfig.class }; + } + + @Override + protected Class[] getServletConfigClasses() { + return new Class[] { WebMvcConfig.class }; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } + + @Override + protected Filter[] getServletFilters() { + return new Filter[] { new DelegatingFilterProxy("csrfFilter") }; + } + +} diff --git a/src/main/java/org/springframework/samples/mvc/config/RootConfig.java b/src/main/java/org/springframework/samples/mvc/config/RootConfig.java new file mode 100644 index 000000000..449d95e7f --- /dev/null +++ b/src/main/java/org/springframework/samples/mvc/config/RootConfig.java @@ -0,0 +1,31 @@ +package org.springframework.samples.mvc.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.web.csrf.CsrfFilter; +import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository; +import org.springframework.security.web.servlet.support.csrf.CsrfRequestDataValueProcessor; +import org.springframework.web.servlet.support.RequestDataValueProcessor; + +// Root Context: defines shared resources visible to all other web components + +@Configuration +public class RootConfig { + + // CSRF protection. Here we only include the CsrfFilter instead of all of Spring Security. + // See https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf + // for more information on Spring Security's CSRF protection + + @Bean + public CsrfFilter csrfFilter() { + return new CsrfFilter(new HttpSessionCsrfTokenRepository()); + } + + // Provides automatic CSRF token inclusion when using Spring MVC Form tags or Thymeleaf. + // See http://localhost:8080/#forms and form.jsp for examples + + @Bean + public RequestDataValueProcessor requestDataValueProcessor() { + return new CsrfRequestDataValueProcessor(); + } +} diff --git a/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java b/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java new file mode 100644 index 000000000..b73729309 --- /dev/null +++ b/src/main/java/org/springframework/samples/mvc/config/WebMvcConfig.java @@ -0,0 +1,80 @@ +package org.springframework.samples.mvc.config; + +import java.util.List; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +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.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.util.UrlPathHelper; + +// DispatcherServlet context: defines Spring MVC infrastructure +// and web application components + +@Configuration +@ComponentScan(basePackages = "org.springframework.samples.mvc") +@EnableWebMvc +@EnableScheduling +public class WebMvcConfig implements WebMvcConfigurer { + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addFormatterForFieldAnnotation(new MaskFormatAnnotationFormatterFactory()); + } + + @Override + public void addArgumentResolvers(List resolvers) { + resolvers.add(new CustomArgumentResolver()); + } + + // Handle HTTP GET requests for /resources/** by efficiently serving + // static resources under ${webappRoot}/resources/ + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("home"); + } + + @Override + public void configureViewResolvers(ViewResolverRegistry registry) { + registry.jsp("/WEB-INF/views/", ".jsp"); + } + + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + UrlPathHelper pathHelper = new UrlPathHelper(); + pathHelper.setRemoveSemicolonContent(false); // For @MatrixVariable's + configurer.setUrlPathHelper(pathHelper); + } + + @Override + public void configureAsyncSupport(AsyncSupportConfigurer configurer) { + configurer.setDefaultTimeout(3000); + configurer.registerCallableInterceptors(new TimeoutCallableProcessingInterceptor()); + } + + @Bean + public MultipartResolver multipartResolver() { + return new CommonsMultipartResolver(); + } + +} diff --git a/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java b/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java index 2db688250..09da254ab 100644 --- a/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java +++ b/src/main/java/org/springframework/samples/mvc/convert/ConvertController.java @@ -5,49 +5,49 @@ import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping("/convert") public class ConvertController { - @RequestMapping("primitive") - public @ResponseBody String primitive(@RequestParam Integer value) { + @GetMapping("primitive") + public String primitive(@RequestParam Integer value) { return "Converted primitive " + value; } // requires Joda-Time on the classpath - @RequestMapping("date/{value}") - public @ResponseBody String date(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date value) { + @GetMapping("date/{value}") + public String date(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date value) { return "Converted date " + value; } - @RequestMapping("collection") - public @ResponseBody String collection(@RequestParam Collection values) { + @GetMapping("collection") + public String collection(@RequestParam Collection values) { return "Converted collection " + values; } - @RequestMapping("formattedCollection") - public @ResponseBody String formattedCollection(@RequestParam @DateTimeFormat(iso=ISO.DATE) Collection values) { + @GetMapping("formattedCollection") + public String formattedCollection(@RequestParam @DateTimeFormat(iso=ISO.DATE) Collection values) { return "Converted formatted collection " + values; } - @RequestMapping("bean") - public @ResponseBody String bean(JavaBean bean) { + @GetMapping("bean") + public String bean(JavaBean bean) { return "Converted " + bean; } - @RequestMapping("value") - public @ResponseBody String valueObject(@RequestParam SocialSecurityNumber value) { + @GetMapping("value") + public String valueObject(@RequestParam SocialSecurityNumber value) { return "Converted value object " + value; } - @RequestMapping("custom") - public @ResponseBody String customConverter(@RequestParam @MaskFormat("###-##-####") String value) { + @GetMapping("custom") + public String customConverter(@RequestParam @MaskFormat("###-##-####") String value) { return "Converted '" + value + "' with a custom converter"; } diff --git a/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java b/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java index 5919e7cf9..9d0b7e99c 100644 --- a/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java +++ b/src/main/java/org/springframework/samples/mvc/data/RequestDataController.java @@ -1,67 +1,67 @@ package org.springframework.samples.mvc.data; import org.springframework.http.HttpEntity; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.MatrixVariable; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; 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.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping("/data") public class RequestDataController { - @RequestMapping(value="param", method=RequestMethod.GET) - public @ResponseBody String withParam(@RequestParam String foo) { + @GetMapping("param") + public String withParam(@RequestParam String foo) { return "Obtained 'foo' query parameter value '" + foo + "'"; } - @RequestMapping(value="group", method=RequestMethod.GET) - public @ResponseBody String withParamGroup(JavaBean bean) { + @GetMapping("group") + public String withParamGroup(JavaBean bean) { return "Obtained parameter group " + bean; } - @RequestMapping(value="path/{var}", method=RequestMethod.GET) - public @ResponseBody String withPathVariable(@PathVariable String var) { + @GetMapping("path/{var}") + public String withPathVariable(@PathVariable String var) { return "Obtained 'var' path variable value '" + var + "'"; } - @RequestMapping(value="{path}/simple", method=RequestMethod.GET) - public @ResponseBody String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) { + @GetMapping("{path}/simple") + public String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) { return "Obtained matrix variable 'foo=" + foo + "' from path segment '" + path + "'"; } - @RequestMapping(value="{path1}/{path2}", method=RequestMethod.GET) - public @ResponseBody String withMatrixVariablesMultiple ( - @PathVariable String path1, @MatrixVariable(value="foo", pathVar="path1") String foo1, - @PathVariable String path2, @MatrixVariable(value="foo", pathVar="path2") String foo2) { + @GetMapping("{path1}/{path2}") + public String withMatrixVariablesMultiple ( + @PathVariable String path1, @MatrixVariable(name="foo", pathVar="path1") String foo1, + @PathVariable String path2, @MatrixVariable(name="foo", pathVar="path2") String foo2) { return "Obtained matrix variable foo=" + foo1 + " from path segment '" + path1 + "' and variable 'foo=" + foo2 + " from path segment '" + path2 + "'"; } - @RequestMapping(value="header", method=RequestMethod.GET) - public @ResponseBody String withHeader(@RequestHeader String Accept) { + @GetMapping("header") + public String withHeader(@RequestHeader String Accept) { return "Obtained 'Accept' header '" + Accept + "'"; } - @RequestMapping(value="cookie", method=RequestMethod.GET) - public @ResponseBody String withCookie(@CookieValue String openid_provider) { + @GetMapping("cookie") + public String withCookie(@CookieValue String openid_provider) { return "Obtained 'openid_provider' cookie '" + openid_provider + "'"; } - @RequestMapping(value="body", method=RequestMethod.POST) - public @ResponseBody String withBody(@RequestBody String body) { + @PostMapping("body") + public String withBody(@RequestBody String body) { return "Posted request body '" + body + "'"; } - @RequestMapping(value="entity", method=RequestMethod.POST) - public @ResponseBody String withEntity(HttpEntity entity) { + @PostMapping("entity") + public String withEntity(HttpEntity entity) { return "Posted request body '" + entity.getBody() + "'; headers = " + entity.getHeaders(); } diff --git a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java index 3f3d4748b..66368fa34 100644 --- a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java +++ b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentController.java @@ -2,13 +2,11 @@ import javax.servlet.http.HttpServletRequest; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class CustomArgumentController { @ModelAttribute @@ -16,8 +14,8 @@ void beforeInvokingHandlerMethod(HttpServletRequest request) { request.setAttribute("foo", "bar"); } - @RequestMapping(value="/data/custom", method=RequestMethod.GET) - public @ResponseBody String custom(@RequestAttribute("foo") String foo) { + @GetMapping("/data/custom") + public String custom(@RequestAttribute("foo") String foo) { return "Got 'foo' request attribute value '" + foo + "'"; } diff --git a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java index ed1b02fcc..59ba7fbf6 100644 --- a/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java +++ b/src/main/java/org/springframework/samples/mvc/data/custom/CustomArgumentResolver.java @@ -13,8 +13,10 @@ public boolean supportsParameter(MethodParameter parameter) { return parameter.getParameterAnnotation(RequestAttribute.class) != null; } - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, - WebDataBinderFactory binderFactory) throws Exception { + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) + throws Exception { + RequestAttribute attr = parameter.getParameterAnnotation(RequestAttribute.class); return webRequest.getAttribute(attr.value(), WebRequest.SCOPE_REQUEST); } diff --git a/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java b/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java index 4059b7f10..c5276ae91 100644 --- a/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java +++ b/src/main/java/org/springframework/samples/mvc/data/standard/StandardArgumentsController.java @@ -7,24 +7,22 @@ import java.io.Writer; import java.security.Principal; import java.util.Locale; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.springframework.stereotype.Controller; import org.springframework.util.FileCopyUtils; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class StandardArgumentsController { // request related - @RequestMapping(value="/data/standard/request", method=RequestMethod.GET) - public @ResponseBody String standardRequestArgs(HttpServletRequest request, Principal user, Locale locale) { + @GetMapping("/data/standard/request") + public String standardRequestArgs(HttpServletRequest request, Principal user, Locale locale) { StringBuilder buffer = new StringBuilder(); buffer.append("request = ").append(request).append(", "); buffer.append("userPrincipal = ").append(user).append(", "); @@ -32,37 +30,37 @@ public class StandardArgumentsController { return buffer.toString(); } - @RequestMapping(value="/data/standard/request/reader", method=RequestMethod.POST) - public @ResponseBody String requestReader(Reader requestBodyReader) throws IOException { + @PostMapping("/data/standard/request/reader") + public String requestReader(Reader requestBodyReader) throws IOException { return "Read char request body = " + FileCopyUtils.copyToString(requestBodyReader); } - @RequestMapping(value="/data/standard/request/is", method=RequestMethod.POST) - public @ResponseBody String requestReader(InputStream requestBodyIs) throws IOException { + @PostMapping("/data/standard/request/is") + public String requestReader(InputStream requestBodyIs) throws IOException { return "Read binary request body = " + new String(FileCopyUtils.copyToByteArray(requestBodyIs)); } // response related - @RequestMapping("/data/standard/response") - public @ResponseBody String response(HttpServletResponse response) { + @GetMapping("/data/standard/response") + public String response(HttpServletResponse response) { return "response = " + response; } - @RequestMapping("/data/standard/response/writer") + @GetMapping("/data/standard/response/writer") public void availableStandardResponseArguments(Writer responseWriter) throws IOException { responseWriter.write("Wrote char response using Writer"); } - @RequestMapping("/data/standard/response/os") + @GetMapping("/data/standard/response/os") public void availableStandardResponseArguments(OutputStream os) throws IOException { os.write("Wrote binary response using OutputStream".getBytes()); } // HttpSession - @RequestMapping("/data/standard/session") - public @ResponseBody String session(HttpSession session) { + @GetMapping("/data/standard/session") + public String session(HttpSession session) { StringBuilder buffer = new StringBuilder(); buffer.append("session=").append(session); return buffer.toString(); diff --git a/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java b/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java index 8db32b5b0..7b3e0d616 100644 --- a/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java +++ b/src/main/java/org/springframework/samples/mvc/exceptions/ExceptionController.java @@ -1,25 +1,24 @@ package org.springframework.samples.mvc.exceptions; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class ExceptionController { - @RequestMapping("/exception") - public @ResponseBody String exception() { + @GetMapping("/exception") + public String exception() { throw new IllegalStateException("Sorry!"); } - @RequestMapping("/global-exception") - public @ResponseBody String businessException() throws BusinessException { + @GetMapping("/global-exception") + public String businessException() throws BusinessException { throw new BusinessException(); } @ExceptionHandler - public @ResponseBody String handle(IllegalStateException e) { + public String handle(IllegalStateException e) { return "IllegalStateException handled!"; } diff --git a/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java b/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java index f50339790..10d5da8ce 100644 --- a/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java +++ b/src/main/java/org/springframework/samples/mvc/exceptions/GlobalExceptionHandler.java @@ -1,14 +1,13 @@ package org.springframework.samples.mvc.exceptions; -import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestControllerAdvice; -@ControllerAdvice +@RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler - public @ResponseBody String handleBusinessException(BusinessException ex) { + public String handleBusinessException(BusinessException ex) { return "Handled BusinessException"; } diff --git a/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java b/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java index b7eda699d..b49489a3c 100644 --- a/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java +++ b/src/main/java/org/springframework/samples/mvc/fileupload/FileUploadController.java @@ -1,13 +1,12 @@ package org.springframework.samples.mvc.fileupload; -import java.io.IOException; - import org.springframework.mvc.extensions.ajax.AjaxUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; 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.context.request.WebRequest; import org.springframework.web.multipart.MultipartFile; @@ -21,12 +20,12 @@ public void ajaxAttribute(WebRequest request, Model model) { model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(request)); } - @RequestMapping(method=RequestMethod.GET) + @GetMapping public void fileUploadForm() { } - @RequestMapping(method=RequestMethod.POST) - public void processUpload(@RequestParam MultipartFile file, Model model) throws IOException { + @PostMapping + public void processUpload(@RequestParam MultipartFile file, Model model) { model.addAttribute("message", "File '" + file.getOriginalFilename() + "' uploaded successfully"); } diff --git a/src/main/java/org/springframework/samples/mvc/form/FormController.java b/src/main/java/org/springframework/samples/mvc/form/FormController.java index a5b396976..b5837b9fe 100644 --- a/src/main/java/org/springframework/samples/mvc/form/FormController.java +++ b/src/main/java/org/springframework/samples/mvc/form/FormController.java @@ -6,9 +6,10 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @@ -33,11 +34,11 @@ public FormBean createFormBean() { return new FormBean(); } - @RequestMapping(method=RequestMethod.GET) + @GetMapping public void form() { } - @RequestMapping(method=RequestMethod.POST) + @PostMapping public String processSubmit(@Valid FormBean formBean, BindingResult result, @ModelAttribute("ajaxRequest") boolean ajaxRequest, Model model, RedirectAttributes redirectAttrs) { diff --git a/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java b/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java index d131a9cf4..dafa6d1a3 100644 --- a/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java +++ b/src/main/java/org/springframework/samples/mvc/mapping/ClasslevelMappingController.java @@ -2,59 +2,59 @@ import javax.servlet.http.HttpServletRequest; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping("/class-mapping/*") public class ClasslevelMappingController { - @RequestMapping("/path") - public @ResponseBody String byPath() { + @GetMapping("/path") + public String byPath() { return "Mapped by path!"; } - @RequestMapping(value="/path/*", method=RequestMethod.GET) - public @ResponseBody String byPathPattern(HttpServletRequest request) { + @GetMapping("/path/*") + public String byPathPattern(HttpServletRequest request) { return "Mapped by path pattern ('" + request.getRequestURI() + "')"; } - @RequestMapping(value="/method", method=RequestMethod.GET) - public @ResponseBody String byMethod() { + @GetMapping("/method") + public String byMethod() { return "Mapped by path + method"; } - @RequestMapping(value="/parameter", method=RequestMethod.GET, params="foo") - public @ResponseBody String byParameter() { + @GetMapping(path="/parameter", params="foo") + public String byParameter() { return "Mapped by path + method + presence of query parameter!"; } - @RequestMapping(value="/parameter", method=RequestMethod.GET, params="!foo") - public @ResponseBody String byParameterNegation() { + @GetMapping(path="/parameter", params="!foo") + public String byParameterNegation() { return "Mapped by path + method + not presence of query!"; } - @RequestMapping(value="/header", method=RequestMethod.GET, headers="FooHeader=foo") - public @ResponseBody String byHeader() { + @GetMapping(path="/header", headers="FooHeader=foo") + public String byHeader() { return "Mapped by path + method + presence of header!"; } - @RequestMapping(value="/notheader", method=RequestMethod.GET, headers="!FooHeader") - public @ResponseBody String byHeaderNegation() { + @GetMapping(path="/notheader", headers="!FooHeader") + public String byHeaderNegation() { return "Mapped by path + method + absence of header!"; } - @RequestMapping(value="/consumes", method=RequestMethod.POST, consumes="application/json") - public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) { + @PostMapping(path="/consumes", consumes="application/json") + public String byConsumes(@RequestBody JavaBean javaBean) { return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')"; } - @RequestMapping(value="/produces", method=RequestMethod.GET, produces="application/json") - public @ResponseBody JavaBean byProduces() { + @GetMapping(path="/produces", produces="application/json") + public JavaBean byProduces() { return new JavaBean(); } diff --git a/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java b/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java index cbebdcbe2..823d9ad0b 100644 --- a/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java +++ b/src/main/java/org/springframework/samples/mvc/mapping/MappingController.java @@ -3,62 +3,61 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class MappingController { - @RequestMapping("/mapping/path") - public @ResponseBody String byPath() { + @GetMapping("/mapping/path") + public String byPath() { return "Mapped by path!"; } - @RequestMapping(value="/mapping/path/*", method=RequestMethod.GET) - public @ResponseBody String byPathPattern(HttpServletRequest request) { + @GetMapping("/mapping/path/*") + public String byPathPattern(HttpServletRequest request) { return "Mapped by path pattern ('" + request.getRequestURI() + "')"; } - @RequestMapping(value="/mapping/method", method=RequestMethod.GET) - public @ResponseBody String byMethod() { + @GetMapping("/mapping/method") + public String byMethod() { return "Mapped by path + method"; } - @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo") - public @ResponseBody String byParameter() { + @GetMapping(path="/mapping/parameter", params="foo") + public String byParameter() { return "Mapped by path + method + presence of query parameter!"; } - @RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="!foo") - public @ResponseBody String byParameterNegation() { + @GetMapping(path="/mapping/parameter", params="!foo") + public String byParameterNegation() { return "Mapped by path + method + not presence of query parameter!"; } - @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="FooHeader=foo") - public @ResponseBody String byHeader() { + @GetMapping(path="/mapping/header", headers="FooHeader=foo") + public String byHeader() { return "Mapped by path + method + presence of header!"; } - @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="!FooHeader") - public @ResponseBody String byHeaderNegation() { + @GetMapping(path="/mapping/header", headers="!FooHeader") + public String byHeaderNegation() { return "Mapped by path + method + absence of header!"; } - @RequestMapping(value="/mapping/consumes", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody String byConsumes(@RequestBody JavaBean javaBean) { + @PostMapping(path="/mapping/consumes", consumes=MediaType.APPLICATION_JSON_VALUE) + public String byConsumes(@RequestBody JavaBean javaBean) { return "Mapped by path + method + consumable media type (javaBean '" + javaBean + "')"; } - @RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody JavaBean byProducesJson() { + @GetMapping(path="/mapping/produces", produces=MediaType.APPLICATION_JSON_VALUE) + public JavaBean byProducesJson() { return new JavaBean(); } - @RequestMapping(value="/mapping/produces", method=RequestMethod.GET, produces=MediaType.APPLICATION_XML_VALUE) - public @ResponseBody JavaBean byProducesXml() { + @GetMapping(path="/mapping/produces", produces=MediaType.APPLICATION_XML_VALUE) + public JavaBean byProducesXml() { return new JavaBean(); } diff --git a/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java b/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java index 47da6ee95..780e67df5 100644 --- a/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java +++ b/src/main/java/org/springframework/samples/mvc/messageconverters/MessageConvertersController.java @@ -5,40 +5,41 @@ import com.rometools.rome.feed.atom.Feed; import com.rometools.rome.feed.rss.Channel; -import org.springframework.stereotype.Controller; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping("/messageconverters") public class MessageConvertersController { // StringHttpMessageConverter - @RequestMapping(value="/string", method=RequestMethod.POST) - public @ResponseBody String readString(@RequestBody String string) { + @PostMapping("/string") + public String readString(@RequestBody String string) { return "Read string '" + string + "'"; } - @RequestMapping(value="/string", method=RequestMethod.GET) - public @ResponseBody String writeString() { + @GetMapping("/string") + public String writeString() { return "Wrote a string"; } // Form encoded data (application/x-www-form-urlencoded) - @RequestMapping(value="/form", method=RequestMethod.POST) - public @ResponseBody String readForm(@ModelAttribute JavaBean bean) { + @PostMapping("/form") + public String readForm(@ModelAttribute JavaBean bean) { return "Read x-www-form-urlencoded: " + bean; } - @RequestMapping(value="/form", method=RequestMethod.GET) - public @ResponseBody MultiValueMap writeForm() { + @GetMapping("/form") + public MultiValueMap writeForm() { MultiValueMap map = new LinkedMultiValueMap(); map.add("foo", "bar"); map.add("fruit", "apple"); @@ -47,37 +48,37 @@ public class MessageConvertersController { // Jaxb2RootElementHttpMessageConverter (requires JAXB2 on the classpath - useful for serving clients that expect to work with XML) - @RequestMapping(value="/xml", method=RequestMethod.POST) - public @ResponseBody String readXml(@RequestBody JavaBean bean) { + @PostMapping("/xml") + public String readXml(@RequestBody JavaBean bean) { return "Read from XML: " + bean; } - @RequestMapping(value="/xml", method=RequestMethod.GET) - public @ResponseBody JavaBean writeXml() { + @GetMapping("/xml") + public JavaBean writeXml() { return new JavaBean("bar", "apple"); } // MappingJacksonHttpMessageConverter (requires Jackson on the classpath - particularly useful for serving JavaScript clients that expect to work with JSON) - @RequestMapping(value="/json", method=RequestMethod.POST) - public @ResponseBody String readJson(@Valid @RequestBody JavaBean bean) { + @PostMapping("/json") + public String readJson(@Valid @RequestBody JavaBean bean) { return "Read from JSON: " + bean; } - @RequestMapping(value="/json", method=RequestMethod.GET) - public @ResponseBody JavaBean writeJson() { + @GetMapping("/json") + public JavaBean writeJson() { return new JavaBean("bar", "apple"); } // AtomFeedHttpMessageConverter (requires Rome on the classpath - useful for serving Atom feeds) - @RequestMapping(value="/atom", method=RequestMethod.POST) - public @ResponseBody String readFeed(@RequestBody Feed feed) { + @PostMapping("/atom") + public String readFeed(@RequestBody Feed feed) { return "Read " + feed.getTitle(); } - @RequestMapping(value="/atom", method=RequestMethod.GET) - public @ResponseBody Feed writeFeed() { + @GetMapping("/atom") + public Feed writeFeed() { Feed feed = new Feed(); feed.setFeedType("atom_1.0"); feed.setTitle("My Atom feed"); @@ -86,13 +87,13 @@ public class MessageConvertersController { // RssChannelHttpMessageConverter (requires Rome on the classpath - useful for serving RSS feeds) - @RequestMapping(value="/rss", method=RequestMethod.POST) - public @ResponseBody String readChannel(@RequestBody Channel channel) { + @PostMapping("/rss") + public String readChannel(@RequestBody Channel channel) { return "Read " + channel.getTitle(); } - @RequestMapping(value="/rss", method=RequestMethod.GET) - public @ResponseBody Channel writeChannel() { + @GetMapping("/rss") + public Channel writeChannel() { Channel channel = new Channel(); channel.setFeedType("rss_2.0"); channel.setTitle("My RSS feed"); 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..174b6b68e 100644 --- a/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java +++ b/src/main/java/org/springframework/samples/mvc/redirect/RedirectController.java @@ -3,11 +3,12 @@ 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.GetMapping; 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; @@ -24,14 +25,14 @@ public RedirectController(ConversionService conversionService) { this.conversionService = conversionService; } - @RequestMapping(value="/uriTemplate", method=RequestMethod.GET) + @GetMapping("/uriTemplate") 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) + @GetMapping("/uriComponentsBuilder") public String uriComponentsBuilder() { String date = this.conversionService.convert(new LocalDate(2011, 12, 31), String.class); UriComponents redirectUri = UriComponentsBuilder.fromPath("/redirect/{account}").queryParam("date", date) @@ -39,7 +40,7 @@ public String uriComponentsBuilder() { return "redirect:" + redirectUri.toUriString(); } - @RequestMapping(value="/{account}", method=RequestMethod.GET) + @GetMapping("/{account}") public String show(@PathVariable String account, @RequestParam(required=false) LocalDate date) { return "redirect/redirectResults"; } diff --git a/src/main/java/org/springframework/samples/mvc/response/ResponseController.java b/src/main/java/org/springframework/samples/mvc/response/ResponseController.java index 22e15ff83..ef95195ac 100644 --- a/src/main/java/org/springframework/samples/mvc/response/ResponseController.java +++ b/src/main/java/org/springframework/samples/mvc/response/ResponseController.java @@ -4,37 +4,37 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping(value="/response", method=RequestMethod.GET) public class ResponseController { - @RequestMapping("/annotation") - public @ResponseBody String responseBody() { + @GetMapping("/annotation") + public String responseBody() { return "The String ResponseBody"; } - @RequestMapping("/charset/accept") - public @ResponseBody String responseAcceptHeaderCharset() { + @GetMapping("/charset/accept") + public String responseAcceptHeaderCharset() { return "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)"; } - @RequestMapping(value="/charset/produce", produces="text/plain;charset=UTF-8") - public @ResponseBody String responseProducesConditionCharset() { + @GetMapping(value="/charset/produce", produces="text/plain;charset=UTF-8") + public String responseProducesConditionCharset() { return "\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01 (\"Hello world!\" in Japanese)"; } - @RequestMapping("/entity/status") + @GetMapping("/entity/status") public ResponseEntity responseEntityStatusCode() { return new ResponseEntity("The String ResponseBody with custom status code (403 Forbidden)", HttpStatus.FORBIDDEN); } - @RequestMapping("/entity/headers") + @GetMapping("/entity/headers") public ResponseEntity responseEntityCustomHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); diff --git a/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java b/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java index eb37c30e5..7c9bfa278 100644 --- a/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java +++ b/src/main/java/org/springframework/samples/mvc/simple/SimpleController.java @@ -1,14 +1,13 @@ package org.springframework.samples.mvc.simple; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class SimpleController { - @RequestMapping("/simple") - public @ResponseBody String simple() { + @GetMapping("/simple") + public String simple() { return "Hello world!"; } diff --git a/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java b/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java index 67efe40f9..fb9889ce4 100644 --- a/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java +++ b/src/main/java/org/springframework/samples/mvc/simple/SimpleControllerRevisited.java @@ -1,15 +1,13 @@ package org.springframework.samples.mvc.simple; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class SimpleControllerRevisited { - @RequestMapping(value="/simple/revisited", method=RequestMethod.GET, headers="Accept=text/plain") - public @ResponseBody String simple() { + @GetMapping(path="/simple/revisited", headers="Accept=text/plain") + public String simple() { return "Hello world revisited!"; } diff --git a/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java b/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java index 6384e3065..4a916d5b7 100644 --- a/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java +++ b/src/main/java/org/springframework/samples/mvc/validation/ValidationController.java @@ -4,16 +4,16 @@ import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController public class ValidationController { // enforcement of constraints on the JavaBean arg require a JSR-303 provider on the classpath - @RequestMapping("/validate") - public @ResponseBody String validate(@Valid JavaBean bean, BindingResult result) { + @GetMapping("/validate") + public String validate(@Valid JavaBean bean, BindingResult result) { if (result.hasErrors()) { return "Object has validation errors"; } else { diff --git a/src/main/java/org/springframework/samples/mvc/views/ViewsController.java b/src/main/java/org/springframework/samples/mvc/views/ViewsController.java index d8ce95f8e..b1f9ab1b2 100644 --- a/src/main/java/org/springframework/samples/mvc/views/ViewsController.java +++ b/src/main/java/org/springframework/samples/mvc/views/ViewsController.java @@ -4,35 +4,35 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/views/*") public class ViewsController { - @RequestMapping(value="html", method=RequestMethod.GET) + @GetMapping("html") public String prepare(Model model) { model.addAttribute("foo", "bar"); model.addAttribute("fruit", "apple"); return "views/html"; } - @RequestMapping(value="/viewName", method=RequestMethod.GET) + @GetMapping("/viewName") public void usingRequestToViewNameTranslator(Model model) { model.addAttribute("foo", "bar"); model.addAttribute("fruit", "apple"); } - @RequestMapping(value="pathVariables/{foo}/{fruit}", method=RequestMethod.GET) + @GetMapping("pathVariables/{foo}/{fruit}") public String pathVars(@PathVariable String foo, @PathVariable String fruit) { // No need to add @PathVariables "foo" and "fruit" to the model // They will be merged in the model before rendering return "views/html"; } - @RequestMapping(value="dataBinding/{foo}/{fruit}", method=RequestMethod.GET) + @GetMapping("dataBinding/{foo}/{fruit}") public String dataBinding(@Valid JavaBean javaBean, Model model) { // JavaBean "foo" and "fruit" properties populated from URI variables return "views/dataBinding"; 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/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 000000000..da5e62170 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + 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/views/fileupload.jsp b/src/main/webapp/WEB-INF/views/fileupload.jsp index 05534b222..0b54e1d9b 100644 --- a/src/main/webapp/WEB-INF/views/fileupload.jsp +++ b/src/main/webapp/WEB-INF/views/fileupload.jsp @@ -16,7 +16,7 @@

diff --git a/src/main/webapp/WEB-INF/views/form.jsp b/src/main/webapp/WEB-INF/views/form.jsp index cf79829fb..dac22b582 100644 --- a/src/main/webapp/WEB-INF/views/form.jsp +++ b/src/main/webapp/WEB-INF/views/form.jsp @@ -20,7 +20,7 @@

Form

-
${message}
+
diff --git a/src/main/webapp/WEB-INF/views/home.jsp b/src/main/webapp/WEB-INF/views/home.jsp index 8e0fe94f2..c450135db 100644 --- a/src/main/webapp/WEB-INF/views/home.jsp +++ b/src/main/webapp/WEB-INF/views/home.jsp @@ -84,7 +84,7 @@ ">By produces via Accept=application/json
  • - ">By produces via Accept=appilcation/xml + ">By produces via Accept=application/xml
  • ">By produces via ".json" @@ -131,6 +131,9 @@

    Standard Resolvable Web Arguments

    +

    + See the org.springframework.samples.mvc.data.standard package for the @Controller code +

    Custom Resolvable Web Arguments

    +

    + See the org.springframework.samples.mvc.data.custom package for the @Controller code +

    • ">Custom @@ -495,7 +501,7 @@ $(document).ready(function() { // after a redirect or a full page refresh (e.g. Views tab). // However, note this general disclaimer about going back to previous tabs: - // http://docs.jquery.com/UI/API/1.8/Tabs#Back_button_and_bookmarking + // https://docs.jquery.com/UI/API/1.8/Tabs#Back_button_and_bookmarking $("#tabs").bind("tabsselect", function(event, ui) { window.location.hash = ui.tab.hash; }); @@ -637,7 +643,7 @@ $(document).ready(function() { }); // Include CSRF token as header in JQuery AJAX requests - // See http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#csrf-include-csrf-token-ajax + // See https://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#csrf-include-csrf-token-ajax var token = $("meta[name='_csrf']").attr("content"); var header = $("meta[name='_csrf_header']").attr("content"); $(document).ajaxSend(function(e, xhr, options) { @@ -647,4 +653,4 @@ $(document).ready(function() { }); - \ No newline at end of file + 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/main/webapp/resources/jquery/1.6/jquery.js b/src/main/webapp/resources/jquery/1.6/jquery.js index 5d5a1d58e..0cd4ae733 100644 --- a/src/main/webapp/resources/jquery/1.6/jquery.js +++ b/src/main/webapp/resources/jquery/1.6/jquery.js @@ -1,13 +1,13 @@ /*! * jQuery JavaScript Library v1.6.1 - * http://jquery.com/ + * https://jquery.com/ * * Copyright 2011, John Resig * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * * Includes Sizzle.js - * http://sizzlejs.com/ + * https://sizzlejs.com/ * Copyright 2011, The Dojo Foundation * Released under the MIT, BSD, and GPL Licenses. * @@ -554,7 +554,7 @@ jQuery.extend({ } // Make sure the incoming data is actual JSON - // Logic borrowed from http://json.org/json2.js + // Logic borrowed from https://json.org/json2.js if ( rvalidchars.test( data.replace( rvalidescape, "@" ) .replace( rvalidtokens, "]" ) .replace( rvalidbraces, "")) ) { @@ -591,7 +591,7 @@ jQuery.extend({ // Evaluates a script in a global context // Workarounds based on findings by Jim Driscoll - // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context + // https://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context globalEval: function( data ) { if ( data && rnotwhite.test( data ) ) { // We use execScript on Internet Explorer @@ -832,7 +832,7 @@ jQuery.extend({ }, // Use of jQuery.browser is frowned upon. - // More details: http://docs.jquery.com/Utilities/jQuery.browser + // More details: https://docs.jquery.com/Utilities/jQuery.browser uaMatch: function( ua ) { ua = ua.toLowerCase(); @@ -1348,7 +1348,7 @@ jQuery.support = (function() { documentElement.removeChild( body ); // Technique from Juriy Zaytsev - // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ + // https://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ // We only care about the case where non-standard event systems // are used, namely in IE. Short-circuiting here helps us to // avoid an eval call (in setAttribute) which can cause CSP @@ -1822,7 +1822,7 @@ jQuery.fn.extend({ }); }, // Based off of the plugin by Clint Helfers, with permission. - // http://blindsignals.com/index.php/2009/07/jquery-delay/ + // http://blindsignals.com delay: function( time, type ) { time = jQuery.fx ? jQuery.fx.speeds[time] || time : time; type = type || "fx"; @@ -2273,7 +2273,7 @@ jQuery.extend({ tabIndex: { get: function( elem ) { // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set - // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + // https://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ var attributeNode = elem.getAttributeNode("tabIndex"); return attributeNode && attributeNode.specified ? @@ -3099,7 +3099,7 @@ function returnTrue() { } // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding -// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +// https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html jQuery.Event.prototype = { preventDefault: function() { this.isDefaultPrevented = returnTrue; @@ -3701,7 +3701,7 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl * Sizzle CSS Selector Engine * Copyright 2011, The Dojo Foundation * Released under the MIT, BSD, and GPL Licenses. - * More information: http://sizzlejs.com/ + * More information: https://sizzlejs.com/ */ (function(){ @@ -5343,7 +5343,7 @@ jQuery.each({ // The variable 'args' was introduced in // https://github.com/jquery/jquery/commit/52a0238 // to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed. - // http://code.google.com/p/v8/issues/detail?id=1050 + // https://code.google.com/p/v8/issues/detail?id=1050 args = slice.call(arguments); if ( !runtil.test( name ) ) { @@ -7839,7 +7839,7 @@ if ( jQuery.support.ajax ) { // Firefox throws exceptions when accessing properties // of an xhr when a network error occured - // http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE) + // https://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE) try { // Was never called and is aborted or complete diff --git a/src/main/webapp/resources/jqueryform/2.8/jquery.form.js b/src/main/webapp/resources/jqueryform/2.8/jquery.form.js index baf8b1637..35a8b43bc 100644 --- a/src/main/webapp/resources/jqueryform/2.8/jquery.form.js +++ b/src/main/webapp/resources/jqueryform/2.8/jquery.form.js @@ -5,8 +5,8 @@ * * Examples and documentation at: http://malsup.com/jquery/form/ * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html + * https://www.opensource.org/licenses/mit-license.php + * https://www.gnu.org/licenses/gpl.html */ ;(function($) { @@ -44,7 +44,7 @@ * an HTML form using AJAX. */ $.fn.ajaxSubmit = function(options) { - // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) + // fast fail if nothing selected (https://dev.jquery.com/ticket/2752) if (!this.length) { log('ajaxSubmit: skipping submit process - no element selected'); return this; @@ -160,7 +160,7 @@ $.fn.ajaxSubmit = function(options) { // 06-NOV-09: now defaulting to iframe mode if file input is detected if (options.iframe !== false && (fileInputs || options.iframe || multipart)) { // hack to fix Safari hang (thanks to Tim Molendijk for this) - // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + // see: https://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d if (options.closeKeepAlive) { $.get(options.closeKeepAlive, function() { fileUpload(a); }); } @@ -534,7 +534,7 @@ $.fn.ajaxForm = function(options) { }); return this; } - // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready() + // is your DOM ready? https://docs.jquery.com/Tutorials:Introducing_$(document).ready() log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)')); return this; } diff --git a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.core.js b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.core.js index b175bd407..42de01454 100644 --- a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.core.js +++ b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.core.js @@ -1,11 +1,11 @@ /*! * jQuery UI 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI + * https://docs.jquery.com/UI */ (function( $, undefined ) { @@ -234,7 +234,7 @@ $(function() { $.support.selectstart = "onselectstart" in div; // set display to none to avoid a layout bug in IE - // http://dev.jquery.com/ticket/4014 + // https://dev.jquery.com/ticket/4014 body.removeChild( div ).style.display = "none"; }); diff --git a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.tabs.js b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.tabs.js index 6a2dec158..77f6c0933 100644 --- a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.tabs.js +++ b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.tabs.js @@ -1,11 +1,11 @@ /* * jQuery UI Tabs 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Tabs + * https://docs.jquery.com/UI/Tabs * * Depends: * jquery.ui.core.js @@ -380,7 +380,7 @@ $.widget( "ui.tabs", { showTab( el, $show ); }); - // TODO make passing in node possible, see also http://dev.jqueryui.com/ticket/3171 + // TODO make passing in node possible, see also https://dev.jqueryui.com/ticket/3171 self.load( self.anchors.index( this ) ); this.blur(); diff --git a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.widget.js b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.widget.js index 77ae17729..a8fb3757f 100644 --- a/src/main/webapp/resources/jqueryui/1.8/jquery.ui.widget.js +++ b/src/main/webapp/resources/jqueryui/1.8/jquery.ui.widget.js @@ -1,11 +1,11 @@ /*! * jQuery UI Widget 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Widget + * https://docs.jquery.com/UI/Widget */ (function( $, undefined ) { diff --git a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.all.css b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.all.css index 603aafd46..7126a84aa 100644 --- a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.all.css +++ b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.all.css @@ -1,11 +1,11 @@ /* * jQuery UI CSS Framework 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Theming + * https://docs.jquery.com/UI/Theming */ @import "jquery.ui.base.css"; @import "jquery.ui.theme.css"; diff --git a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.core.css b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.core.css index ea82f08a8..d829fa3e6 100644 --- a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.core.css +++ b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.core.css @@ -1,11 +1,11 @@ /* * jQuery UI CSS Framework 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Theming/API + * https://docs.jquery.com/UI/Theming/API */ /* Layout helpers diff --git a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.tabs.css b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.tabs.css index 1ed9c22d0..8d2c259fb 100644 --- a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.tabs.css +++ b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.tabs.css @@ -1,11 +1,11 @@ /* * jQuery UI Tabs 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Tabs#theming + * https://docs.jquery.com/UI/Tabs#theming */ .ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */ .ui-tabs .ui-tabs-nav { margin: 0; padding: .2em .2em 0; } diff --git a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.theme.css b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.theme.css index c1018644e..7bac24115 100644 --- a/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.theme.css +++ b/src/main/webapp/resources/jqueryui/1.8/themes/base/jquery.ui.theme.css @@ -1,13 +1,13 @@ /* * jQuery UI CSS Framework 1.8.13 * - * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Copyright 2011, AUTHORS.txt (https://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. - * http://jquery.org/license + * https://jquery.org/license * - * http://docs.jquery.com/UI/Theming/API + * https://docs.jquery.com/UI/Theming/API * - * To view and modify this theme, visit http://jqueryui.com/themeroller/ + * To view and modify this theme, visit https://jqueryui.com/themeroller/ */ diff --git a/src/main/webapp/resources/json2.js b/src/main/webapp/resources/json2.js index a1a3b170c..8f5bc8a22 100644 --- a/src/main/webapp/resources/json2.js +++ b/src/main/webapp/resources/json2.js @@ -1,16 +1,16 @@ /* - http://www.JSON.org/json2.js + https://www.JSON.org/json2.js 2010-03-20 Public Domain. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. - See http://www.JSON.org/js.html + See https://www.JSON.org/js.html This code should be minified before deployment. - See http://javascript.crockford.com/jsmin.html + See https://javascript.crockford.com/jsmin.html USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO NOT CONTROL. diff --git a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java index c2116dac8..d687e8e99 100644 --- a/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/AbstractContextControllerTests.java @@ -1,12 +1,13 @@ package org.springframework.samples.mvc; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.samples.mvc.config.WebMvcConfig; 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") +@ContextConfiguration(classes = WebMvcConfig.class) public class AbstractContextControllerTests { @Autowired diff --git a/src/test/java/org/springframework/samples/mvc/data/CustomArgumentControllerTests.java b/src/test/java/org/springframework/samples/mvc/data/CustomArgumentControllerTests.java index a0ab7d4e7..e8a9a5a78 100644 --- a/src/test/java/org/springframework/samples/mvc/data/CustomArgumentControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/data/CustomArgumentControllerTests.java @@ -14,7 +14,7 @@ public class CustomArgumentControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = standaloneSetup(new CustomArgumentController()) .setCustomArgumentResolvers(new CustomArgumentResolver()).build(); } diff --git a/src/test/java/org/springframework/samples/mvc/data/DataControllerTests.java b/src/test/java/org/springframework/samples/mvc/data/DataControllerTests.java index 887cacd8b..4e31be891 100644 --- a/src/test/java/org/springframework/samples/mvc/data/DataControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/data/DataControllerTests.java @@ -47,7 +47,7 @@ public void pathVar() throws Exception { @Test public void matrixVar() throws Exception { - this.mockMvc.perform(get("/data/matrixvars;foo=bar/simple")).andDo(print()) + this.mockMvc.perform(get("/data/matrixvars;foo=bar/simple")) .andExpect(content().string("Obtained matrix variable 'foo=bar' from path segment 'matrixvars'")); } diff --git a/src/test/java/org/springframework/samples/mvc/exceptions/ExceptionControllerTests.java b/src/test/java/org/springframework/samples/mvc/exceptions/ExceptionControllerTests.java index 8a0ff4541..d7ac2f7d6 100644 --- a/src/test/java/org/springframework/samples/mvc/exceptions/ExceptionControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/exceptions/ExceptionControllerTests.java @@ -18,7 +18,7 @@ public class ExceptionControllerTests extends AbstractContextControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = webAppContextSetup(this.wac).build(); } 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..97992e323 100644 --- a/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/form/FormControllerTests.java @@ -24,7 +24,7 @@ public class FormControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setPrefix("/WEB-INF/"); @@ -51,7 +51,6 @@ public void submitSuccess() throws Exception { .param("additionalInfo[java]", "true") .param("_additionalInfo[java]", "on") .param("subscribeNewsletter", "false")) - .andDo(print()) .andExpect(status().isMovedTemporarily()) .andExpect(redirectedUrl("/form")) .andExpect(flash().attribute("message", diff --git a/src/test/java/org/springframework/samples/mvc/mapping/MappingControllerTests.java b/src/test/java/org/springframework/samples/mvc/mapping/MappingControllerTests.java index 71b191546..861093fe2 100644 --- a/src/test/java/org/springframework/samples/mvc/mapping/MappingControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/mapping/MappingControllerTests.java @@ -23,7 +23,7 @@ public class MappingControllerTests extends AbstractContextControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); } diff --git a/src/test/java/org/springframework/samples/mvc/messageconverters/MessageConvertersControllerTests.java b/src/test/java/org/springframework/samples/mvc/messageconverters/MessageConvertersControllerTests.java index fdab6b28c..650623392 100644 --- a/src/test/java/org/springframework/samples/mvc/messageconverters/MessageConvertersControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/messageconverters/MessageConvertersControllerTests.java @@ -95,7 +95,6 @@ public void writeJson() throws Exception { @Test public void writeJson2() throws Exception { this.mockMvc.perform(get(URI, "json").accept(MediaType.APPLICATION_JSON)) - .andDo(print()) .andExpect(jsonPath("$.foo").value("bar")) .andExpect(jsonPath("$.fruit").value("apple")); } 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..7798ee19e 100644 --- a/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/redirect/RedirectControllerTests.java @@ -17,7 +17,7 @@ public class RedirectControllerTests { @Before public void setup() throws Exception { this.mockMvc = standaloneSetup(new RedirectController(new DefaultFormattingConversionService())) - .alwaysExpect(status().isMovedTemporarily()).build(); + .alwaysExpect(status().isFound()).build(); } @Test 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..89b5b647d 100644 --- a/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/response/ResponseControllerTests.java @@ -1,24 +1,23 @@ 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; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; + public class ResponseControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = standaloneSetup(new ResponseController()).build(); } 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..a7c6d4d97 100644 --- a/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java +++ b/src/test/java/org/springframework/samples/mvc/simple/SimpleControllerRevisitedTests.java @@ -15,7 +15,7 @@ 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().contentType("text/plain;charset=ISO-8859-1")) .andExpect(content().string("Hello world revisited!")); } diff --git a/src/test/java/org/springframework/samples/mvc/validation/ValidationControllerTests.java b/src/test/java/org/springframework/samples/mvc/validation/ValidationControllerTests.java index a0b42b1a3..47bd522af 100644 --- a/src/test/java/org/springframework/samples/mvc/validation/ValidationControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/validation/ValidationControllerTests.java @@ -1,20 +1,20 @@ package org.springframework.samples.mvc.validation; -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.Before; import org.junit.Test; + import org.springframework.test.web.servlet.MockMvc; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; + public class ValidationControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = standaloneSetup(new ValidationController()).alwaysExpect(status().isOk()).build(); } diff --git a/src/test/java/org/springframework/samples/mvc/views/ViewsControllerTests.java b/src/test/java/org/springframework/samples/mvc/views/ViewsControllerTests.java index e69321f08..dc5864eb4 100644 --- a/src/test/java/org/springframework/samples/mvc/views/ViewsControllerTests.java +++ b/src/test/java/org/springframework/samples/mvc/views/ViewsControllerTests.java @@ -20,7 +20,7 @@ public class ViewsControllerTests extends AbstractContextControllerTests { private MockMvc mockMvc; @Before - public void setup() throws Exception { + public void setup() { this.mockMvc = webAppContextSetup(this.wac).alwaysExpect(status().isOk()).build(); } 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/log4j2-test.xml b/src/test/resources/log4j2-test.xml new file mode 100644 index 000000000..4014ced5b --- /dev/null +++ b/src/test/resources/log4j2-test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + +