diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java index 8a8badfcc6..62399fbfb7 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java @@ -172,7 +172,7 @@ public class EnableSchedulingTests { @Test public void withExplicitScheduledTaskRegistrar() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( - ExplicitScheduledTaskRegistrarConfig.class); + ExplicitScheduledTaskRegistrarConfig.class); Thread.sleep(100); assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10)); @@ -287,7 +287,7 @@ public class EnableSchedulingTests { @Test public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrarBean() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( - SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar.class); + SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar.class); Thread.sleep(20); assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("explicitScheduler2-")); @@ -296,9 +296,11 @@ public class EnableSchedulingTests { static class ThreadAwareWorker { + String executedByThread; } + @Configuration @EnableScheduling static class SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar implements SchedulingConfigurer { @@ -337,7 +339,7 @@ public class EnableSchedulingTests { @Test public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( - SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class); + SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class); Thread.sleep(20); assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("explicitScheduler2-")); @@ -383,7 +385,7 @@ public class EnableSchedulingTests { @Test public void withTaskAddedVia_configureTasks() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( - SchedulingEnabled_withTaskAddedVia_configureTasks.class); + SchedulingEnabled_withTaskAddedVia_configureTasks.class); Thread.sleep(20); assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("taskScheduler-")); @@ -463,7 +465,7 @@ public class EnableSchedulingTests { @Test public void withInitiallyDelayedFixedRateTask() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( - FixedRateTaskConfig_withInitialDelay.class); + FixedRateTaskConfig_withInitialDelay.class); Thread.sleep(1950); AtomicInteger counter = ctx.getBean(AtomicInteger.class); diff --git a/spring-web/src/main/java/org/springframework/http/CacheControl.java b/spring-web/src/main/java/org/springframework/http/CacheControl.java index 28279c855c..a291e7ae7e 100644 --- a/spring-web/src/main/java/org/springframework/http/CacheControl.java +++ b/spring-web/src/main/java/org/springframework/http/CacheControl.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.http; import java.util.concurrent.TimeUnit; @@ -22,79 +23,78 @@ import org.springframework.util.StringUtils; /** * A builder for creating "Cache-Control" HTTP response headers. * - *

Adding Cache-Control directives to HTTP responses can significantly improve the client experience when interacting - * with a web application. This builder creates opinionated "Cache-Control" headers with response directives only, with - * several use cases in mind. + *

Adding Cache-Control directives to HTTP responses can significantly improve the client + * experience when interacting with a web application. This builder creates opinionated + * "Cache-Control" headers with response directives only, with several use cases in mind. * *

* - *

Note that to be efficient, Cache-Control headers should be written along HTTP validators such as - * "Last-Modifed" or "ETag" headers. + *

Note that to be efficient, Cache-Control headers should be written along HTTP validators + * such as "Last-Modified" or "ETag" headers. * * @author Brian Clozel + * @author Juergen Hoeller + * @since 4.2 * @see rfc7234 section 5.2.2 * @see - * HTTP caching - Google developers reference + * HTTP caching - Google developers reference * @see Mark Nottingham's cache documentation - * @since 4.2 */ public class CacheControl { - private boolean mustRevalidate; + private long maxAge = -1; - private boolean noCache; + private boolean noCache = false; - private boolean noStore; + private boolean noStore = false; - private boolean noTransform; + private boolean mustRevalidate = false; - private boolean cachePublic; + private boolean noTransform = false; - private boolean cachePrivate; + private boolean cachePublic = false; - private boolean proxyRevalidate; + private boolean cachePrivate = false; - private long maxAge; + private boolean proxyRevalidate = false; + + private long sMaxAge = -1; - private long sMaxAge; /** - * Create a CacheControl instance with default values, - * i.e. that will produce an empty "Cache-Control" header value. + * Create an empty CacheControl instance. + * @see #empty() */ protected CacheControl() { - this.mustRevalidate = false; - this.noCache = false; - this.noStore = false; - this.noTransform = false; - this.cachePublic = false; - this.cachePrivate = false; - this.proxyRevalidate = false; - this.maxAge = -1; - this.sMaxAge = -1; + } + + + /** + * Return an empty directive. + *

This is well suited for using other optional directives without "max-age", "no-cache" or "no-store". + * @return {@code this}, to facilitate method chaining + */ + public static CacheControl empty() { + return new CacheControl(); } /** * Add a "max-age=" directive. - * *

This directive is well suited for publicly caching resources, knowing that they won't change within * the configured amount of time. Additional directives can be also used, in case resources shouldn't be * cached ({@link #cachePrivate()}) or transformed ({@link #noTransform()}) by shared caches. - * *

In order to prevent caches to reuse the cached response even when it has become stale * (i.e. the "max-age" delay is passed), the "must-revalidate" directive should be set ({@link #mustRevalidate()} - * * @param maxAge the maximum time the response should be cached * @param unit the time unit of the {@code maxAge} argument * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.8 */ public static CacheControl maxAge(long maxAge, TimeUnit unit) { @@ -103,34 +103,15 @@ public class CacheControl { return cc; } - /** - * Add a "no-store" directive - * - *

This directive is well suited for preventing caches (browsers and proxies) to cache the content of responses. - * - * @return {@code this}, to facilitate method chaining - * - * @see rfc7234 section 5.2.2.3 - */ - public static CacheControl noStore() { - CacheControl cc = new CacheControl(); - cc.noStore = true; - return cc; - } - /** * Add a "no-cache" directive. - * *

This directive is well suited for telling caches that the response can be reused only if the client * revalidates it with the server. This directive won't disable cache altogether and may result with * clients sending conditional requests (with "ETag", "If-Modified-Since" headers) and the server responding * with "304 - Not Modified" status. - * *

In order to disable caching and minimize requests/responses exchanges, the {@link #noStore()} directive * should be used. - * * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.2 */ public static CacheControl noCache() { @@ -140,25 +121,23 @@ public class CacheControl { } /** - * Return an empty directive. - * - *

This is well suited for using other optional directives without "no-cache", "no-store" or "max-age". - * + * Add a "no-store" directive. + *

This directive is well suited for preventing caches (browsers and proxies) to cache the content of responses. * @return {@code this}, to facilitate method chaining + * @see rfc7234 section 5.2.2.3 */ - public static CacheControl empty() { + public static CacheControl noStore() { CacheControl cc = new CacheControl(); + cc.noStore = true; return cc; } + /** - * Add a "must-revalidate" directive - * + * Add a "must-revalidate" directive. *

This directive indicates that once it has become stale, a cache MUST NOT use the response * to satisfy subsequent requests without successful validation on the origin server. - * * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.1 */ public CacheControl mustRevalidate() { @@ -167,13 +146,10 @@ public class CacheControl { } /** - * Add a "no-transform" directive - * + * Add a "no-transform" directive. *

This directive indicates that intermediaries (caches and others) should not transform the response content. * This can be useful to force caches and CDNs not to automatically gzip or optimize the response content. - * * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.4 */ public CacheControl noTransform() { @@ -182,13 +158,10 @@ public class CacheControl { } /** - * Add a "public" directive - * + * Add a "public" directive. *

This directive indicates that any cache MAY store the response, even if the response * would normally be non-cacheable or cacheable only within a private cache. - * * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.5 */ public CacheControl cachePublic() { @@ -197,13 +170,10 @@ public class CacheControl { } /** - * Add a "private" directive - * + * Add a "private" directive. *

This directive indicates that the response message is intended for a single user * and MUST NOT be stored by a shared cache. - * * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.6 */ public CacheControl cachePrivate() { @@ -212,13 +182,10 @@ public class CacheControl { } /** - * Add a "proxy-revalidate" directive - * + * Add a "proxy-revalidate" directive. *

This directive has the same meaning as the "must-revalidate" directive, - * except that it does not apply to private caches (i.e. browsers, HTTP clients) - * + * except that it does not apply to private caches (i.e. browsers, HTTP clients). * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.7 */ public CacheControl proxyRevalidate() { @@ -227,15 +194,12 @@ public class CacheControl { } /** - * Add a "s-maxage" directive - * + * Add an "s-maxage" directive. *

This directive indicates that, in shared caches, the maximum age specified by this directive * overrides the maximum age specified by other directives. - * * @param sMaxAge the maximum time the response should be cached * @param unit the time unit of the {@code sMaxAge} argument * @return {@code this}, to facilitate method chaining - * * @see rfc7234 section 5.2.2.9 */ public CacheControl sMaxAge(long sMaxAge, TimeUnit unit) { @@ -243,15 +207,15 @@ public class CacheControl { return this; } + /** - * Return the "Cache-Control" header value - * - * @return null if no directive was added, the header value otherwise + * Return the "Cache-Control" header value. + * @return {@code null} if no directive was added, or the header value otherwise */ public String getHeaderValue() { StringBuilder ccValue = new StringBuilder(); if (this.maxAge != -1) { - appendDirective(ccValue, "max-age=" + Long.toString(maxAge)); + appendDirective(ccValue, "max-age=" + Long.toString(this.maxAge)); } if (this.noCache) { appendDirective(ccValue, "no-cache"); @@ -278,17 +242,14 @@ public class CacheControl { appendDirective(ccValue, "s-maxage=" + Long.toString(this.sMaxAge)); } String ccHeaderValue = ccValue.toString(); - if (StringUtils.hasText(ccHeaderValue)) { - return ccHeaderValue; - } - return null; + return (StringUtils.hasText(ccHeaderValue) ? ccHeaderValue : null); } - private void appendDirective(StringBuilder b, String value) { - if (b.length() > 0) { - b.append(", "); + private void appendDirective(StringBuilder builder, String value) { + if (builder.length() > 0) { + builder.append(", "); } - b.append(value); + builder.append(value); } } diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index 50027872cd..6d27959773 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -321,14 +321,14 @@ public class ResponseEntity extends HttpEntity { B location(URI location); /** - * Set the caching directives for the resource, as specified by the + * Set the caching directives for the resource, as specified by the HTTP 1.1 * {@code Cache-Control} header. *

A {@code CacheControl} instance can be built like * {@code CacheControl.maxAge(3600).cachePublic().noTransform()}. - * @param cacheControl the instance that builds cache related HTTP response headers + * @param cacheControl a builder for cache-related HTTP response headers * @return this builder - * @see RFC-7234 Section 5.2 * @since 4.2 + * @see RFC-7234 Section 5.2 */ B cacheControl(CacheControl cacheControl); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java index ab26750443..75ff89c72d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java @@ -81,7 +81,6 @@ import org.springframework.web.servlet.support.RequestContextUtils; * @author Arjen Poutsma * @author Juergen Hoeller * @since 3.0 - * * @deprecated as of Spring 3.2, in favor of * {@link org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver ExceptionHandlerExceptionResolver} */ diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java index 77c99cdee0..a1275c9c68 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,8 +78,7 @@ import org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMappin * @since 2.5 * @see RequestMapping * @see AnnotationMethodHandlerAdapter - * - * @deprecated in Spring 3.2 in favor of + * @deprecated as of Spring 3.2, in favor of * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping RequestMappingHandlerMapping} */ @Deprecated diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java index 072a85de52..2f30a689e5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,39 +23,36 @@ import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.servlet.ModelAndView; /** - * SPI for resolving custom return values from a specific handler method. Typically implemented to detect special return - * types, resolving well-known result values for them. + * SPI for resolving custom return values from a specific handler method. + * Typically implemented to detect special return types, resolving + * well-known result values for them. * *

A typical implementation could look like as follows: * *

  * public class MyModelAndViewResolver implements ModelAndViewResolver {
  *
- *   public ModelAndView resolveModelAndView(Method handlerMethod,
- *		   			Class handlerType,
- *		   			Object returnValue,
- *		 			ExtendedModelMap implicitModel,
- *		 			NativeWebRequest webRequest) {
- *     if (returnValue instanceof MySpecialRetVal.class)) {
- *       return new MySpecialRetVal(returnValue);
+ *     public ModelAndView resolveModelAndView(Method handlerMethod, Class handlerType,
+ *             Object returnValue, ExtendedModelMap implicitModel, NativeWebRequest webRequest) {
+ *         if (returnValue instanceof MySpecialRetVal.class)) {
+ *             return new MySpecialRetVal(returnValue);
+ *         }
+ *         return UNRESOLVED;
  *     }
- *     return UNRESOLVED;
- *   }
  * }
* * @author Arjen Poutsma - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomModelAndViewResolvers - * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomModelAndViewResolvers * @since 3.0 */ public interface ModelAndViewResolver { - /** Marker to be returned when the resolver does not know how to handle the given method parameter. */ + /** + * Marker to be returned when the resolver does not know how to handle the given method parameter. + */ ModelAndView UNRESOLVED = new ModelAndView(); - ModelAndView resolveModelAndView(Method handlerMethod, - Class handlerType, - Object returnValue, - ExtendedModelMap implicitModel, - NativeWebRequest webRequest); + + ModelAndView resolveModelAndView(Method handlerMethod, Class handlerType, Object returnValue, + ExtendedModelMap implicitModel, NativeWebRequest webRequest); + } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java index d854fc4288..d7eca3fe7f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java @@ -54,6 +54,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes this.messageSource = messageSource; } + @Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { @@ -76,12 +77,10 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes /** * Template method that handles {@link ResponseStatus @ResponseStatus} annotation. - * - *

Default implementation send a response error using + *

The default implementation sends a response error using * {@link HttpServletResponse#sendError(int)} or * {@link HttpServletResponse#sendError(int, String)} if the annotation has a * {@linkplain ResponseStatus#reason() reason} and then returns an empty ModelAndView. - * * @param responseStatus the annotation * @param request current HTTP request * @param response current HTTP response diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java index 5c0282f527..e41ca9d542 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,7 @@ import org.springframework.web.util.WebUtils; * @author Juergen Hoeller * @author Arjen Poutsma * @since 2.5.2 - * - * @deprecated in 3.2 together with {@link DefaultAnnotationHandlerMapping}, + * @deprecated as of 3.2, together with {@link DefaultAnnotationHandlerMapping}, * {@link AnnotationMethodHandlerAdapter}, and {@link AnnotationMethodHandlerExceptionResolver}. */ @Deprecated