Commit Graph

1442 Commits

Author SHA1 Message Date
Juergen Hoeller f532de92aa Revised checkResource implementation
Issue: SPR-14729
(cherry picked from commit ca17edd)
2016-09-18 21:33:52 +02:00
Brian Clozel 9e5435e6f2 Check template availability in ScriptTemplateView
This commit overrides the `checkResource` implementation in
`ScriptTemplateView` in order to check if the template file resource is
available and if the resolver can then proceed with rendering the
template.

Issue: SPR-14729
Cherry-picked from: 66b370e10
2016-09-17 22:30:54 +02:00
Sam Brannen 8f62b63663 Introduce 'value' alias for @Bean's 'name' attribute
In order to simplify configuration for use cases involving @Bean where
only a bean name or aliases are supplied as an attribute, this commit
introduces a new 'value' attribute that is an @AliasFor 'name' in @Bean.

Issue: SPR-14728
2016-09-17 16:16:06 +02:00
Brian Clozel 084daa7fb5 Document media type registration for appcache files
Since appcache manifests can have various file extensions, developers
should register the (file extension, media type) mapping in their Spring
MVC / Reactive Web configuration.

This commit adds javadoc on both `AppCacheManifestTransformer` variants
to explain how to do that.

Issue: SPR-14510
2016-09-16 12:04:56 +02:00
Juergen Hoeller 6dc1898dbb Timeout exceptions as RuntimeExceptions
Issue: SPR-14669
2016-09-15 08:54:17 +02:00
Rossen Stoyanchev 765b47246a Improve async request timeout handling
Rather than setting the status to 503 directly from the timeout
interceptor which no longer seems to work reliably with Servlet
containers like Jetty even performing an additional ERROR dispatch back
to the original URL, we know rather set the DeferredResult to an
AsyncTimeoutException, which results in a dispatch and standard
handling within Spring MVC. This should be a more reliable way of
dealing with timeouts.

Issue: SPR-14669
2016-09-14 21:34:30 -04:00
Rossen Stoyanchev bc14c5ba83 Polish [CssLinkResource|AppCacheManifest]Transformer
This commit updates the two transformers to make them more
consistent with updates of their spring-web-reactive equivalents.

Issue: SPR-14521
2016-09-13 18:04:40 -04:00
Juergen Hoeller ce42ed4d44 Polishing 2016-09-13 21:58:41 +02:00
Brian Clozel 1881aa5b5b Change default appcache manifest file extension
This commit changes the default file extension configured with
`AppCacheManifestTranformer`. This ResourceTransformer was previously
considering `.manifest` files by default, but this has been changed in
the official spec to `appcache`, in order not to clash with Microsoft's
unregistered application/manifest type.

Issue: SPR-14687
2016-09-09 22:11:20 +02:00
Brian Clozel 4588b6c9f4 Rename ResolvedResource to HttpResource
`ResolvedResource` is a rather generic name - changing the extended
interface to something more meaningful: `HttpResource`.
For now, implementations are linked with the resource handling chain,
but this aspect has been removed from the interface documentation.

Issue: SPR-14264
2016-09-09 18:18:09 +02:00
Brian Clozel ccb3c44dbc Add ResolvedResource in resource handling chain
Prior to this commit, the resource handling chain and its
`ResourceResolvers` would use specific `Resource` implementations in
order to add resource metadata to the HTTP response. For example,
`VersionedResource` and `EncodedResource` are both adding specific HTTP
response headers.

This commit aims at making this mechanism more stable and reusable,
since the previous implementation would fail in case a resolved resource
would be both a `VersionedResource` wrapping a `EncodedResource` (or the
other way arount). Only one of the specific implementations would
contribute its metadata since the code supporting that in
`ResourceHttpRequestHandler` would only check for `instanceof` tests,
whereas those implementations are acutally delegating calls to
the wrapped resource.

Now both `VersionedResource` and `EncodedResource` have been replaced by
specific implementations of `ResolvedResource`, which directly provides
those HTTP response headers as part of `getResponseHeaders()`.

This commit applies the same changes for the web reactive
implementations and its `ResourceWebHandler`.

Issue: SPR-14264
2016-09-07 09:52:33 +02:00
Brian Clozel cc5300c4d5 Align MVC checkNotModified with reactive support
Since SPR-14522, the web reactive framework supports checkNotModified
features. This commit aligns the existing MVC infrastructure with
web reactive's behavior.

Because of the new Servlet 3.0 baseline, some constraints
aren't relevant anymore and duplicate code has been removed in
`HttpEntityMethodProcessor`.

Issue: SPR-14659
2016-09-06 18:02:48 +02:00
Brian Clozel 72e4fac28d Fix missing resources in GzipResourceResolverTests 2016-09-06 15:39:28 +02:00
Rossen Stoyanchev 108ebe0f2b Polish resource handling tests 2016-09-05 21:59:22 -04:00
Brian Clozel a8ba065a6e Mention AntPathMatcher regexp support
This commit documents the regexp support in `AntPathMatcher` when
matching for URL patterns. This support is also mentioned in places
where developers can register patterns for ViewControllers or resource
handlers.

Issue: SPR-14652
2016-09-02 11:35:58 +02:00
Juergen Hoeller e08b1b75b6 @PathVariable supports 'required' attribute (for model attribute methods)
Issue: SPR-14646
2016-08-31 14:43:39 +02:00
Brian Clozel 7a88776329 Fix missing ResourceHttpRequestHandler init in registry
Issue: SPR-14577
2016-08-31 10:43:11 +02:00
Rossen Stoyanchev 436486b8a1 Relax ServletContext check for resource handling
This is a follow-up on commit 3b95e0b relaxing the expectation that a
ServletContext is present. Instead we check defensively and fall back
on PathExtensionContentNegotiationStrategy which can use JAF.

Issue: SPR-14577
2016-08-30 13:04:58 -04:00
Sebastien Deleuze e8530c917e Add Smile and CBOR Jackson data formats support
This commit adds Smile and CBOR Jackson HttpMessageConverters
and make it possible to create Smile and CBOR ObjectMapper via
Jackson2ObjectMapperBuilder, which now allows to specify any
custom JsonFactory.

Like with JSON and XML Jackson support, the relevant
HttpMessageConverters are automaticially configurered by
Spring MVC WebMvcConfigurationSupport if jackson-dataformat-smile
or jackson-dataformat-cbor dependencies are found in the classpath.

Issue: SPR-14435
2016-08-30 11:06:40 +02:00
Rossen Stoyanchev 204a50ee6c Fix compile issue 2016-08-29 21:06:35 -04:00
Rossen Stoyanchev 4d3c3056ed Polish media type change in ResourceHttpRequestHandler 2016-08-29 19:49:24 -04:00
Rossen Stoyanchev 3b95e0b6e0 Fix media type regression in resource handling
Issue: SPR-14577
2016-08-29 16:27:24 -04:00
Juergen Hoeller dfdfd72a3e Polishing
(cherry picked from commit 430180a)
2016-08-26 18:59:40 +02:00
Brian Clozel d8fc13f6fc Fix server errors for invalid If-None-Match request headers
HttpEntityMethodProcessor should not throw IllegalArgumentExceptions for
invalid If-None-Match headers.

For those cases, this commit makes sure that both
`HttpEntityMethodProcessor` and `ServletWebRequest` have a consistent
behavior and stop processing the request as conditional and leave the
handler handle it.

Issue: SPR-14559
2016-08-26 15:48:47 +02:00
Juergen Hoeller 2e4a7480fc Consistent use of JDK 7 StandardCharsets over Charset.forName
Issue: SPR-14492
2016-08-26 14:16:19 +02:00
Juergen Hoeller 14046575b0 Polishing 2016-08-26 13:27:33 +02:00
Juergen Hoeller a8f7f75f64 Moved encodeHttpHeaderFieldParam method to HttpHeaders itself (including tests)
This commit also sets the test source encoding to UTF-8.

Issue: SPR-14547
2016-08-26 11:14:02 +02:00
Juergen Hoeller d047174c6b Unit test for empty Access-Control-Request-Headers (Chrome 52)
Includes optimized method/header resolution in CorsConfiguration.

Issue: SPR-14617
2016-08-24 11:40:18 +02:00
Juergen Hoeller 7bb4ab6842 Various @since tags (and varargs on setInterceptors)
(cherry picked from commit 5222489)
2016-08-18 12:58:02 +02:00
Juergen Hoeller 453822817f Protected visibility for configurePathMatch and configureAsyncSupport
Issue: SPR-14599
2016-08-18 10:15:48 +02:00
Juergen Hoeller d2e3a1a4f5 DelegatingWebMvcConfiguration properly delegates extendHandlerExceptionResolvers
Issue: SPR-14599
2016-08-18 09:05:47 +02:00
Juergen Hoeller eeeab27f1f Polishing
(cherry picked from commit 35e247a)
2016-08-10 16:42:21 +02:00
Juergen Hoeller 59a24b406a Polishing 2016-08-10 14:20:42 +02:00
Sebastien Deleuze e86529ec90 Prevent StackOverflowError in AbstractJackson2HttpMessageConverter
Issue: SPR-14520
2016-08-04 11:20:38 -07:00
Juergen Hoeller e03dea1d64 Polishing 2016-07-26 17:15:19 +02:00
Juergen Hoeller 382a931e7d Polishing 2016-07-22 22:28:20 +02:00
Marius Grama 3635c9dbfe Update xmlunit library to version 2.1.0
xmlunit 2.1.0 is the latest release for xmlunit.
Most of the xmlunit functionality used within spring-framework
was done through the xmlunit 1.x helper class
`org.custommonkey.xmlunit.XMLAssert`.

As of xmlunit 2.0.0 most of the XML comparison methods are done
through hamcrest matchers exposed by the xmlunit-matchers
library. In some cases during the migration, the matchers
had to be customized with custom `NodeMatcher` or
`DifferenceEvaluator` instances in order to keep the assertions
correct (they were performed with xmlunit 1.x previously).

Issue: SPR-14043
2016-07-21 15:04:21 +02:00
Juergen Hoeller 9cc625ee2c Polishing
(cherry picked from commit 5a92aa4)
2016-07-20 23:25:17 +02:00
Juergen Hoeller 28e7c11234 Polishing 2016-07-20 22:41:56 +02:00
Sebastien Deleuze 3a4e5d5da8 Fix ParameterizedType + contextClass support in Jackson converter
Issue: SPR-14470
2016-07-20 09:29:23 +02:00
Juergen Hoeller 99be15f58b Revise encoding steps towards use of JDK Charset and StandardCharsets
Issue: SPR-14492
2016-07-19 23:43:06 +02:00
Juergen Hoeller adc595b5f1 Avoid dependency on WebUtils for extracting file extension
Issue: SPR-14479
2016-07-19 23:30:33 +02:00
Juergen Hoeller fd4b5ac892 Ignore JRuby template tests (not compatible with JDK 9 yet)
Issue: SPR-13344
2016-07-19 19:42:31 +02:00
Juergen Hoeller d07381e862 Avoid deprecated number constructors on JDK 9
Issue: SPR-13344
2016-07-19 19:25:55 +02:00
Juergen Hoeller aaac199e8b Consistently use constructor-based instantiation instead of Class.newInstance / BeanUtils.instantiate
Issue: SPR-14486
2016-07-19 19:21:06 +02:00
Juergen Hoeller 8bb34bc962 Resource.isFile() and JAF MediaTypeFactory
Issue: SPR-14484
2016-07-19 18:53:31 +02:00
Juergen Hoeller dc1664939c Javadoc fixes and pruning of outdated references 2016-07-15 22:12:11 +02:00
Juergen Hoeller 503f0e3397 Polishing 2016-07-15 17:27:59 +02:00
Juergen Hoeller 8ccd727c9a AbstractHandlerMethodMapping adds type+method info to getMappingForMethod exceptions
Issue: SPR-14452
2016-07-13 15:42:34 +02:00
Juergen Hoeller 84afc601b8 Configurable UrlPathHelper in PathExtensionContentNegotiationStrategy
This commit also aligns ResourceUrlProvider's and RequestMappingInfo's UrlPathHelper setter/getter signatures.

Issue: SPR-14454
2016-07-13 15:14:42 +02:00
Juergen Hoeller 6aa5931e28 Polishing 2016-07-07 01:05:25 +02:00
Juergen Hoeller a1f5fb53db Java 8 getParameterCount() instead of getParameterTypes().length
Issue: SPR-13188
2016-07-07 01:04:24 +02:00
Juergen Hoeller da9c24c41e Polishing 2016-07-06 18:11:33 +02:00
Juergen Hoeller 102dc8a4dd Polishing 2016-07-06 15:29:15 +02:00
Juergen Hoeller 76dedd7ca2 FactoryBean, BeanPostProcessor and HandlerInterceptor variants declared with default methods
Issue: SPR-14432
2016-07-06 15:10:08 +02:00
Stephane Nicoll e4b0486c5a Add @FunctionalInterface on candidate interfaces
Issue: SPR-14432
2016-07-06 14:32:13 +02:00
Juergen Hoeller 7dda9fbd8c Drop JasperReports support
Issue: SPR-13294
2016-07-05 23:06:15 +02:00
Juergen Hoeller bc2c22d51e Streamline XML namespace support towards unversioned schemas
This commit also removes support code for outdated options which were only available in older schema versions.

Issue: SPR-13499
2016-07-05 20:50:03 +02:00
Sam Brannen 1391248ea6 Introduce log4j 2 for Spring's test suite
This commit adds a test runtime dependency on log4j 2 for every project
and migrates all log4j.properties files to log4j2-test.xml files.

Issue: SPR-14431
2016-07-05 19:19:09 +02:00
Stephane Nicoll 00d2606b00 Explicit type can be replaced by <>
Issue: SPR-13188
2016-07-05 17:00:34 +02:00
Juergen Hoeller b5db5d3aac Broadly remove deprecated core classes and methods
Issue: SPR-14430
2016-07-05 15:52:49 +02:00
Juergen Hoeller 0fc0ce78ae Drop deprecated dependencies on Log4j, JRuby, JExcel, Burlap, Commons Pool/DBCP
This commit also removes outdated support classes for Oracle, GlassFish, JBoss.

Issue: SPR-14429
2016-07-05 15:46:53 +02:00
Juergen Hoeller 51252ebbca Avoid defensive checks against Java 8 API (java.util.Optional etc)
This commit also fixes broken javadoc links and code references.

Issue: SPR-13188
2016-07-05 02:09:00 +02:00
Juergen Hoeller 2b3445df81 Drop Portlet MVC support
This commit also removes the corresponding deprecated Servlet MVC variant and updates DispatcherServlet.properties to point to RequestMappingHandlerMapping/Adapter by default.

Issue: SPR-14129
2016-07-04 23:33:47 +02:00
Juergen Hoeller ae0b7c26c5 Drop Servlet 2.5 runtime compatibility
Issue: SPR-13189
2016-07-04 23:31:21 +02:00
Juergen Hoeller ff6ead1fff Remove Velocity support
Issue: SPR-13795
2016-07-04 23:30:58 +02:00
Juergen Hoeller b204437cef Polishing 2016-07-02 14:48:15 +02:00
Juergen Hoeller e7a53e37fb Avoid stateful MethodParameter nesting level changes in MVC processing 2016-07-02 13:02:22 +02:00
Juergen Hoeller cfc560c4c4 Leniently accept custom DeferredResult etc subclasses for null values
Issue: SPR-14423
2016-07-02 12:55:30 +02:00
Rossen Stoyanchev 9c29ed75f8 Suppress OPTIONS handling for an ERROR dispatch
Issue: SPR-14410
2016-06-30 12:34:54 -04:00
Juergen Hoeller 16949941f8 MatchableHandlerMapping extends HandlerMapping and lives in web.servlet.handler now
Issue: SPR-14321
2016-06-30 14:38:26 +02:00
Rossen Stoyanchev 89396ff01f Refactor handleNoMatch for @RequestMapping
Originally handleNoMatch looked for partial matches based on URL
pattern, HTTP method, consumes, produces, and params in that order
but without narrowing down the set of partial matches resulting in
potentially inaccruate response status codes

Commit 473de0 added an improvement to narrow the set with partial
matches for URL pattern and HTTP method matches.

This commit overhauls handleNoMatch so that the narrowing down of
matches happens at each stage resulting in more accurate error
reporting for request mappings with fine-grained conditions.

Issue: SPR-14397
2016-06-29 15:59:00 -04:00
Juergen Hoeller 2d5496df2b Polishing 2016-06-29 15:53:46 +02:00
Juergen Hoeller f2328e8e3c Polishing 2016-06-29 10:57:16 +02:00
Rossen Stoyanchev 775ffbe10b Improve static resource path check 2016-06-28 16:46:51 -04:00
Sam Brannen 1a7c6d3b10 Update @since tags in HandlerMappingIntrospector & Co. 2016-06-28 19:04:03 +02:00
Rossen Stoyanchev 2cdcf752ba MvcUriComponentsBuilder respects optional params
Issue: SPR-14405
2016-06-27 16:02:54 -04:00
Rossen Stoyanchev e38623df87 Fix MediaType lookup for ResourceHttpRequestHandler
As of 4.3 ResourceHttpRequestHandler delegates to the configured
ContentNegotiationManager, or one created internally, to look up
the media type for are resource.

This commit ensures the internally created ContentNegotiationManager is
correctly injected with the ServletContext through which it can perform
lookups as before.

Also the ServletPathContentNegotiationStrategy now checks the
ServletContext first and then delegates to its parent the
PathContentNegotiationStrategy and not vice versa. This is
consistent with how handleNoMatch (also in the same class) works
and also matches how ResourceHttpRequestHandler worked before 4.3.

Issue: SPR-14368
2016-06-27 14:56:55 -04:00
Rossen Stoyanchev a30ab30e4e Introduce HandlerMapping introspection API
Issue: SPR-14321
2016-06-27 14:23:02 -04:00
Brian Clozel a25c43f695 Enforce UTF-8 response encoding in SseEmitter
This commit sets the response content type to
"text/event-stream;charset=UTF-8". Even if the SSE spec says that the
encoding should always be UTF-8 and that specifying the charset is
optional, we're setting it in all cases, since some containers might use
the default encoding "ISO-8859-1" and confuse HTTP clients.

Issue: SPR-14407
2016-06-27 17:05:31 +02:00
Brian Clozel 0345d734e6 Improve exception logging in HandlerExceptionResolvers
This commit updates AbstractHandlerExceptionResolver to only log at the
WARN level exceptions that are actually resolved by the
ExceptionResolver.

In case developers wish to log each time an ExceptionResolver is called,
a DEBUG level log is still available.

Issue: SPR-14392
2016-06-23 14:12:37 +02:00
Rossen Stoyanchev 058279bc7e HEAD mapping has higher priority over other conditions
When comparing multiple matching @RequestMapping's, the HTTP method
condition has the lowest precedence. It's mainly about ensuring an
explicit mapping wins over an implicit (i.e. no method) one.

As of 4.3 HTTP HEAD is handled automatically for controller methods
that match to GET. However an explicit mapping HTTP HEAD allows an
application to take control.

This commit ensures that for HTTP HEAD requests the HTTP method
condition is checked first which means that an explicit HEAD mapping
now trumps all other conditions.

Normally we look for the most specific matching @RequestMapping.
For HTTP HEAD we now look for the most specific match among
@RequestMapping methods with a HEAD mapping first.

Issue: SPR-14383
2016-06-21 13:32:40 -04:00
Rossen Stoyanchev db1092f119 Polish RequestMappingInfoTests 2016-06-21 10:43:08 -04:00
Rossen Stoyanchev 919f6c96f9 ForwardedHeaderFilter is case-insensitive
Issue: SPR-14372
2016-06-17 14:20:42 -04:00
Juergen Hoeller 981c894acf @ExceptionHandler matches against cause type as well
Issue: SPR-14291
2016-06-07 21:22:01 +02:00
Juergen Hoeller 8c4bc3656b Polishing 2016-06-07 15:42:16 +02:00
Juergen Hoeller a9fda3e7e2 Defensive catching of any Throwable subclasses instead of just Error
Issue: SPR-14329
2016-06-04 00:17:20 +02:00
youmoo 9975f02e4d Method comment is wrong 2016-06-01 17:00:42 +02:00
Juergen Hoeller 37de0e45f6 Polishing 2016-06-01 11:39:08 +02:00
Rossen Stoyanchev fc40643033 Optimize Consumes/ProducesRequestCondition
Before this change Consumes/ProducesRequestCondition shared a common
match method in the package private AbstractMediaTypeExpression. The
benefit, two lines of code, was negligible but was forcing each
condition into parsing the content type of the request body or
evaluating the content type for the response respectively.

This change removes the shared match method and brings it down into
each sub-class resulting in a performance improvement as well as in
simpler code including exception handling.

Issue: SPR-14299
2016-05-31 14:55:50 -04:00
Rossen Stoyanchev 27215b5061 Negated produces works with no Accept header present
Issue: SPR-14299
2016-05-31 14:44:27 -04:00
Rossen Stoyanchev 8343ce9e44 Add defaultLocale to AcceptHeaderLocaleResolver
Issue: SPR-14312
2016-05-31 13:55:11 -04:00
Rossen Stoyanchev f20f6c952a Flush headers after null ResponseBodyEmitter
Issue: SPR-14315
2016-05-31 09:35:02 -04:00
Rossen Stoyanchev 431a50823f Polish 2016-05-31 09:35:01 -04:00
Lifu Zhou 7e95cd8b4e Flush headers after null StreamingResponseBody
Issue: SPR-14315
2016-05-31 09:34:51 -04:00
Juergen Hoeller 2d85accb83 SpringTilesContainerFactory uses Tiles 3's createDecoratedContainer
Issue: SPR-14311
2016-05-27 18:24:49 +02:00
Juergen Hoeller dacc31e3d3 For attribute is not actually required
Issue: SPR-14287
2016-05-26 19:18:30 +02:00
Rossen Stoyanchev c2625f968c Properly handle single-value map with @MatrixVariable
Issue: SPR-14294
2016-05-22 09:53:42 -04:00
Juergen Hoeller 5682950289 Polishing 2016-05-06 12:03:10 +02:00
Juergen Hoeller 42d32ba396 ResourceRegion fits better in core.io.support (next to EncodedResource)
Issue: SPR-14221
2016-05-06 12:02:51 +02:00
Juergen Hoeller e5dbe12e85 ResourceHttpRequestHandler sets "Accept-Ranges" header only once
Issue: SPR-14221
2016-05-06 11:50:47 +02:00
Sam Brannen 7b13311f03 Delete unused imports 2016-05-03 20:12:37 +02:00
Brian Clozel 5ac31fb39d Refactor HTTP Range support with ResourceRegion
Prior to this commit, the `ResourceHttpMessageConverter` would support
all HTTP Range requests and `MethodProcessors` would "wrap" controller
handler return values with a `HttpRangeResource` to support that use
case in Controllers.

This commit refactors that support in several ways:
* a new ResourceRegion class has been introduced
* a new, separate, ResourceRegionHttpMessageConverter handles the HTTP
range use cases when serving static resources with the
ResourceHttpRequestHandler
* the support of HTTP range requests on Controller handlers has been
removed until a better solution is found

Issue: SPR-14221, SPR-13834
2016-05-02 19:00:52 +02:00
Brian Clozel 977840884b Allow custom instances of WebJarAssetLocator
This commit allows to configure a custom WebJarAssetLocator in
WebJarResourceResolvers.

Issue: SPR-14092
2016-04-28 19:02:04 +02:00
Sebastien Deleuze 15138ed96f Revisit ScriptTemplateView resource loading
Resources are now retrieved using the application context in order to
support natively non-classpath locations like /WEB-INF/...

As a consequence of this refactoring, ScriptTemplateView#createClassLoader()
protected method as been removed, since it did not make sense anymore with
this new resource loading implementation.

Issue: SPR-14210
2016-04-28 15:40:14 +02:00
Juergen Hoeller d06188ed4d ResponseEntity allows for setting non-standard status code
Issue: SPR-14205
2016-04-26 23:06:10 +02:00
Rossen Stoyanchev 5ec6206e3f Update spring-mvc-3.2.xsd
The backport in commit cf39078 changed the spring-mvc-3.2.xsd.
This change updates the same in the master branch.

Issue: SPR-14186
2016-04-21 14:11:49 -04:00
Johnny Lim 44e652f99e Remove duplicate words
Closes gh-1039
2016-04-19 08:24:21 +02:00
Rossen Stoyanchev 7cdcc102a9 Explicit HEAD sorted higher than implicit GET match
Issue: SPR-14182
2016-04-17 15:12:43 -04:00
Juergen Hoeller 537193a4e0 Consistent license header 2016-04-11 20:49:38 +02:00
Juergen Hoeller 4ae065996b Polishing
(cherry picked from commit aa5c12c)
2016-04-08 23:06:25 +02:00
Juergen Hoeller 37bd51cf6d Handle Resources beyond int length through Servlet 3.1's setContentLengthLong
Issue: SPR-14135
2016-04-08 15:54:24 +02:00
Juergen Hoeller ed14ae60e5 Consistent deprecation of outdated MVC infrastructure classes
Issue: SPR-14128
2016-04-07 11:37:34 +02:00
Juergen Hoeller f6cb30b165 @ExceptionHandler is able to process Error thrown from handler method
Issue: SPR-11106
2016-03-31 11:52:36 +02:00
Juergen Hoeller 2dae4d8134 Deprecated FormTag's "commandName" in favor of "modelAttribute"
Issue: SPR-14094
2016-03-29 12:09:16 +02:00
Juergen Hoeller 94cb7786c8 Polishing 2016-03-25 23:28:45 +01:00
Juergen Hoeller 775bcccd10 Polishing 2016-03-24 21:44:16 +01:00
Juergen Hoeller 852212d0c5 Polishing 2016-03-24 19:57:54 +01:00
Juergen Hoeller 517ebd1d3e Consistent formatting 2016-03-24 19:22:50 +01:00
Juergen Hoeller 06db5aa43f Polishing 2016-03-24 15:34:17 +01:00
Juergen Hoeller 9a52c81443 UriComponentsBuilder allows more efficient (and less restrictive) CORS origin comparison
Also introduces a specifically narrowed cloneBuilder() method for UriComponentsBuilders.

Issue: SPR-14080
2016-03-24 15:33:44 +01:00
Juergen Hoeller 3eff478c45 RequestMethodsRequestCondition uses common HttpMethod resolution
Issue: SPR-13776
2016-03-24 13:54:00 +01:00
Juergen Hoeller 86d5c5c0f7 Avoid putIfAbsent call in HttpEntityMethodProcessor
Issue: SPR-14086
2016-03-24 13:51:48 +01:00
Brian Clozel 20bb25647f Polish 2016-03-24 10:56:46 +01:00
Juergen Hoeller 5025c615b1 Consistent use of AnnotatedElementUtils.findMergedAnnotation/hasAnnotation
Issue: SPR-13440
2016-03-23 18:39:20 +01:00
Juergen Hoeller 311d4c95a3 Revised newline handling tests pass on Windows now
Issue: SPR-13503
2016-03-23 18:35:26 +01:00
Brian Clozel e079a726f8 Polish 2016-03-23 16:40:12 +01:00
Brian Clozel c7bd3b8440 Support HTTP range requests in Controllers
Prior to this commit, HTTP Range requests were only supported by the
ResourceHttpRequestHandler when serving static resources.

This commit improves the ResourceHttpMessageConverter that
now supports partial writes of Resources.
For this, the `HttpEntityMethodProcessor` and
`RequestResponseBodyMethodProcessor` now wrap resources with HTTP
range information in a `HttpRangeResource`, if necessary. The
message converter handle those types and knows how to handle partial
writes.

Controller methods can now handle Range requests for
return types that extend Resource or HttpEntity:

    @RequestMapping("/example/video.mp4")
    public Resource handler() { }

    @RequestMapping("/example/video.mp4")
    public HttpEntity<Resource> handler() { }

Issue: SPR-13834
2016-03-23 16:40:12 +01:00
Brian Clozel 15fe8279e6 Reset Expires HTTP header when caching configured
Just like SPR-13252 addressed this issue for the "Pragma" header, this
issue resets the HTTP 1.0 "Expires" header.
When such a header has been set (by a filter, for example) and HTTP
caching has been configured at the WebContentGenerator, this header
value is reset to "". In this case, "Cache-Control" and "Expires" might
have inconsistent values and we consider that the HTTP caching
configuration should take precedence.

Depending on the servlet container chosen to deploy the application,
this might result in empty "" header values or no header set at all.

Issue: SPR-14053
2016-03-23 16:35:13 +01:00
Kazuki Shimizu 9b2023111d Add newline at the beginning of textarea macro for FreeMarker and Velocity
Issue: SPR-13503
2016-03-23 11:31:16 +01:00
Rossen Stoyanchev 7a5e93ff16 Add support for setting the "Vary" response header
Issue: SPR-14070
2016-03-22 21:47:55 -04:00
Rossen Stoyanchev 6bfe0c050d Polish 2016-03-22 20:59:16 -04:00
Rossen Stoyanchev 92dd4eb3ef Fix NPE in ResponseBodyEmitterReturnValueHandler
The possibility of NPE was introduced in the previous commit:
971ccab038

Issue: SPR-14046
2016-03-16 13:40:35 -04:00
Rossen Stoyanchev 582864802e Ensure RedirectModel is initialized
This commit fixes an old bug in ModelAndViewContainer where getModel
returns a new ModelMap instance that isn't saved and re-used.

Issue: SPR-14045
2016-03-14 23:00:19 -04:00
Rossen Stoyanchev 971ccab038 DeferredResult/ResponseBodyEmitter adapter mechanism
The DeferredResult~ and the ResponseBodyEmitterReturnValueHandler now
each expose an adapter mechanism for plugging in other async return
value types. As a result the ListenableFutureReturnValueHandler and
CompletionStageReturnValueHandler are no longer needed and are now
deprecated.

Issue: SPR-14046
2016-03-14 12:20:02 -04:00
Juergen Hoeller d124a13eb4 Consistent use of empty enumerations 2016-03-11 15:07:59 +01:00
Juergen Hoeller 8852a5e178 Support for placeholders in @CrossOrigin attributes
Issue: SPR-14010
2016-03-11 15:04:16 +01:00
Brian Clozel 8ca6a18dae Allow Validator config in XML websocket namespace
This commit adds a new "validator" XML attribute to the
`<websocket:message-broker/>` element. This allows configuring a
specific Validator to be used for payload validation.

Issue: SPR-13996
2016-03-10 16:35:20 +01:00
Brian Clozel 0a56667093 Fix SpringUrl Velocity macro URI encoding
Prior to this commit, the springUrl Velocity macro would only prepend
the context to the given URL; this means that the
ServletHttpResponse.encodeUri method is not called and neither the
ResourceUrlProvider.

This commit changes this macro to use RequestContext.getContextUrl which
prepends the context and encodes the URI.

Issue: SPR-14027
2016-03-08 17:07:59 +01:00
Rossen Stoyanchev ff2a911baa Update MVC config to use CNM for static resources
The MVC config now plugs the configured ContentNegotiationManager into
resource request handling.

Issue: SPR-13658
2016-03-04 16:06:01 -05:00
Rossen Stoyanchev f162256906 Use ContentNegotiationManager for static resources
The ResourceHttpRequestHandler now relies on the conifgured
ContentNegotiationManager to determine the content type for resource
requests rather than implementing that internally.

First we check against the matched resource based on the resource file
extension. Then we expand the check against the request with any
configured content negotiation strategy.

Issue: SPR-13658
2016-03-04 16:06:01 -05:00
Rossen Stoyanchev 1a76f7e9c2 Polish static resource handling 2016-03-04 16:05:49 -05:00
Brian Clozel 5067f00228 Polish
Issue: SPR-14018
2016-03-04 11:38:25 +01:00
Ruben Dijkstra 41da04d386 Remove duplicate slash from resolved WebJar locations
This commit updates the WEBJARS_LOCATION in WebJarResourceResolver to
avoid getting duplicate slashes in resolved resources locations such
as `/webjars//bootstrap/3.3.2/js/bootstrap.min.js`.

Issue: SPR-14018
2016-03-04 11:36:30 +01:00
Brian Clozel 44c32128dc Add newline at the beginning of textarea JSP tags
This commit adds a newline char at the beginning of textarea tags
values. As per the HTML 4.01 spec (and browsers behavior), a line break
following a start tag is ignored.

This can lead to Spring's textarea tag to ignore a line break char at
the beginning of a tag value.

See https://www.w3.org/TR/html401/appendix/notes.html#notes-line-breaks

Issue: SPR-13503
2016-03-03 16:48:17 +01:00
Brian Clozel 50bcd67fb6 Relax SPR-13867 changes for ResourceHttpRequestHandler
Prior to this change, SPR-13867 made sure that any class extending
WebContentGenerator would not overwrite existing HTTP "Cache-Control"
response headers - set by a filter, a Controller handler, etc.

This caused issues with resource handling, since specifying a cache
configuration there would not overwrite default headers set by filters,
for example by Spring Security.

This commit restricts the previous changes to the
RequestMappingHandlerAdapter, in order to avoid overwriting header set
by a filter or a Controller handler in those cases.

Issue: SPR-14005
2016-03-02 17:42:44 +01:00
Brian Clozel 3df66d023c Polish documentation on WebApplicationInitializer
Issue: SPR-13978
2016-03-01 17:38:52 +01:00
Sebastien Deleuze c385427397 Allow to specify AbstractHttpMessageConverter default charset
Before this commit, specifying the charset to use with produces or
consumes @RequestMapping attributes resulted in default charset
loss. That was really annoying for JSON for example, where using
UTF-8 charset is mandatory in a lot of use cases.

This commit adds a defaultCharset property to
AbstractHttpMessageConverter in order to avoid losing the
default charset when specifying the charset with these
@RequestMapping attributes.

It changes slightly the default behavior (that's why we have waited
4.3), but it is much more error prone, and will match with most
user's expectations since the charset loss was accidental in most
use cases (users usually just want to limit the media type supported
by a specific handler method).

Issue: SPR-13631
2016-02-29 23:34:32 +01:00
Sam Brannen 467b5f3f28 Introduce composed annotations for @RequestMapping
This commit introduces the following common composed annotations for
@RequestMapping in Spring MVC and Spring MVC REST.

- @GetMapping
- @PostMapping
- @PutMapping
- @DeleteMapping
- @PatchMapping

Issue: SPR-13992
2016-02-29 18:22:30 +01:00
Juergen Hoeller a02fd7c995 RequestMappingHandlerAdapter properly invokes handler method in case of no session as well
Issue: SPR-13999
2016-02-29 15:05:50 +01:00
Juergen Hoeller 9c0f99c0b5 Polishing 2016-02-29 12:57:09 +01:00
Juergen Hoeller 1815a6a7eb RequestMappingHandlerAdapter properly invokes handler method in synchronizeOnSession mode again
Issue: SPR-13999
2016-02-29 11:12:11 +01:00
Juergen Hoeller ca19920d74 Refined ApplicationContextInitializer assignability exception 2016-02-24 17:50:14 +01:00
Rossen Stoyanchev b3d67b928b Check supported locales in AcceptHeaderLocaleResolver
Issue: SPR-13330
2016-02-22 09:44:06 -05:00
Rossen Stoyanchev f32aded27a Consolidate CORS/OPTIONS request mapping
The CORS pre-flight request matching logic for all request conditions
was added (in 4.2) to RequestMappingInfo. However the logic for
default handling of all HTTP OPTIONS requests for 4.3 unintentionally
overrode some of the pre-flight request handling thus causing issues.

This commit moves CORS pre-flight matching logic into each respective
RequestMethodCondition implementations so each has to consider in one
place what happens for pre-flight and for all other requests.

Issue: SPR-13130
2016-02-19 13:56:52 -05:00
Rossen Stoyanchev 26575148a5 Polish test class 2016-02-19 13:56:52 -05:00
Rossen Stoyanchev 08eb623c41 Fix regression introduced in 4.3 snapshot
Commit ccd17d introduced a regression where a custom HTTP method
would no longer match for an empty @RequestMapping condition.

The previous behavior should now be restored. Effectively
RequestMethodRequestCondition as before will now match to any HTTP
method (even unknown/custom ones) if the methods condition is empty.
The only exception is HTTP OPTIONS for which we provide default
handling as a fallback (i.e. when not mapped explicitly).

Issue: SPR-13130
2016-02-18 14:37:36 -05:00
Sam Brannen c2f704717e Polish Javadoc for DefaultRequestToViewNameTranslator 2016-02-17 17:30:57 +00:00
Rossen Stoyanchev 024bd6e604 Polish 2016-02-17 08:23:18 -05:00
matthew-pearson 57b466fdfc 404 rather than 405 or 200
Check that the path is valid and resolvable before checking that the
http method is supported. For invalid or unresolvable paths, always
respond with a 404.
2016-02-17 08:23:18 -05:00
Juergen Hoeller f6ebc4ce97 Polishing 2016-02-11 22:24:50 +01:00
Rossen Stoyanchev a1e9e6f53e Polish MVC Java config tests 2016-02-10 15:29:56 -05:00
Rossen Stoyanchev d53c04b4df Add option to extend exception resolvers
Issue: SPR-13931
2016-02-10 15:26:40 -05:00
Rossen Stoyanchev c45ad3022b Add "hosts" property to RedirectView
Issue: SPR-13693
2016-02-10 14:21:27 -05:00
Rossen Stoyanchev aba04d576f Polish RedirectViewTests 2016-02-10 14:21:27 -05:00
Brian Clozel 0ab3f6092c Fix failing tests
Issue: SPR-13913
2016-02-10 13:48:49 +01:00
Rossen Stoyanchev cdfcc23b6f Reduce log level for @ExceptionHandler failure
Issue: SPR-13932
2016-02-09 12:57:02 -05:00
Rossen Stoyanchev e4539d9f40 Add protected method for required RequestBody 2016-02-05 02:24:03 -05:00
Rossen Stoyanchev 7756feacd8 Polish 2016-02-05 00:04:59 -05:00
Rossen Stoyanchev 1291d6e1bd Support CharSequence for response body
Issue: SPR-13423
2016-02-04 23:55:48 -05:00
Juergen Hoeller 28e8af2e2e AbstractXlsView does not explicitly flush (for compatibility with WebSphere Liberty)
Issue: SPR-13910
2016-02-04 19:48:05 +01:00
Rossen Stoyanchev aa064d7653 Polish MVC config tests 2016-01-29 14:58:32 -05:00
Rossen Stoyanchev 1cf0fb8174 Shared custom argument resolvers
Custom argument resolvers configured in the MVC Java config or the
MVC namespace are now injected in both the RequestMappingHandlerAdapter
as well as in the ExceptionHandlerExceptionResolver.

Issue: SPR-12058
2016-01-29 14:49:25 -05:00
Rossen Stoyanchev e62ada898b Add @RequestAttribute with servlet-based support
Issue: SPR-13894
2016-01-26 16:37:50 -05:00
Rossen Stoyanchev 698f923fc3 Add @SessionAttribute with Servlet-based support
Issue: SPR-13894
2016-01-26 16:37:44 -05:00
Juergen Hoeller 7df3a327f6 Polishing 2016-01-26 22:29:48 +01:00
Juergen Hoeller 3779fe9bf6 @UsesJava8 declaration on inner class
Issue: SPR-13850
2016-01-26 18:18:27 +01:00
Juergen Hoeller b4f33adf48 Consistent java.util.Optional resolution, lenient handling of optional multipart files, correct Servlet 3.0 Part list/array selection
Issue: SPR-13418
Issue: SPR-13849
Issue: SPR-13850
Issue: SPR-13893
2016-01-26 18:06:15 +01:00
Rossen Stoyanchev 2607a22537 HTTP OPTIONS lists all HTTP methods except TRACE
This is in line with the current behavior of HttpServlet that would
have been in used with dispatchOptionsRequest on the DispatcherSerlvet
set to false (the default prior to 4.3).

Issue: SPR-13130
2016-01-25 16:35:23 -05:00
Rossen Stoyanchev 319e8e2c2f Add allowHeader property to WebContentGenerator
The WebContentGenerator now maintains an additional property that
sub-classes can use for an "Allow" header in response to an HTTP
OPTIONS request. This property is pre-initialized once at startup
and does not have to rely on getSupportedMethods in addition to
adding HTTP OPTIONS if not explicitly listed.

Issue: SPR-13130
2016-01-25 16:35:15 -05:00
Rossen Stoyanchev 135738f9bf AbstractController supports HTTP OPTIONS
Issue: SPR-13130
2016-01-25 08:49:04 -05:00
Rossen Stoyanchev ccd17dfaea Support HTTP OPTIONS
Issue: SPR-13130
2016-01-24 20:18:41 -05:00
Rossen Stoyanchev d70ad765bf Support HTTP HEAD
Issue: SPR-13130
2016-01-24 20:18:41 -05:00
Rossen Stoyanchev fb7dfc4569 Polish 2016-01-24 20:18:35 -05:00
Brian Clozel 2b3ad218e5 Clarify RequestMappingHandlerAdapter javadoc
This commit updates the javadoc of
`RequestMappingHanderAdapter.setCacheSecondsForSessionAttributeHandlers`
to explain how one can disable that feature and prevent "Cache-Control"
directives from being added when `@SessionAttributes` annotations are
used on Controllers.

Issue: SPR-13598
2016-01-22 21:17:58 +01:00
Brian Clozel 84fe46cd43 Register prefixed path patterns with FixedVersionStrategy
Prior to this change, configuring a `FixedVersionStrategy` like so
would configure a single "/js/**" path pattern:

```
versionResourceResolver.addFixedVersionStrategy("v1.0.0","/js/**");
```

This commit makes sure that for each path pattern, its prefixed version
is added to the map. For example, the previous configuration also
adds "/v1.0.0/js/**".

Issue: SPR-13883
2016-01-22 18:30:39 +01:00
Brian Clozel 8f1d06f19c Reorder HTTP headers processing in RequestMappingHandlerAdapter
Prior to this change, the `RequestMappingHandlerAdapter` would first add
a "Cache-Control" HTTP header to the response (depending on its
`WebContentGenerator` configuration and `@SessionAttributes` on the
handler class); then, the Adapter would delegate the actual handler the
processing of the request.
This leads to issues, as the handler does not have full control to the
response and has to deal with pre-existing headers in the response. This
means that the Adapter and the handler can add incompatible
Cache-Control directives without knowing it, since one cannot see the
headers added by the other until the response is committed.

This commit switches the order of execution: first, the handler is
called (possibly adding HTTP headers), then the RMHA processes the
response and adds "Cache-Control" directives *only if there's no
Cache-Control header already defined*.

Issue: SPR-13867
2016-01-22 16:04:03 +01:00
Rossen Stoyanchev ebccfd023a MVC Java config protected factory methods
This change exposes protected methods for instantiating sub-classes of
RequestMappingHandlerAdapter and ExceptonHandlerExceptionResolver
similar to the existing method for RequestMappingHandlerMapping.
2016-01-22 09:48:50 -05:00
Brian Clozel 2f6d86b7aa Fix OutOfBoundsExceptio in ResourceUrlEncodingFilter
Prior to this change, the `ResourceUrlEncodingFilter` would try to
lookup resources URLs as soon as the given URL would be longer than the
expected context+servlet prefix path. This can lead to
OutOfBoundsExceptions when the provided URL does not start with that
prefix and still has the required length.

This commit makes sure that all candidate URLs for resources lookup are
prefixed with the cached servlet and context path. This underlines the
fact that the `ResourceUrlEncodingFilter` does not support relative URLs
for now and delegates to the native servlet implementation in that case.

Issue: SPR-13861
2016-01-21 17:28:29 +01:00
Rossen Stoyanchev 9e16cbda4c Polish ServletServerHttpRequest change 2016-01-20 17:50:36 -05:00
Sammy Chu 5185953f29 Avoid double encoding URI in ServletServerHttpRequest
Issue: SPR-13876
2016-01-20 17:42:40 -05:00
Rossen Stoyanchev a5f4aa6824 Add HttpStatus to ModelAndView
Issue: SPR-13560
2016-01-20 16:54:05 -05:00
Rossen Stoyanchev 73a794336c Support @ResponseStatus on controller type level
Issue: SPR-13547
2016-01-15 17:15:34 -05:00
Juergen Hoeller 9761af9ad8 Validate @RequestMapping methods on AOP proxies
Issue: SPR-13842
2016-01-15 17:01:58 +01:00
Stephane Nicoll 2fc2c29e9a Update copyright header 2016-01-15 10:51:11 +01:00
Rossen Stoyanchev 24fdf64d91 Fix javadoc issue in ResponseEntityExceptionHandler
Issue: SPR-13869
2016-01-14 14:25:30 -05:00
Juergen Hoeller 773d175681 Polishing 2016-01-13 12:52:05 +01:00
Brian Clozel cdda839426 XML configuration support for RFC 5861
This commit adds the XML+XSD configuration part of the RFC 5861
Cache-Control directives added in Spring's `CacheControl`.

Issue: SPR-13841
2016-01-07 18:13:34 +01:00
Brian Clozel d681f77d62 Polish
Issue: SPR-13817
2016-01-05 17:31:30 +01:00
Brian Clozel 473cf9c40e Preserve ETag HTTP header for versioned resources
Prior to this change, a resource handler chain configured with a
`VersionResourceResolver` would add the resource version to the request
attributes when serving that resource. This approach would not work when
a `CachingResourceResolver` is configured and the resource is already
cached. Indeed, that code path is not executed when the resource is
resolved from the cache.

This commit adds a new `VersionedResource` interface that's used by the
`VersionResourceResolver`, adding a `getVersion()` method that returns
the version string for that resource. This way, the version information
is cached with the resource itself and the request attributes are no
longer used for this.

Issue: SPR-13817
2016-01-05 14:55:14 +01:00
Rossen Stoyanchev 74b77e0d74 Fix warnings 2015-12-22 16:16:51 -05:00
Rossen Stoyanchev 12b73caa84 Add @RestControllerAdvice
Issue: SPR-13673
2015-12-22 16:11:34 -05:00
Juergen Hoeller 41ee25b1e7 Convenience constructors for common view prefix/suffix scenarios
Issue: SPR-13813
2015-12-22 12:00:49 +01:00
Juergen Hoeller 57b3ee324f Tiles 2 support back for Spring 4.3 (to be eventually removed for 5.0 now)
Issue: SPR-13229
2015-12-21 22:15:22 +01:00
Juergen Hoeller 4668aa775d Language tag methods declared as @UsesJava7
Issue: SPR-13274
2015-12-21 19:08:37 +01:00
Juergen Hoeller 0dd320f92e Support for BCP 47 language tags
Issue: SPR-13032
2015-12-21 18:40:26 +01:00
Juergen Hoeller 2e6eb614b5 Avoid scoped destruction callbacks in case of no post-processor actually applying
Issue: SPR-13744
2015-12-18 17:14:57 +01:00
Juergen Hoeller 3d87718fc6 DispatcherServlet and ServletWrapping/ForwardingController accept any HTTP method by default
Issue: SPR-4799
2015-12-18 12:57:18 +01:00
Sam Brannen 5b3edcd9f9 Spring Cleaning in December
- Delete unused imports
- Delete unused code
- Clean up warnings
2015-12-17 20:27:33 +01:00
Juergen Hoeller 0e68d2e951 Explicit references to spring-mvc-4.2.xsd for Velocity declarations
Issue: SPR-13235
2015-12-17 18:30:11 +01:00
Juergen Hoeller a2a9c47e59 Deprecate Velocity support
Issue: SPR-13235
2015-12-17 17:15:57 +01:00
Juergen Hoeller 8ce5e88c66 Require Jackson 2.6+, FreeMarker 2.3.21+, XStream 1.4.5+
Issue: SPR-13062
2015-12-17 17:14:50 +01:00
Stephane Nicoll 752d3c715a Initiate structure for 4.3 XSDs 2015-12-17 15:43:23 +01:00
Juergen Hoeller 997278e3ed Polishing 2015-12-16 20:19:41 +01:00
Juergen Hoeller 5626384812 Consistent trace log messages and general polishing 2015-12-16 15:59:02 +01:00
Brian Clozel 3be35c053d Use LinkedHashmap to preserve insert order
In several places in the spring-webmvc module, URL patterns / objects
relationships are kept in `HashMap`s. When matching with actual URLs,
the algorithm uses a pattern comparator to sort the matching patterns
and select the most specific. But the underlying collection
implementation does not keep the original order which can lead to
inconsistencies.

This commit changes the underlying collection implementation to
`LinkedHashmap`s, in order to keep the insert order if the comparator
does not reorder entries.

Issue: SPR-13798
2015-12-16 15:24:35 +01:00
Juergen Hoeller 9e03e0e73d Polishing 2015-12-15 11:53:40 +01:00
Juergen Hoeller ef1e17fd15 Polishing 2015-12-13 01:14:38 +01:00
Juergen Hoeller 0968e47b04 Polishing 2015-12-11 21:56:26 +01:00
Rossen Stoyanchev dc7ed57c67 Support resource URL encoding at context path
Issue: SPR-13757
2015-12-10 12:24:04 -05:00
Juergen Hoeller 11806b9215 Class identity comparisons wherever possible (and further polishing)
Issue: SPR-12926
2015-12-09 12:28:09 +01:00
Juergen Hoeller 4261f34b63 Consistent and lenient HttpMethod resolution across all web modules
Issue: SPR-13776
2015-12-09 12:26:44 +01:00
Rossen Stoyanchev 153a23dbf9 Configure view controllers with ApplicationContext
Issue: SPR-13762
2015-12-04 13:09:37 -05:00
Juergen Hoeller 08ff3a85bf Integration test for proper re-resolution of Optional @RequestPart argument
Includes a trivial refinement of RestTemplate's ResourceAccessException message.

Issue: SPR-13755
2015-12-03 12:55:32 +01:00
Juergen Hoeller a9e5e9ecc8 Polishing 2015-12-02 15:35:42 +01:00
Brian Clozel c226753985 Do not rewrite relative links with FixedVersionStrategy
Prior to this change, the resource handling FixedVersionStrategy would
be applied on all links that match the configured pattern. This is
problematic for relative links and can lead to rewritten links such as
"/fixedversion/../css/main.css" which breaks.

This commit prevents that Strategy from being applied to such links.
Of course, one should avoid to use that VersionStrategy with relative
links, but this change aims at not breaking existing links even if it
means not prefixing the version as expected.

Issue: SPR-13727
2015-12-01 14:47:23 +01:00
Juergen Hoeller a0747c2148 Consistent bean type checking for endpoint handlers
Issue: SPR-13725
2015-11-25 21:26:03 +01:00
Brian Clozel b35d44bd4c Fix inputstream reading for HTTP range requests
Prior to this commit, range requests would be served by
ResourceHttpRequestHandler by partially reading the inputstream of
static resources. In case of resources contained in ZIP/JAR containers,
InputStreams may not fill the entire read buffer when calling
`inputStream.read(byte[])`. This was the case when using Spring Boot's
ZipInflaterInputStream - this would then not read the entire file
content and would close the response without writing the expected body
length indicated in the "Content-Length" header.

This commit makes sure that the whole resource is read.

Issue: SPR-13661
2015-11-24 21:36:22 +01:00
Johnny Lim 2defb6555e Fix broken Javadoc related to `<` and `>` 2015-11-12 11:22:08 +01:00
Rossen Stoyanchev e707347474 Fix failing tests 2015-11-11 18:02:50 -05:00
Rossen Stoyanchev 3a919a48d6 Switch "attachment" to "inline" on Content-Disposition
Issue: SPR-13587, SPR-13643
2015-11-11 17:14:29 -05:00
Juergen Hoeller 760bc719f2 Polishing 2015-11-09 15:03:14 +01:00
Juergen Hoeller bc7bcab578 Consistent method selection for listeners and endpoint mappings
Issue: SPR-13654
2015-11-09 14:57:45 +01:00
Rossen Stoyanchev a3168fde18 Expand range of whitelisted extensions by media type
This commit expands the range of whitelisted extensions by checking
if an extension can be resolved to image/*, audo/*, video/*, as well
as any content type that ends with +xml.

Issue: SPR-13643
2015-11-06 16:45:41 -05:00
Rossen Stoyanchev 237439ef97 Whitelist extension if present in the request mapping
We know skip the Content-Disposition header for any extension if the
chosen request mapping explicitly contains the URl extension.

Issue: SPR-13629
2015-11-06 12:37:13 -05:00
Brian Clozel 889366320d Do not process undefined conditional HTTP requests
Prior to this change, the HttpEntityMethodProcessor would try to process
conditional requests that are undefined by the spec, such as:

* an HTTP GET request with "If-None-Match:*"
* a request with both "If-None-Match" and "If-Match"
* a request with both "If-None-Match" and "If-Unmodified-Since"

This commit skips the processing of those requests as conditional
requests and continues with normal request handling.

Issue: SPR-13626
2015-11-06 17:59:41 +01:00
Rossen Stoyanchev ac975df448 Fix javadoc ambiguity
Issue: SPR-13642
2015-11-05 20:02:37 -05:00
Rossen Stoyanchev f0464e8176 Add section on RFD + whitelist yml/properties/csv
Issue: SPR-13643
2015-11-05 19:31:29 -05:00
Rossen Stoyanchev bdb71e91ad No Content-Disposition if HTML in the request mapping
Issue: SPR-13629
2015-11-02 13:07:48 -05:00
Juergen Hoeller cca037a74d Polishing 2015-11-02 14:42:46 +01:00
Juergen Hoeller ce20268597 Consistent warn logging without stacktrace in Portlet HandlerExceptionResolver
Issue: SPR-13611
2015-11-02 14:19:58 +01:00
Sebastien Deleuze 76d7f4527a Revert most SPR-13100 changes since SPR-13267 was a better fix
Issue: SPR-13596
2015-11-02 10:40:53 +01:00
Rossen Stoyanchev 598fafd957 Fix failing test 2015-10-29 21:02:45 -04:00
Rossen Stoyanchev c5995149b3 Further improve detecttion of custom CNVR
Refine the approach of having <mvc:view-resolvers> detect and use the
ContentNegotiationManager instance registered with
<mvc:annotation-driven> introduced in the last commit.

Issue: SPR-13559
2015-10-29 20:58:31 -04:00
Rossen Stoyanchev f84a0c914a Detect custom ContentNegotiationViewResolver
The <mvc:annotation-driven> element now adds an alias when a
ContentNegotiationManager bean is registered with a custom name.
This helps <mvc:view-resolvers> to more reliably find such a custom
ContentNegotiationManager.

Issue: SPR-13559
2015-10-29 18:01:00 -04:00
Brian Clozel 9334fabe26 Don't throw NPE when serving webjar directories
Prior to this change, serving resources with ResourceHttpRequestHandler
could result in NPE when requesting an existing folder located in a JAR.

This commit swallows those exceptions, as it is not possible to foresee
those cases without reading the actual resource. This result in a HTTP
200 response with a zero Content-Length instead of a HTTP 500 internal
exception.

Issue: SPR-13620
2015-10-29 16:10:27 +01:00
Juergen Hoeller a778468771 Consistent JSP tag documentation
Issue: SPR-13520
2015-10-28 18:31:17 +01:00
Juergen Hoeller a268cdb913 Fixed javadoc links to setCacheSeconds 2015-10-28 16:06:59 +01:00
Juergen Hoeller 6d369308cc Improved SessionLocaleResolver documentation
Issue: SPR-13505
2015-10-28 14:30:08 +01:00
Juergen Hoeller c1c07bbeb2 AbstractDispatcherServletInitializer allows for registering any FrameworkServlet subclass
Issue: SPR-13616
2015-10-28 14:00:20 +01:00
Juergen Hoeller 400749667a Polishing 2015-10-26 23:10:33 +01:00
Rossen Stoyanchev 1c382be00e Expose build method in SseEventBuilder
Issue: SPR-13591
2015-10-26 16:19:10 -04:00
Rossen Stoyanchev 050e79e45e Skip Content-Disposition header if status != 2xx
Issue: SPR-13588
2015-10-26 16:01:32 -04:00
Rossen Stoyanchev 2bd1daa75e Protect against RFD exploits
Issue: SPR-13548
2015-10-15 10:33:27 +02:00
Juergen Hoeller 6256586047 Polishing 2015-10-12 18:12:31 +02:00
Juergen Hoeller 1d59c5fd41 StandardScriptEvaluator uses same eval exception exposure as ScriptTemplateView
Issue: SPR-13557
2015-10-09 22:55:01 +02:00
Juergen Hoeller 44b76d39a4 ExceptionHandlerExceptionResolver allows for Model parameter
Issue: SPR-13546
2015-10-07 20:06:06 +02:00
Sam Brannen 28c07a6d38 Polish Javadoc for MVC exception handling classes 2015-10-06 17:30:45 +02:00
Sam Brannen 7ac6af0fb0 Polish Javadoc for AsyncHandlerInterceptor & RequestBodyAdvice 2015-10-06 09:35:24 +02:00
Rossen Stoyanchev 42e5ad4111 Polish 2015-09-30 14:05:08 -04:00
Rossen Stoyanchev 24a91b43cc Polish content negotiation 2015-09-29 17:08:37 -04:00
Sam Brannen 452b124ff6 Polish FreeMarker tests and suppress warnings 2015-09-28 19:33:49 +02:00
Sam Brannen 58c2990794 Reinstate and modernize Jasper Reports tests 2015-09-28 19:22:23 +02:00
Sam Brannen d5ee787e1e Migrate JUnit 3 tests to JUnit 4
This commit migrates all remaining tests from JUnit 3 to JUnit 4, with
the exception of Spring's legacy JUnit 3.8 based testing framework that
is still in use in the spring-orm module.

Issue: SPR-13514
2015-09-27 21:17:51 +02:00
Sebastien Deleuze 1580288815 Improve error reporting in ScriptTemplateView
This commit introduces a new ScriptRenderException in order to:
 - Print in the resulting error page the reason of the script failure
 - Not print the whole stacktrace in the logs

The ScriptRenderException thrown in ScriptTemplateView#renderMergedOutputModel()
is wrapped into a ServletException in order to avoid printing 2 times the messages in
the logs (throwing directly a ScriptRenderException would make it wrapped in a
NestedServletException that contains a getMessage() override not needed in this
context)

Issue: SPR-13488
2015-09-26 10:30:48 +02:00
Rossen Stoyanchev fdbe8dc4c1 ResponseBodyEmitter detects timeout/completion
ResponseBodyEmitter now registers by default to receive callbacks
on timeout/completion and sets its internal "complete" flag to true
in order to prevent proactively further use of the emitter.

Issue: SPR-13498
2015-09-25 14:06:33 -04:00
Juergen Hoeller 11b4e3be2c Consistent HttpMethod resolution against underlying HttpServletRequest 2015-09-24 20:53:22 +02:00
Brian Clozel 7f700cc63e Polish 2015-09-24 19:58:58 +02:00
Brian Clozel 583a48ab75 Do not process conditional requests for non-GET
Prior to this commit, HttpEntityMethodProcessor would process
conditional requests even if those aren't GET requests.
This is an issue for POST requests with "If-None-Match: *" headers and
many other use cases, which should not receive an HTTP 304 Not Modified
status in response.

This commit only triggers ETag/Last-Modified conditional requests bits
for GET requests.

Issue: SPR-13496
2015-09-24 17:49:20 +02:00
Juergen Hoeller c34a62e141 LocaleChangeInterceptor allows for ignoring invalid locale values
Issue: SPR-9456
2015-09-24 00:32:45 +02:00
Rossen Stoyanchev ffd9c62fc8 Translate IOException to HttpMessageNotReadableEx
Some converters (Jackson, Gson, Protobuf) already do this. It is now
also done in AbstractMessageConverterMethodArgumentResolver which
enforces a consistent behavior across controller method arguments.

Issue: SPR-12745
2015-09-23 17:22:37 -04:00
Juergen Hoeller 54d3d782a9 Polishing 2015-09-23 22:44:52 +02:00
Juergen Hoeller c7fd4ccf48 StandardScriptUtils.retrieveEngineByName for lookup with descriptive exception message
Also revised StandardScriptFactory for finer-grained template methods, added further configuration variants to StandardScriptEvaluator, and identified thread-local ScriptEngine instances in ScriptTemplateView by appropriate key.

Issue: SPR-13491
Issue: SPR-13487
2015-09-23 22:37:35 +02:00
Juergen Hoeller fe3aad4ab2 Latest dependency updates (H2 1.4.189, Underscore.js 1.8.3) 2015-09-23 22:03:08 +02:00
Sebastien Deleuze cffad9d4b1 Limit the number of ScriptEngine instances to the number of threads
This commit makes ThreadLocal<ScriptEngine> engineHolder ScriptTemplateView
field static in order to limit the maximum number of ScriptEngine instances
to the number of threads, regardless of the number of view instances.

Issue: SPR-13487
2015-09-23 13:17:37 +02:00
Nicolas Labrot e4c0859d41 Support @CrossOrigin as a merged composed annotation
Issue: SPR-13468
2015-09-22 14:55:42 -04:00
Sam Brannen 74b05118eb Polish RequestMappingHandlerMappingTests 2015-09-22 14:35:19 -04:00
Sam Brannen e2bfbdcfd1 Support attribute overrides with @ResponseStatus
This commit introduces support for attribute overrides for
@ResponseStatus when @ResponseStatus is used as a meta-annotation on
a custom composed annotation.

Specifically, this commit migrates all code that looks up
@ResponseStatus from using AnnotationUtils.findAnnotation() to using
AnnotatedElementUtils.findMergedAnnotation().

Issue: SPR-13441
2015-09-11 21:05:30 +02:00
Sebastien Deleuze f3b7e9ff2d Expose view url to render function in ScriptTemplateView
After this change, with Nashorn it is possible to use either
render(template, model) or render(template, model, url).
With JRuby or Jython, specifying the 3 parameters is mandatory.

Issue: SPR-13453
2015-09-09 18:05:04 +02:00
Sebastien Deleuze ff02ad47e0 Close properly the InputStream in ScriptTemplateView#getTemplate()
Issue: SPR-13445
2015-09-09 12:15:48 +02:00
Juergen Hoeller 99f72ce3db Polishing 2015-09-09 11:45:12 +02:00
Juergen Hoeller 5f598586ea SseEmitter exposes super constructor with timeout value
Issue: SPR-13446
2015-09-09 11:43:52 +02:00
Juergen Hoeller 52fdfd59ab Polishing 2015-09-08 18:11:30 +02:00
Juergen Hoeller 667fc7e4a9 Polishing 2015-09-04 14:38:47 +02:00
Brian Clozel e81a430e61 Fix @RequestBody(required=false) support
Prior to this commit, requests with an empty body and no Content-Type
header set would fail with a HttpMediaTypeNotSupportedException when
mapped to a Controller method argument annotated with
@RequestBody(required=false).
In those cases, the server implementation considers with an
"application/octet-stream" content type and polls messageconverters for
conversion. If no messageconverter is able to process this request, a
HttpMediaTypeNotSupportedException is thrown.

This change makes sure that such exceptions are not thrown if the
incoming request has:
* no body
* no content-type header

In this case, a null value is returned.

Issue: SPR-13147
2015-09-03 14:53:43 +02:00
Juergen Hoeller eaba794823 Removed misleading note on readonly and disabled flags in spring-form.tld
Issue: SPR-13397
2015-08-27 11:50:10 +02:00
Rossen Stoyanchev 1a9e42b49d Support multipart filename with charset
StandardMultipartHttpServletRequest now supports filenames with
charset information.

Issue: SPR-13319
2015-08-25 20:54:43 -04:00
Juergen Hoeller 4314da922a RedirectView and RequestContext use RequestContextUtils.findWebApplicationContext
Issue: SPR-13346
2015-08-25 22:16:27 +02:00
Juergen Hoeller 6aa9e0caf9 mvc:tiles-configurer supports preparer-factory and definitions-factory
Issue: SPR-13363
2015-08-25 18:10:27 +02:00
Brian Clozel 190eb6ace1 Set ETag header with VersionResourceResolver
Prior to this change, VersionResourceResolver and VersionStrategy would
resolve static resources using version strings. They assist
ResourceHttpRequestHandler with serving static resources. The
RequestHandler itself can be configured with HTTP caching strategies to
set Cache-Control headers.

In order to have a complete strategy with Cache-Control and ETag
response headers, developers can't reuse that version string information
and have to rely on other mechanisms (like ShallowEtagHeaderFilter).

This commit makes VersionResourceResolver use that version string to set
it as a request attribute, which will be used by the
ResourceHttpRequestHandler to write an ETag response header.

Issue: SPR-13382
2015-08-25 16:49:10 +02:00
Brian Clozel 0b9c3de320 Sanitize request URL in ResourceUrlEncodingFilter
Prior to this change, ResourceUrlEncodingFilter and ResourceUrlProvider
would try to resolve the resource path using the full request URL (i.e.
request path and request parameters), whereas the request path is the
only information to consider.
This would lead to StringIndexOutOfBoundsExceptions when the path +
request params information was given to the AntPathMatcher.

This commit makes the appropriate change to both
ResourceUrlEncodingFilter and ResourceUrlProvider, in order to only
select the request path.

Issue: SPR-13374
2015-08-25 14:12:03 +02:00
Sebastien Deleuze 04cff89eb7 Update ScriptTemplateView to manage content type
This commit introduces the following changes:
 - Content type can now be properly configured
 - Default content type is "text/html"
 - Content type and charset are now properly set in the response

Issue: SPR-13379
2015-08-25 01:02:12 +02:00
Sam Brannen 2df3646e90 Let Jetty pick its own available port
In an attempt to make our Jetty-based integration tests more robust,
this commit discontinues use of SocketUtils for picking a random,
available port and instead lets the Jetty Server pick its own port.
2015-08-22 18:58:55 +02:00
Juergen Hoeller c685fd7c23 Polishing 2015-08-21 17:03:53 +02:00
Sebastien Deleuze d4c74ad346 Add an ObjectMapper constructor to MappingJackson2(Json|Xml)View
Instead of having to use the default constructor then calling
setObjectMapper(ObjectMapper), these constructors allow
MappingJackson2JsonView and MappingJackson2XmlView to be created and
configured with the desired object mapper in one step.
2015-08-19 14:04:15 +02:00
Sebastien Deleuze 4338719d98 Serialize with type only collections in Jackson HttpMessageConverter
Issue: SPR-13318
2015-08-17 17:17:51 +02:00
Rossen Stoyanchev f5210ce0c8 Ensure headers committed immediately for SseEmitter
Issue: SPR-13341
2015-08-12 15:05:29 -04:00
Juergen Hoeller e0f012f32d Removal of redundant JdkVersion checks in the test suite
Issue: SPR-13312
2015-08-12 18:42:36 +02:00
Juergen Hoeller e841cad577 Deprecation polishing 2015-08-11 13:59:31 +02:00
Juergen Hoeller 9ef38807e6 Polishing 2015-07-30 19:34:33 +02:00
Brian Clozel 80767ff6e9 Use sendError in ResponseStatusExceptionResolver
Prior to this commit, the `ResponseStatusExceptionResolver` would use:
* `HttpServletResponse.sendError` if both a status and a reason are set
on the `@ResponseStatus` annotation
* `HttpServletResponse.setStatus` if only a status is set on the
`@ResponseStatus` annotation

This is actually a change of behavior, since this Resolver was using
`sendError` in all cases previously.

Because this change can create issues such as
https://github.com/spring-projects/spring-boot/issues/3623
this commit rollbacks those changes and clarifies the behavior on the
javadoc of the annotation itself.

Issue: SPR-11193, SPR-13226
2015-07-30 16:10:01 +02:00
Juergen Hoeller e8ef3654c6 Polishing 2015-07-30 12:16:59 +02:00
Juergen Hoeller 10a2f50130 Overridable invokeHandlerMethod and createInvocableHandlerMethod hooks
Issue: SPR-13293
2015-07-30 12:13:06 +02:00
Juergen Hoeller ff46cec58f Polishing 2015-07-29 12:40:35 +02:00
Juergen Hoeller 965fca808a Polishing 2015-07-29 01:08:16 +02:00
Juergen Hoeller d83735694e Polishing 2015-07-28 12:15:48 +02:00
Juergen Hoeller 9e62c8efa1 DefaultHandlerExceptionResolver logs warn entries for conversion exceptions
Issue: SPR-13267
2015-07-28 12:14:42 +02:00
Brian Clozel 0e2e6cf045 Polish WebJarsResourceResolver
Follow up to accb8519fd - same fix when resolving missing resources or
resolving a public URL for these resources.
2015-07-27 15:06:51 +02:00
Brian Clozel accb8519fd Polish WebJarsResourceResolver
Fix a potential NPE when trying to resolve non-existing webjars
resources in the resolver chain.
2015-07-27 14:16:09 +02:00
Sam Brannen b6c0e7cba3 Remove trailing whitespace in Java source code 2015-07-27 12:40:54 +02:00
Juergen Hoeller e1cce309ae DispatcherServlet passes resolved multipart request into applyDefaultViewName
Issue: SPR-13272
2015-07-24 18:19:27 +02:00
Sebastien Deleuze 8e5244ac3d Polish script templating documentation 2015-07-24 00:00:24 +02:00
Juergen Hoeller 1a636b1023 Polishing 2015-07-21 20:33:13 +02:00
Juergen Hoeller 7c22d60fd8 Streamlined WebContentGenerator API variants: checkRequest, prepareResponse, applyCacheControl, applyCacheSeconds
Issue: SPR-11792
2015-07-21 20:33:03 +02:00
Brian Clozel 088a50c1fb Improve setDateHeader impl in MockServletResponse
Prior to this change, calling the `setDateHeader` method on a
MockHttpServletResponse instance (internal implementation for testing
the spring-web module) would just store the given long value in a Map,
not writing it as a formatted date String.

This can be problematic when testing features related to date headers
such as "Expires", "If-Modified-Since", "Last-Modified", etc.

This commit formats long dates into date Strings using the date format
recommended by the RFC and the GMT time zone.
2015-07-21 14:28:44 +02:00
Brian Clozel eef937e4f2 Rename <mvc:cachecontrol/> to <mvc:cache-control/> 2015-07-21 12:09:25 +02:00
Brian Clozel 9149bf7ad4 Polish 2015-07-21 11:57:02 +02:00
Felix 09e3fc40e5 Reset Pragma header in WebContentGenerator
As filter-based libraries and projects (such as Spring Security) may
use the "Pragma" header in HTTP responses, WebContentGenerator should
make sure that such headers are overwritten to avoid clashes with
the HTTP caching headers set by the HTTP caching configuration.

Issue: SPR-13252
2015-07-21 10:08:04 +02:00
Brian Clozel dba46c1358 Partial revert of SPR-13090
Use ServletHttpResponse.setDateHeader whenever possible and avoid using
SimpleDateFormat.
2015-07-20 22:48:20 +02:00
Sebastien Deleuze 70a03ee2a4 Rename CorsConfigurationMapping to UrlBasedCorsConfigurationSource
Issue: SPR-13192
2015-07-20 10:47:24 +02:00
Sam Brannen 6950d977c2 Polish and simplify DispatcherServletInitializerTests 2015-07-19 19:52:38 +02:00
Sam Brannen 5f3506ae8f Suppress build warnings in tests 2015-07-19 19:28:16 +02:00
Brian Clozel 106cce58cc Fix tests
Issue: SPR-13241
2015-07-17 13:32:38 +02:00
Brian Clozel 064abad9d8 PathResourceResolver should not resolve root path
When resolving resources, the PathResourceResolver creates a Resource
instance and checks whether this resource `exists()` and `isReadable()`.
While that last call returns false for folders on the file system, both
calls return true for folders located inside JARs.

If a JAR location is configured as a resource location, then
PathResourceResolver can resolve folders in JARs as valid locations and
candidates for paths resolution.

Prior to this change, the PathResourceResolver would resolve "" as a
valid resource path (here, the "/META-INF/resources/webjars" if
configured, for example) and return a "" path for this resource,
effectively turning all "/" URLs into empty ones "".

This commit fixes the resolveUrlPathInternal implementation by not
allowing empty paths as valid resource paths.

Issue: SPR-13241
2015-07-17 10:31:37 +02:00
Juergen Hoeller d183bbb667 Javadoc refinements, exception fine-tuning, general polishing
Issue: SPR-13034
2015-07-15 15:42:17 +02:00
Sebastien Deleuze 34de167e59 Support non thread-safe ScriptEngine in ScriptTemplateView
This commit adds a new sharedEngine property to ScriptTemplateConfigurer
and ScriptTemplateView in order to support non thread-safe ScriptEngine
implementations like Nashorn.

When this flag is set to false, the engine is retrieved from a
ThreadLocal<ScriptEngine> field instead of a ScriptEngine one.

Also as part of this commit, all the initialization logic has been moved from
ScriptTemplateConfigurer to ScriptTemplateView since the script engine can
now be lazily initialized multiple time in the view when sharedEngine is
set to false.

Issue: SPR-13034
2015-07-15 13:39:33 +02:00
Juergen Hoeller bdb63483df Common DataWithMediaType class and common synchronization for ResponseBodyEmitter/SseEmitter
Issue: SPR-13223
Issue: SPR-13224
2015-07-14 00:08:40 +02:00
Stephane Nicoll d738dddd8f Add `createDispatcherServlet` hook point
Add an extra hook point in `AbstractDispatcherServletInitializer` to
customize the `DispatcherServlet`.

Issue: SPR-13222
2015-07-13 14:43:06 +02:00
Sebastien Deleuze 882fe129f3 Polish CORS support 2015-07-10 16:42:50 +02:00
Sebastien Deleuze cd9b3903a7 Introduce CorsFilter and CorsConfigurationMapping
This commit introduces the following changes:
 - The new CorsConfigurationMapping class allows to share the mapped
   CorsConfiguration logic between AbstractHandlerMapping and CorsFilter
 - In AbstractHandlerMapping, the Map<String, CorsConfiguration>
   corsConfiguration property has been renamed to corsConfigurations
 - CorsFilter allows to process CORS requests at filter level, using any
   CorsConfigurationSource implementation (for example
   CorsConfigurationMapping)

Issue: SPR-13192
2015-07-09 22:19:46 +02:00
Brian Clozel 8e566026e0 RedirectViews should always use RESPONSE_STATUS_ATTRIBUTE
By default, RedirectViews have http10Compatible set to true, which means
that they use HTTP 302 as a default HTTP response status. Setting this
property to false make RedirectViews use HTTP 303 by default.

Now when set to false, RedirectViews also don't use the
RESPONSE_STATUS_ATTRIBUTE request attribute as a response HTTP if it is
available.

This commit makes both configuration choices behave the same regarding
this request attribute: use it as a response status if it's available.

Issue: SPR-13208
2015-07-09 12:11:22 +02:00
Brian Clozel ef0eb01f93 Fix backwards compatibility in WebContentInterceptor
As of SPR-11792, WebContentGenerator and WebContentInterceptor offer
new APIs and new behavior regarding HTTP caching, including the use of a
new CacheControl class.

Those changes broke part of the behavior in WebContentInterceptor. This
class allows to override the global Cache configuration at the Generator
level, using specific mappings. Prior to this change, those mappings
would not properly apply the HTTP caching configuration when using
deprecated configuration settings in WebContentGenerator.

This change fixes those backwards compatibility issues for
WebContentInterceptor users.

Issue: SPR-13207
2015-07-08 01:08:16 +02:00
Sebastien Deleuze 8ee0e78980 Add Access-Control-Request-Method check for CORS preflight requests
Issue: SPR-13193
2015-07-07 09:34:39 +02:00
Sebastien Deleuze aea23e42c7 Polish 2015-07-07 09:26:06 +02:00
Rossen Stoyanchev 0d1b7fd14f Fix RequestPartServletServerHttpRequest encoding issue
When using Appache Commons FileUpload, multi parts with binary data
(i.e. that are not actual files) are saved and then accessed as
String request parameters.

Before this change however the RequestPartServletServerHttpRequest
used a fixed encoding (UTF-8) while the parsing code in
CommonsFileUploadSupport/Resolver used the encoding from the
content-type header, or the request, or the FileUpload component.

This change does a best effort to determine the encoding of the
request parameter using a similar algorithm as the parsing side
that should work the same unless the encoding comes from the
FileUpload component which is not accessible.

Issue: SPR-13096
2015-07-07 00:47:06 -04:00
Rossen Stoyanchev 3272a3b8ba Check HTTP method before raising 415
This commit moves the check whether an HTTP method supports request
body up to the base class so that all sub-classes can benefit (not just
@RequestBody).

Issue: SPR-13176
2015-06-30 15:24:01 -04:00
Brian Clozel 244c95b076 Fix @RequestBody argument processing for null Content-Type
Since the changes introduced in SPR-12778, some `@RequestBody` args
would not be properly processed in some cases:

* requests with an empty body
* no Content-Type header defined

This typically happens when GET requests are mapped on a handler dealing
with POST requests and HTTP bodies.

This change makes sure that the `RequestResponseBodyMethodProcessor` is
only involved for requests that:

* have a Content-Type defined
* OR are HTTP requests eligible for an HTTP body (PUT, POST, PATCH)

Issue: SPR-13176
Fixes spring-projects/spring-boot#3313
2015-06-30 19:13:34 +02:00
Juergen Hoeller dc1f921f5c Split between basic MethodParameter and SynthesizingMethodParameter
This split avoids a package tangle (between core and core.annotation) and also allows for selective use of raw annotation exposure versus synthesized annotations, with the latter primarily applicable to web and message handler processing at this point.

Issue: SPR-13153
2015-06-30 00:02:02 +02:00
Brian Clozel 39d689da0c Fix conditional requests support for HttpEntity
Prior to this commit, `HttpEntityMethodProcessor` would rely on
`ServletWebRequest` to process conditional requests and with incoming
`"If-Modified-Since"` / `"If-None-Match"` request headers.

This approach is problematic since in that class:

* response is wrapped in a `ServletServerHttpResponse`
* this wrapped response does not write response headers right away
* `ServletWebRequest.checkNotModified` methods can't apply their
logic with incomplete response headers

This solution adds some minimal code duplication and applies
the conditional request logic within the Processor.

A possible alternative would be to improve the
`ServletServerHttpResponse$ServletResponseHttpHeaders` implementation
with write methods - but this solution would only work for Servlet 3.x
applications.

Issue: SPR-13090
2015-06-29 16:47:27 +02:00
Sam Brannen 42424d6359 Document XML attributes in mvc:resource-chain in 4.1 XSD
Issue: SPR-12804
2015-06-29 16:21:32 +02:00
Sam Brannen c9b26d80e1 Polish resource chain documentation 2015-06-29 15:57:58 +02:00
Brian Clozel c61552b258 Document XML attributes in mvc:resource-chain
Issue: SPR-12804
2015-06-29 15:32:29 +02:00
Juergen Hoeller a2d3c27ed1 Allow MVC handler methods to return any CharSequence type as view name
Issue: SPR-13165
2015-06-26 22:17:53 +02:00
Brian Clozel ba48d6489f Mention Groovy Markup Templates in ref doc
Add a section on Groovy Markup Template support and
reorder sections in the View Technologies chapter, to have in order:

* Thymeleaf
* Groovy Markup Template
* Velocity and Freemarker
* JSPs
* Script Templates
* other views...

Issue: SPR-12829
2015-06-26 10:14:30 +02:00
Sebastien Deleuze 289f35da3a Call type aware canWrite() when using a GenericHttpMessageConverter
This commit introduces the following changes:
 - In AbstractMessageConverterMethodProcessor, the type aware variant of
   canWrite() is now called when the converter implements
   GenericHttpMessageConverter.
 - The Javadoc has been updated in GenericHttpMessageConverter to make it clear
   that the type aware canRead() and canWrite() methods should perform the same
   checks than non type aware ones.
  - AbstractGenericHttpMessageConverter now implements default type aware
    canRead() and canWrite() methods than just call the non type aware variants.
    Due to this, if subclasses just override the non type aware variants,
    they still have the right behavior.

Issue: SPR-13161
2015-06-25 15:02:33 +02:00
Sebastien Deleuze 31a5434ea4 Make @ResponseBody method return type available for message converters
This commit adds canWrite() and write() methods to the
GenericHttpMessageConverter interface. These are type aware variants
of the methods available in HttpMessageConverter, in order to keep
parametrized type information when serializing objects.

AbstractMessageConverterMethodProcessor now calls those type aware
methods when the message converter implements GenericHttpMessageConverter.

AbstractJackson2HttpMessageConverter and GsonHttpMessageConverter uses
these new methods to make @ResponseBody method return type available
for type resolution instead of just letting the JSON serializer trying
to guess the type to use from the object to serialize.

Issue: SPR-12811
2015-06-22 17:05:45 +02:00
Brian Clozel 9ada55dc6b Fix NPE in GzipResourceResolver
This change fixes a NullPointerException in GzipResourceResolver, which
assumed that calls to the `resolveResource` method were made with only
non-null values for request.

This is not the case for the VersionResourceResolver, which tries to
resolve resources that aren't requested per se by the HTTP request.

Issue: SPR-13149
2015-06-22 11:22:23 +02:00
Sam Brannen de9f27872e Polish CORS support classes
- Simplified "check" algorithms in CorsConfiguration

- Improved robustness of setter methods in CorsConfiguration in order to
  avoid attempts to modify immutable lists

- Improved CORS documentation and fixed typo

- Introduced constants in CorsConfiguration

- Removed auto-boxing in CorsRegistration
2015-06-20 16:12:18 +02:00
Sam Brannen 6c530b7bfb Delete trailing whitespace in XML files 2015-06-19 17:14:10 +02:00
Sam Brannen 078d252d1e Delete trailing whitespace in Java source code 2015-06-19 17:09:52 +02:00
Sebastien Deleuze 1e39a18819 Polish 2015-06-18 18:04:29 +02:00
Rossen Stoyanchev 0ef8af4798 Use .setStatus in ResponseStatusExceptionResolver
Before this change ResponseStatusExceptionResolver always used
.sendError despite the javadoc on @ResponseStatus#code. This was
perhaps justifiable from a HandlerExceptionResolver. Nevertheless
.setStatus should be more REST API friendly while still marking
the response as an error.

Issue: SPR-11193
2015-06-17 17:16:52 -04:00
Rossen Stoyanchev 8d7812b1b6 Raise IAE when no converter matches return type
Before this change the AbstractMessageConverterMethodProcessor always
raised a 406 if it couldn't find a converter. However if the reason
for not finding it is because there is simply no converter for the
return value type (i.e. programming error) and doesn't have anything to
do with content negotiation, then we should raise a 500 instead and
make it easier to figure out what's wrong.

Issue: SPR-13135
2015-06-17 17:03:36 -04:00
Brian Clozel a421bd2c27 Avoid duplicate Etag/Last-Modified header values
This commit improves SPR-13090 and avoids adding duplicate ETag and
Last-Modified headers in HTTP responses.
Previously, those were added twice to the response since:

* we're adding all ResponseEntity headers to the response
* the `checkNotModified` methods automatically add those headers

Issue: SPR-13090
2015-06-17 10:08:58 +02:00
Juergen Hoeller 92f1754b1e Fixed fallback mode in ObjenesisCglibAopProxy, plus consistent support for bypassing Objenesis (e.g. on Google App Engine)
This 4.2 commit revises SpringObjenesis towards a smart delegate, including support for a "spring.objenesis.ignore" system property.

Issue: SPR-13131
2015-06-16 22:01:37 +02:00
Rossen Stoyanchev 210e10c657 Add AsyncHandlerMethodReturnValueHandler
Before this change HandlerMethodReturnValueHandler's were invoked in a
specific order (type-based, annotation-based, custom). However handlers
that deal with asynchronous return value handling need to always be
considered first. This affects custom handlers in particular since they
are normally ordered last.

This change introduces an AsyncHandlerMethodReturnValueHandler
sub-interface with a single method to determine if the return value is
asynchronous and if it is to look for a matching handler only among
those that are of type AsyncHandlerMethodReturnValueHandler.

Issue: SPR-13083
2015-06-16 08:48:56 -04:00
Sebastien Deleuze 8187833502 Change default JSON prefix from "{} && " to ")]}', "
Issue: SPR-13078
2015-06-16 11:30:07 +02:00
Sebastien Deleuze a08c9f3137 Polish serialization/deserialization exception logging
This commit introduces the following changes in AbstractHandlerExceptionResolver:
 - warnLogger used to log exception is enabled by default
 - the exception message is now logged instead of the whole exception stacktrace
 - warn logging is only performed if doResolveException() returns a non-null
   ModelAndView, in order to avoid logging multiple times the error

Issue: SPR-13100
2015-06-16 10:27:52 +02:00
Juergen Hoeller b7d3a2a25b ResourceHttpRequestHandlerTests avoids millisecond-level comparisons 2015-06-16 00:18:22 +02:00
Rossen Stoyanchev 4b05bda0bf Missing path variable is now a 500 error
Before this change a missing path variable value resulted in a 400
error where in fact the error is due to a mismatch between the
declared @PathVariable and the URI template, i.e. a 500 error.

This change introduced a MissingPathVariableException as a sub-class
of ServletRequestBindingException (the exception previously thrown)
and results in a response status code of 500 by default.

Issue: SPR-13121
2015-06-15 16:09:19 -04:00
Stephane Nicoll 95acf8c989 Remove references to codehaus.org
Issue: SPR-13129
2015-06-15 15:44:29 +02:00
Sam Brannen 32c17bf540 Revise method and parameter names in annotation support
In AnnotatedElementUtils, all methods pertaining to merging annotation
attributes have been renamed to "getMerged*()" and "findMerged*()"
accordingly. Existing methods such as getAnnotationAttributes(..) have
been deprecated in favor of the more descriptive "merged" variants.
This aligns the naming conventions in AnnotatedElementUtils with those
already present in AnnotationReadingVisitorUtils.

The use of "annotationType" as a variable name for the fully qualified
class name of an annotation type has been replaced with
"annotationName" in order to improve the readability and intent of the
code base.

In MetaAnnotationUtils.AnnotationDescriptor, getMergedAnnotation() has
been renamed to synthesizeAnnotation(), and the method is now
overridden in UntypedAnnotationDescriptor to always throw an
UnsupportedOperationException in order to avoid potential run-time
ClassCastExceptions.

Issue: SPR-11511
2015-06-14 00:34:40 +02:00
Sam Brannen 2b339db53b Polish @CrossOrigin
- origin --> origins
- method --> methods
- constants are now actually constant (i.e., static final)
2015-06-13 17:09:58 +02:00
Brian Clozel 0175068cab Improve Last-Modified & ETag support
Prior to this change, the `"Last-Modified"` and "`Etag`" support had
been improved with SPR-11324: HTTP response headers are now
automatically added for conditional requests and more.

This commit fixes the format of the "`Last-Modified`" and "`ETag`"
values, which were using an epoch timestamp rather than an HTTP-date
format defined in RFC 7231 section 7.1.1.1.

Also, Conditional responses are only applied when the given response
applies, i.e. when it has an compatible HTTP status (2xx).

Issue: SPR-13090
2015-06-11 14:46:14 +02:00
Rossen Stoyanchev 9712a32c46 Allow setting timeout in ResponseBodyEmitter
Issue: SPR-13104
2015-06-10 14:47:24 -04:00
Sebastien Deleuze 0c3b34f7d5 Polish CORS global configuration
This commit introduces the following changes:
 - configureCors(CorsConfigurer configurer) is renamed to
   addCorsMappings(CorsRegistry registry)
 - enableCors(String... pathPatterns) is renamed to
   addMapping(String pathPattern)
 - <cors /> element must have at least one <mapping /> child
   element in order to be consistent with XML based configuration
   and have more explicit configuration

Issues: SPR-12933, SPR-13046
2015-06-05 16:55:15 +02:00
Sebastien Deleuze 15da5efc86 Fix combining class and method level @CrossOrigin attributes
Issue: SPR-13097
2015-06-05 15:32:58 +02:00
Sebastien Deleuze e5f76af193 Support CORS global configuration in XML namespace
This commit introduces support for this kind of CORS XML namespace configuration:

	<mvc:cors>

		<mvc:mapping path="/api/**"
					allowed-origins="http://domain1.com, http://domain2.com"
					allowed-methods="GET, PUT"
					allowed-headers="header1, header2, header3"
					exposed-headers="header1, header2" allow-credentials="false"
					max-age="123" />

		<mvc:mapping path="/resources/**" allowed-origins="http://domain1.com" />

	</mvc:cors>

Issue: SPR-13046
2015-06-02 19:14:12 +02:00
Jasper de Vries ec4783400c SPR-13080 SseEventBuilder needs event rather than name 2015-06-01 10:02:28 -04:00
Rossen Stoyanchev 3e74476c11 Polish 2015-06-01 09:48:06 -04:00
Sam Brannen 1a56b47502 Introduce alias for 'value' attribute in @MatrixVariable
Issue: SPR-11393
2015-05-31 18:50:35 +02:00
Sam Brannen 60eb9e9ca2 Introduce 'value' alias for 'origin' in @CrossOrigin
Issue: SPR-11393
2015-05-31 18:34:01 +02:00
Sam Brannen f0c0813011 Change semantics of @CrossOrigin's maxAge regarding negative values 2015-05-31 18:20:52 +02:00
Sam Brannen 72b44af862 Introduce test for invalid @CrossOrigin.allowCredentials() 2015-05-31 18:17:52 +02:00
Sam Brannen 9ce7485237 Introduce alias for 'value' attribute in @SessionAttributes
Issue: SPR-11393
2015-05-31 17:21:03 +02:00
Sam Brannen 6a5b2672e7 Introduce alias for 'value' attribute in @ResponseStatus
Issue: SPR-11393
2015-05-31 17:00:23 +02:00
Sam Brannen c55486d5d5 Introduce alias for 'value' attribute in @RequestPart
Issue: SPR-11393
2015-05-31 16:32:45 +02:00
Sam Brannen c4c3ce796a Introduce alias for 'value' attribute in @CookieValue
Issue: SPR-11393
2015-05-31 16:07:27 +02:00
Sam Brannen 7018747cec Remove trailing whitespace in Java source code 2015-05-29 02:03:44 +02:00
Sam Brannen e30c9b2ef3 Synthesize annotation from a map of attributes
Spring Framework 4.2 RC1 introduced support for synthesizing an
annotation from an existing annotation in order to provide additional
functionality above and beyond that provided by Java. Specifically,
such synthesized annotations provide support for @AliasFor semantics.
As luck would have it, the same principle can be used to synthesize an
annotation from any map of attributes, and in particular, from an
instance of AnnotationAttributes.

The following highlight the major changes in this commit toward
achieving this goal.

- Introduced AnnotationAttributeExtractor abstraction and refactored
  SynthesizedAnnotationInvocationHandler to delegate to an
  AnnotationAttributeExtractor.

- Extracted code from SynthesizedAnnotationInvocationHandler into new
  AbstractAliasAwareAnnotationAttributeExtractor and
  DefaultAnnotationAttributeExtractor implementation classes.

- Introduced MapAnnotationAttributeExtractor for synthesizing an
  annotation that is backed by a map or AnnotationAttributes instance.

- Introduced a variant of synthesizeAnnotation() in AnnotationUtils
  that accepts a map.

- Introduced findAnnotation(*) methods in AnnotatedElementUtils that
  synthesize merged AnnotationAttributes back into an annotation of the
  target type.

The following classes have been refactored to use the new support for
synthesizing AnnotationAttributes back into an annotation.

- ApplicationListenerMethodAdapter
- TestAnnotationUtils
- AbstractTestContextBootstrapper
- ActiveProfilesUtils
- ContextLoaderUtils
- DefaultActiveProfilesResolver
- DirtiesContextTestExecutionListener
- TestPropertySourceAttributes
- TestPropertySourceUtils
- TransactionalTestExecutionListener
- MetaAnnotationUtils
- MvcUriComponentsBuilder
- RequestMappingHandlerMapping

In addition, this commit also includes changes to ensure that arrays
returned by synthesized annotations are properly cloned first.

Issue: SPR-13067
2015-05-29 01:38:51 +02:00
Brian Clozel 9e6494eef6 Reinstate WebContentGenerator.checkAndPrepare variant
Reinstate a variant of the `WebContentGenerator.checkAndPrepare` method
for projects that are using it.

This variant is now marked as deprecated.

Issue: SPR-11792
2015-05-22 22:31:56 +02:00
Brian Clozel 4d5fca596d Fix directories I/O in ResourceHttpRequestHandler
Prior to this commit, the `ResourceHttpRequestHandler` would not
properly handle HTTP requests to **directories contained in JARs**.
This would result in HTTP 500 errors, caused by `FileNotFoundException`
or `NullPointerException`.

This can be tracked to webapp ClassLoader implementations in servlet
containers:
* in Jetty9x, fetching a directory within a JAR as a `Resource` and
getting its InputStream work fine, but attempting to `close()` it
results in a NullPointerException as the underlying stream is null.
* In Tomcat6x, one cannot fetch an InputStream for the same `Resource`
as it throws a FileNotFoundException.

This change adds more try/catch clauses and catches more Exception so as
to result in HTTP 200 OK responses instead of server errors. While this
is inconsistent because the same code path would result in HTTP 404 with
existing directories on the file system, there's no other simple way to
make those checks for resources contained in JARs.

Issue: SPR-12999
2015-05-21 14:30:12 +02:00
Rossen Stoyanchev ad4c8795ae Include only path in <spring:mvcUrl>
Issue: SPR-13045
2015-05-20 17:06:47 -04:00
Juergen Hoeller b4095c3e1d Class identity comparisons wherever possible
Issue: SPR-12926
2015-05-20 14:34:16 +02:00
Brian Clozel 57e0c789a8 Polish
Issue: SPR-12323
2015-05-19 23:57:30 +02:00
Brian Clozel c5d6cc4134 Polish
Issue: SPR-12673
2015-05-19 21:40:52 +02:00
Brian Clozel 9e5a33c1b3 Add a ResourceResolver implementation for WebJars
Prior to this commit, WebJars users needed to use versioned links within
templates for WebJars resources, such as `/jquery/1.2.0/jquery.js`.
This can be rather cumbersome when updating libraries - all references
in templates need to be updated.

One could use version-less links in templates, but needed to add a
specific MVC Handler that uses webjars.org's webjar-locator library.
While this approach makes maintaing templates easier, this makes HTTP
caching strategies less optimal.

This commit adds a new WebJarsResourceResolver that search for resources
located in WebJar locations. This ResourceResolver is automatically
registered if the "org.webjars:webjars-locator" dependency is present.

Registering WebJars resource handling can be done like this:

```java
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
  registry.addResourceHandler("/webjars/**")
          .addResourceLocations("classpath:META-INF/resources/webjars")
          .resourceChain(true)
              .addResolver(new WebJarsResourceResolver());
}
```

Issue: SPR-12323

polish
2015-05-19 18:01:08 +02:00
Brian Clozel c36435c042 Execute HandlerInterceptors in registration order
Prior to this commit, registering `HandlerInterceptor`s using the
`InterceptorRegistry` would not guarantee their order of execution. In
fact, `HandlerInterceptor`s would always be executed before
`MappedInterceptor`s.

This change makes `MappedInterceptor` implement the `HandlerInterceptor`
interface, in order to register all interceptors in a single ordered
list. The order of execution of interceptors is now guaranteed in the
`HandlerExecutionChain` built by `AbstractHandlerMapping`.

Issue: SPR-12673
2015-05-19 12:48:40 +02:00
Stephane Nicoll cf391f5ce1 polish
Remove unused imports
2015-05-19 08:49:01 +02:00
Rossen Stoyanchev 90d54285d2 Add httpMethods property to LocalChangeInterceptor
Issue: SPR-13032
2015-05-18 15:18:28 -04:00
Rossen Stoyanchev 85cf4e6999 All MVC building methods accept controller type
Issue: SPR-13033
2015-05-18 14:54:41 -04:00
james e41877d64e SPR-13033: Use @RequestMapping of correct class
MvcUriComponentsBuilder::fromMethodCall creates wrong URLs with derived
controller classes. The @RequestMapping of the declaring class of the
method that is called is used instead of the @RequstMapping of the
given controller class.

https://jira.spring.io/browse/SPR-13033
2015-05-18 14:12:31 -04:00
Rossen Stoyanchev 5e8d838334 CORS-related refinements
After this change CorsProcessor has a single processRequest method and
it also explicitly deals with a null CorsConfiguration, which for
pre-flight requests results in a rejection while for simple requests
results in no CORS headers added.

The AbstractHandlerMapping now uses a LinkedHashMap to preserve the
order in which global patterns are provided.
2015-05-18 12:20:54 -04:00
Sebastien Deleuze decb55ce14 Rename CrossOriginConfigurer/Registration to CorsConfigurer/Registration
Issue: SPR-12933
2015-05-18 10:57:14 +02:00
Sebastien Deleuze 49fff7513d Add global CORS configuration capabilities
This commit adds JavaConfig based global CORS configuration
capabilities to Spring MVC. It is now possible to specify
multiple CORS configurations, each mapped on a path pattern,
by overriding
WebMvcConfigurerAdapter#configureCrossOrigin(CrossOriginConfigurer).

It is also possible to combine global and @CrossOrigin based
CORS configuration.

Issue: SPR-12933
2015-05-16 00:52:51 +02:00
Rossen Stoyanchev e843bcc725 Do not log headers in exception message
Issue: SPR-12984
2015-05-14 06:19:47 -04:00
Juergen Hoeller 0711d6d0df Polishing 2015-05-13 15:04:26 +02:00
Brian Clozel 71c3e4e4ee Fix empty URLs handling in ResourceUrlEncodingFilter
Prior to this commit, the ResourceUrlEncodingFilter would fail with a
StringIndexOutOfBoundsException when:

* the current request has a servlet context
* the URL to encode is relative and is shorter than the context value

This change defensively checks for those lengths and delegates to the
parent implementation if necessary.

Issue: SPR-13018
2015-05-13 14:30:09 +02:00
Juergen Hoeller 00147379f9 Polishing
(cherry picked from commit 9e925aa)
2015-05-11 22:22:23 +02:00
Arjen Poutsma 76beb36e4b Remove duplicate separators when combining paths
Prior to this commit, AntPathMatcher would not correctly combine a path
that ends with a separator with a path that starts with a separator.
For example, `/foo/` + `/bar` combined into `/foo//bar`.

Specifically, this commit:

 - Removes the duplicated separator in combined paths

 - Improves RequestMappingInfo's toString() representation

 - Fixes Javadoc formatting in AntPathMatcher

 - Polishes AntPathMatcherTests

 - Polishes Javadoc in AbstractRequestCondition

Issue: SPR-12975
2015-05-08 13:49:34 +02:00