Commit Graph

795 Commits

Author SHA1 Message Date
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
Juergen Hoeller dbd82d128d Polishing 2015-05-07 20:18:17 +02:00
Brian Clozel 8b545f47bd Fix remote context handling in UrlTag
Prior to this change, the `UrlTag` would simply append the remote
context and the path value in case of a context relative URL.

The following code snippet would output "//foo":

```
<spring:url value="/foo" context="/" />
```

This change now removes trailing slashes in remote context to avoid
this.

Issue: SPR-12782
2015-05-06 14:54:18 +02:00
Sam Brannen ba84458c65 Overhaul AnnotatedElementUtils
- Methods which search for a specific annotation now properly ensure
   that the sought annotation was actually found.

 - Both the "get" and the "find" search algorithms no longer needlessly
   traverse meta-annotation hierarchies twice.

 - Both the "get" and the "find" search algorithms now properly
   increment the metaDepth when recursively searching within the
   meta-annotation hierarchy.

 - Redesigned getMetaAnnotationTypes() so that it doesn't needlessly
   search irrelevant annotations.

 - Documented and tested hasMetaAnnotationTypes().

 - Documented isAnnotated().

Issue: SPR-11514
2015-05-05 23:35:00 +02:00
Rossen Stoyanchev 8853107f76 Find CORS config by HandlerMethod
Before this change AbstractHandlerMethodMapping used a map from Method
to CorsConfiguration. That works for regular @RequestMapping methods.
However frameworks like Spring Boot and Spring Integration may
programmatically register the same Method under multiple mappings,
i.e. adapter/gateway type classes.

This change ensures that CorsConfiguraiton is indexed by HandlerMethod
so that we can store CorsConfiguration for different handler instances
even when the method is the same.

In order for to make this work, HandlerMethod now provides an
additional field called resolvedFromHandlerMethod that returns the
original HandlerMethod (with the String bean name). This makes it
possible to  perform reliable lookups.

Issue: SPR-11541
2015-05-05 12:56:07 -04:00
Rossen Stoyanchev 4a8baebf59 Improve MappingRegistry tests and polish
Issue: SPR-11541
2015-05-05 12:56:06 -04:00
Sam Brannen 16b189cc1a Add failing test for concrete @RequestMapping method in abstract superclass
This commit introduces failing (but currently disabled) test cases in
HandlerMethodAnnotationDetectionTests that attempt to reproduce the
scenario described in SPR-9517.

See: ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass

Furthermore, this commit also introduces passing tests cases for a
similar scenario. See: ParameterizedSubclassOverridesDefaultMappings

Issue: SPR-9517
2015-05-05 17:31:30 +02:00
Sam Brannen 5dd70a8e46 Simplify HandlerMethodAnnotationDetectionTests config 2015-05-05 17:31:30 +02:00
Brian Clozel 77937c5b02 Polish JRubyScriptTemplateTests (case sensitive issue) 2015-05-05 13:56:54 +02:00
Sam Brannen 3fb2645744 Polish HandlerMethodAnnotationDetectionTests 2015-05-05 13:19:09 +02:00
Sebastien Deleuze 7919364db6 Polish script based view tests
Issue: SPR-12266
2015-05-05 11:38:47 +02:00
Rossen Stoyanchev e306098155 Encapsulate CORS checking within CorsConfiguration
CorsConfiguration now provides methods to check and determine the
allowed origin, method, and headers according to its own configuration.

This simplifies significantly the work that needs to be done from
DefaultCorsProcessor. However an alternative CorsProcessor can still
access the raw CorsConfiguration and perform its own checks.

Issue: SPR-12885
2015-05-05 09:31:41 +02:00
Sebastien Deleuze 83f269b512 Make DefaultCorsProcessor Servlet 2.5 compliant
This commit adds CORS related headers to HttpHeaders
and update DefaultCorsProcessor implementation to
use ServerHttpRequest and ServerHttpResponse instead
of HttpServletRequest and HttpServletResponse. Usage
of ServerHttpResponse allows to avoid using Servlet 3.0
specific methods in order keep CORS support Servlet 2.5
compliant.

Issue: SPR-12885
2015-05-05 09:31:41 +02:00
Rossen Stoyanchev 71683c5f8d Fix regressions from 8f558e7
The change to provide public register/unregister methods in
AbstractHandlerMethodMapping assumed that a single method cannot be
mapped more than once. This is not the case with the MvcEndpoints and
EndpointHandlerMapping from Spring Boot which wrap one or more
non-web Endpoint types with an MvcEndpointAdapter in order to expose
them for use over the web. In effect Spring MVC sees a single handler
method mapped many times.

This change removes that assumption so rather than unregistering with
a HandlerMethod, which is not necessarily unique, the unregister method
now takes the actual mapping, which is the only thing that should actually
be unique.

Issue: SPR-11541
2015-05-04 17:24:49 -04:00
Rossen Stoyanchev 205e5dfd6f Support bridged methods in MvcUriComponentsBuilder
Issue: SPR-12977
2015-05-04 10:26:46 -04:00
Rossen Stoyanchev 9637b12f89 Fix typo
Issue: SPR-12962
2015-05-04 09:52:27 -04:00
Sam Brannen e9c4db34ec Improve ex. msg for duplicate methods in MvcUriComponentsBuilder
This commit adds additional context to the exception message generated
when two candidate methods are discovered in MvcUriComponentsBuilder's
getMethod(Class<?>, String, Object...).

Issue: SPR-12977
2015-05-04 13:43:26 +02:00
Sam Brannen 859751b9d9 Add test for bridge method support in MvcUriComponentsBuilder
This commit introduces a new fromMethodNameWithBridgedMethod() test in
MvcUriComponentsBuilderTests which is currently disabled via @Ignore
until this bug is resolved.

Issue: SPR-12977
2015-05-04 13:43:25 +02:00
Brian Clozel bb3f26483b Fix CachingResourceResolver key generation
When used in combination with GzipResourceResolver, the
CachingResourceResolver does not properly cache results, since it only
takes the request path as a input for cache key generation.

Here's an example of that behavior:

1. an HTTP client requests a resource with `Accept-Encoding: gzip`, so
the GzipResourceResolver can resolve a gzipped resource.
2. the configured CachingResourceResolver caches that resource.
3. another HTTP client requests the same resource, but it does not
support gzip encoding; the previously cached gzipped resource is still
returned.

This commit uses the presence/absence of gzip encoding support as an
input in cache keys generation.

Issue: SPR-12982
2015-05-04 13:33:22 +02:00
Rossen Stoyanchev 3abcea1296 Add RequestMappingInfoBuilder
Issue: SPR-11541
2015-05-04 06:08:26 -04:00
Rossen Stoyanchev 8f558e7c73 Add methods to (un)register HandlerMethod mappings
Issue: SPR-11541
2015-05-04 06:08:26 -04:00
Rossen Stoyanchev 6a28c86d18 Refactor AbstractHandlerMethodMapping
Before this change AbstractHandlerMethodMapping contained multiple
maps all containing different kinds of mapping meta-data. After the
change a MappingDefinitionRegistry inner class encapsulates these
fields along with their initialization code.

Issue: SPR-11541
2015-05-04 06:08:25 -04:00
Rossen Stoyanchev ff7d4eebd8 Polish AbstractHandlerMethodMapping
Issue: SPR-11541
2015-05-04 06:08:25 -04:00
Rossen Stoyanchev 49e90575e9 Disable ShallowEtagHeaderFilter for HTTP streaming
Issue: SPR-12960
2015-05-04 06:08:25 -04:00
Rossen Stoyanchev 86fd0afbf2 Switch to AnnotatedElementUtils.findXxx for @MVC
Issue: SPR-12296
2015-04-24 11:23:00 -04:00
Rossen Stoyanchev 8376e1eca1 Support @RequestMapping as meta-annotation
Issue: SPR-12296
2015-04-24 10:33:44 -04:00
Rossen Stoyanchev 0ddcbce90a MvcUriCB no longer extends UriCB
Before 4.2 the MvcUriComponentsBuilder exposed only static factory
methods and therefore there should be no reason for it to extend
UriComponentsBuilder (design oversight). It's also highly unlikely
for application code to treat MvcUriCB as UriCB since there is no
need and no way to obtain an instance (constructor is protected).

This change removes the base class declaration from MvcUriCB.

Issue: SPR-12617
2015-04-23 11:16:20 -04:00
Rossen Stoyanchev cbabb00ba2 Polish 2015-04-23 11:12:24 -04:00
Rossen Stoyanchev 1cd0f433e0 Allow MvcUriComponentsBuilder instance with baseUrl
Before this change MvcUriComponentsBuilder exposed only static factory
methods for creating links where the links are relative to the current
request or a baseUrl explicitly provided as an argument.

This change allows creating an MvcUriComponents builder instance with
a built-in baseUrl. The instance can then be used with non-static
withXxx(...) method alternatives to the static fromXxx(...) methods.

Issue: SPR-12617
2015-04-23 11:03:37 -04:00
Sebastien Deleuze a3159dfbf2 Add script based templating support
This commit adds support for script based templating. Any templating
library running on top of a JSR-223 ScriptEngine that implements
Invocable like Nashorn or JRuby could be used.

For example, in order to render Mustache templates thanks to the Nashorn
Javascript engine provided with Java 8+, you should declare the following
configuration:

@Configuration
@EnableWebMvc
public class MustacheConfig extends WebMvcConfigurerAdapter {

	@Override
	public void configureViewResolvers(ViewResolverRegistry registry) {
		registry.scriptTemplate();
	}

	@Bean
	public ScriptTemplateConfigurer configurer() {
		ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
		configurer.setEngineName("nashorn");
		configurer.setScripts("mustache.js");
		configurer.setRenderObject("Mustache");
		configurer.setRenderFunction("render");
		return configurer;
	}
}

The XML counterpart is:

<beans>
	<mvc:annotation-driven />

	<mvc:view-resolvers>
		<mvc:script-template />
	</mvc:view-resolvers>

	<mvc:script-template-configurer engine-name="nashorn" render-object="Mustache" render-function="render">
		<mvc:script location="mustache.js" />
	</mvc:script-template-configurer>
</beans>

Tested with:
 - Handlebars running on Nashorn
 - Mustache running on Nashorn
 - React running on Nashorn
 - EJS running on Nashorn
 - ERB running on JRuby
 - String templates running on Jython

Issue: SPR-12266
2015-04-22 08:47:04 +02:00
Sebastien Deleuze 713fc5c4ab Add onTimeout() and onCompletion() callbacks to ResponseBodyEmitter
Issue: SPR-12939
2015-04-21 19:34:01 +02:00
Sebastien Deleuze 5b0a0f4db5 Support CompletableFuture as alternative to DeferredResult in MVC
Issue: SPR-12597
2015-04-20 14:19:31 +02:00
Sebastien Deleuze 9a65eec36f Avoid registering CorsConfiguration for methods without @CrossOrigin
Issue: SPR-12931
2015-04-20 09:04:38 +02:00
Sam Brannen d31f3ee0b2 Suppress warning in ServletAnnotationControllerHandlerMethodTests 2015-04-17 02:11:12 +02:00
Rossen Stoyanchev e4acbae270 Polish 2015-04-13 18:16:38 -04:00
Rossen Stoyanchev 26cfe5795f Find @ResponseStatus recursively on getCause()
Issue: SPR-12903
2015-04-13 18:10:55 -04:00
Rossen Stoyanchev c172d9d745 Add trailing slash support to AbstractUrlHandlerMapping
Issue: SPR-12818
2015-04-13 15:33:25 -04:00
Rossen Stoyanchev 8ff7cc73bc Try defaulContentType for application/octet-stream
AbstractHttpMessageConverter now tries to call getDefaultContentType
with the actual value to be converted to see if that will result in
a more concrete mediat type than application/octet-stream.

Issue: SPR-12894
2015-04-13 14:31:25 -04:00
Rossen Stoyanchev b6449baaa6 List all unsatisfied request param groups
Issue: SPR-12854
2015-04-06 23:33:56 -04:00
Rossen Stoyanchev 13403d51e5 Improve error message for missing request body
Issue: SPR-12888
2015-04-06 17:24:49 -04:00
Sebastien Deleuze b0e1e66b7f Add CORS support
This commit introduces support for CORS in Spring Framework.

Cross-origin resource sharing (CORS) is a mechanism that allows
many resources (e.g. fonts, JavaScript, etc.) on a web page to
be requested from another domain outside the domain from which
the resource originated. It is defined by the CORS W3C
recommandation (http://www.w3.org/TR/cors/).

A new annotation @CrossOrigin allows to enable CORS support
on Controller type or method level. By default all origins
("*") are allowed.

@RestController
public class SampleController {

	@CrossOrigin
	@RequestMapping("/foo")
	public String foo() {
		// ...
	}
}

Various @CrossOrigin attributes allow to customize the CORS configuration.

@RestController
public class SampleController {

	@CrossOrigin(origin = { "http://site1.com", "http://site2.com" },
				 allowedHeaders = { "header1", "header2" },
				 exposedHeaders = { "header1", "header2" },
				 method = RequestMethod.DELETE,
				 maxAge = 123, allowCredentials = "true")
	@RequestMapping(value = "/foo", method = { RequestMethod.GET, RequestMethod.POST} )
	public String foo() {
		// ...
	}
}

A CorsConfigurationSource interface can be implemented by HTTP request
handlers that want to support CORS by providing a CorsConfiguration
that will be detected at AbstractHandlerMapping level. See for
example ResourceHttpRequestHandler that implements this interface.

Global CORS configuration should be supported through ControllerAdvice
(with type level @CrossOrigin annotated class or class implementing
CorsConfigurationSource), or with XML namespace and JavaConfig
configuration, but this is not implemented yet.

Issue: SPR-9278
2015-04-02 16:12:11 +02:00
Sebastien Deleuze 35f40ae654 Add @JsonView deserialization support for request bodies
Jackson 2.5.0 or later is required.

Issue: SPR-12501
2015-04-02 12:05:45 +02:00
Sebastien Deleuze ca06582f2a Support Jackson @JsonFilter
This commit adds a filters property to MappingJacksonValue
and also manages a special FilterProvider class name model key in
order to be able to specify a customized FilterProvider for each
handler method execution, and thus provides a more dynamic
alternative to our existing JsonView support.

A filters property is also now available in Jackson2ObjectMapperBuilder
and Jackson2ObjectMapperFactoryBean in order to set easily a
global FilterProvider.

More details about @JsonFilter at
http://wiki.fasterxml.com/JacksonFeatureJsonFilter.

Issue: SPR-12586
2015-04-02 11:23:18 +02:00
izeye 593aff99b0 Fix typo. 2015-04-02 14:58:47 +09:00
Rossen Stoyanchev 7e799295e5 Fix compile error 2015-04-01 16:53:27 -04:00
Rossen Stoyanchev b5b0fd5e5e Add RequestBodyAdviceAdapter
Issue: SPR-12501
2015-04-01 16:27:16 -04:00
Juergen Hoeller f926f6cb3e Polishing 2015-03-31 17:32:39 +02:00
Juergen Hoeller 39bc8b7992 AbstractContextLoaderInitializer and AbstractDispatcherServletInitializer support ApplicationContextInitializers now
Issue: SPR-12430
2015-03-31 17:21:57 +02:00
Sam Brannen 72ec5792cf Polish Javadoc for abstract XLSX views 2015-03-31 01:16:23 +02:00
Rossen Stoyanchev 36ed4df59d Improve empty request body handling
The check for an empty request body InputStream is now in the base
class AbstractMessageConverterMethodArgumentResolver shared for
all arguments that involve reading with an HttpMessageConverter --
@RequestBody, @RequestPart, and HttpEntity.

When an empty body is detected any configured RequestBodyAdvice is
given a chance to select a default value or leave it as null.

Issue: SPR-12778, SPR-12860, SPR-12861
2015-03-29 21:42:22 -04:00
Rossen Stoyanchev 0556ed4f16 Add RequestBodyAdvice
RequestBodyAdvice is analogous to ResponseBodyAdvice (added in 4.1)
but for intercepting for reading the request with an
HttpMessageConverter for resolving an @RequestBody or an HttpEntity
method argument.

Issue: SPR-12501
2015-03-29 21:42:14 -04:00
Juergen Hoeller beae336627 Polishing 2015-03-25 15:22:41 +01:00
Juergen Hoeller d23893fd25 Consistent javadoc param declarations for type variables 2015-03-25 00:44:01 +01:00
Juergen Hoeller 935ffc5827 Fine-tuned concurrency and general polishing in SSE support classes
Issue: SPR-12212
2015-03-25 00:39:26 +01:00
Juergen Hoeller c8cc8b7cbd Removed outdated references to Servlet 2.3/2.4
(cherry picked from commit 673dac5)
2015-03-24 21:24:12 +01:00
Rossen Stoyanchev 95f6e4cc9b Support StreamingResponseBody return value type
Issue: SPR-12831
2015-03-23 15:38:52 -04:00
Juergen Hoeller 76cf5beb59 Support for XSSFWorkbook and SXSSFWorkbook (xmlx format; POI 3.9+)
Introduces an AbstractXlsView and dedicated subclasses for POI's xmlx support.
Deprecates the traditional AbstractExcelView which is based on pre POI 3.5 API.

Issue: SPR-6898
2015-03-23 20:01:05 +01:00
Juergen Hoeller e2110e353e Support for JasperReports xlsx exporter
Issue: SPR-12843
2015-03-23 19:59:25 +01:00
Brian Clozel f9ce11eef8 Provide controller level Cache-Control support
Prior to this commit, Cache-Control HTTP headers could be set using
a WebContentInterceptor and configured cache mappings.

This commit adds support for cache-related HTTP headers at the controller
method level, by returning a ResponseEntity instance:

ResponseEntity.status(HttpStatus.OK)
    .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic())
    .eTag("deadb33f8badf00d")
    .body(entity);

Also, this change now automatically checks the "ETag" and
"Last-Modified" headers in ResponseEntity, in order to respond HTTP
"304 - Not Modified" if necessary.

Issue: SPR-8550
2015-03-23 18:05:14 +01:00
Brian Clozel 38f32e3816 Improve HTTP caching flexiblity
This commit improves HTTP caching defaults and flexibility in
Spring MVC.

1) Better default caching headers

The `WebContentGenerator` abstract class has been updated with
better HTTP defaults for HTTP caching, in line with current
browsers and proxies implementation (wide support of HTTP1.1, etc);
depending on the `setCacheSeconds` value:

* sends "Cache-Control: max-age=xxx" for caching responses and
do not send a "must-revalidate" value by default.
* sends "Cache-Control: no-store" or "Cache-Control: no-cache"
in order to prevent caching

Other methods used to set specific header such as
`setUseExpiresHeader` or `setAlwaysMustRevalidate` are now deprecated
in favor of `setCacheControl` for better flexibility.
Using one of the deprecated methods re-enables previous HTTP caching
behavior.

This change is applied in many Handlers, since
`WebContentGenerator` is extended by `AbstractController`,
`WebContentInterceptor`, `ResourceHttpRequestHandler` and others.

2) New CacheControl builder class

This new class brings more flexibility and allows developers
to set custom HTTP caching headers.

Several strategies are provided:

* `CacheControl.maxAge(int)` for caching responses with a
"Cache-Control: max-age=xxx" header
* `CacheControl.noStore()` prevents responses from being cached
with a "Cache-Control: no-store" header
* `CacheControl.noCache()` forces caches to revalidate the cached
response before reusing it, with a "Cache-Control: no-store" header.

From that point, it is possible to chain method calls to craft a
custom CacheControl instance:

```
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS)
    .cachePublic().noTransform();
```

3) Configuring HTTP caching in Resource Handlers

On top of the existing ways of configuring caching mechanisms,
it is now possible to use a custom `CacheControl` to serve
resources:

```
@Configuration
public class MyWebConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS);
    registry.addResourceHandler("/resources/**)
            .addResourceLocations("classpath:/resources/")
            .setCacheControl(cc);
  }
}
```

or

```
<mvc:resources mapping="/resources/**" location="classpath:/resources/">
  <mvc:cachecontrol max-age="3600" cache-public="true"/>
</mvc:resources>
```

Issue: SPR-2779, SPR-6834, SPR-7129, SPR-9543, SPR-10464
2015-03-23 18:01:04 +01:00
Rossen Stoyanchev 18039785ae Update Javadoc of AsyncHandlerInterceptor
Issue: SPR-12608, SPR-12720
2015-03-20 16:58:01 -04:00
Rossen Stoyanchev 6a96c26dd4 Add HttpRange tests, set Accept-Range header, polish
Issue: SPR-10805
2015-03-20 15:35:43 -04:00
Arjen Poutsma da48739628 Support byte ranges in ResourceHttpRequestHandler
This commit introduces support for HTTP byte ranges in the
ResourceHttpRequestHandler. This support consists of a number of
changes:

- Parsing of HTTP Range headers in HttpHeaders, using a new HttpRange
  class and inner ByteRange/SuffixByteRange subclasses.
- MIME boundary generation moved from FormHttpMessageConverter to
  MimeTypeUtils.
- writePartialContent() method introduced in ResourceHttpRequestHandler,
  handling the byte range logic
- Additional partial content tests added to
  ResourceHttpRequestHandlerTests.

Issue: SPR-10805
2015-03-20 15:35:43 -04:00
Juergen Hoeller 898c24fcdd Optimized access to resolved bean type (avoiding BeanFactory locks)
Revised HandlerMethod.getBeanType() impl for both web and messaging.
In addition, HandlerMethods get created with the internal BeanFactory now.

Issue: SPR-12832
2015-03-20 17:35:44 +01:00
Rossen Stoyanchev 83ff0adc2e Add accessors for expirationTime in FlashMap
FlashMap now has a single field reflecting the expiration time and
also provides accessors that can be used for serialization purposes.

Issue: SPR-12757
2015-03-19 17:25:44 -04:00
Rossen Stoyanchev de9c9febc3 Compare encoded params in AbstractFlashMapManager
AbstractFlashMapManager no longer decodes the target query parameters
it needs to use to match to the request after the redirect.

Instead it stores query parameters as-is adn then relies on parsing the
encoded query string after the redirect.

Issue: SPR-12569
2015-03-19 16:57:26 -04:00
Rossen Stoyanchev 46537a76ed Polish FlashMapManagerTests 2015-03-19 15:04:13 -04:00
Rossen Stoyanchev febcd0c46d Add baseUrl overloaded MvcUriComponentsBuilder methods
Issue: SPR-12800
2015-03-16 20:45:01 -04:00
Juergen Hoeller 6c169bd644 Initial support for JSR-354 Money & Currency
Issue: SPR-12209
2015-03-13 19:40:00 +01:00
Juergen Hoeller bc6a98c144 Polishing (in particular updating javadoc references to Apache Commons) 2015-03-13 18:19:10 +01:00
Juergen Hoeller 13659d645b Consistent support for @Order annotation as alternative to Ordered interface
Issue: SPR-12806
2015-03-13 18:18:33 +01:00
Rossen Stoyanchev 624790a520 Move X-Forwarded-* tests to UriComponentsBuilderTests 2015-03-13 09:33:21 -04:00
Sam Brannen d90cee78ef Remove trailing whitespace in source code 2015-03-07 21:16:18 +01:00
Kazuki Shimizu c746b10da9 Support @NumberFormat as a meta-annotation
This commit ensures that @NumberFormat can be used as a
meta-annotation, as was already the case for @DateTimeFormat.

In addition, this commit polishes FormattingConversionServiceTests and
MvcNamespaceTests.

Issue: SPR-12743
2015-03-07 21:00:25 +01:00
Juergen Hoeller a71001b45c Polishing
Issue: SPR-12778
2015-03-06 17:46:35 +01:00
Brian Clozel 450072e38a Add spring-mvc spring-beans XSD schemas for 4.2 2015-03-06 17:02:11 +01:00
Rossen Stoyanchev d64c48ff5f UriComponentsBuilder.fromHttpRequest sets port correctly
Issue: SPR-12771
2015-03-05 21:52:27 -05:00
Juergen Hoeller fdd1f83639 Polishing
(cherry picked from commit 3783591)
2015-03-02 22:05:16 +01:00
Stephane Nicoll babbf6e871 Harmonize resources location
Issue: SPR-12766
2015-02-28 10:32:40 +01:00
Juergen Hoeller 540d8792fe Fixed javadoc warnings and revised FastByteArrayOutputStream code style 2015-02-27 23:49:55 +01:00
Juergen Hoeller 287045ef74 Allow for shared Objenesis caching in ObjenesisCglibAopProxy
Issue: SPR-12755
2015-02-26 18:34:52 +01:00
Brian Clozel cbe4a49b54 Polish file locations in resource handling
Issue: SPR-12747
2015-02-26 17:50:26 +01:00
Brian Clozel 6b07c53c61 Allow file locations for resource handling
Prior to this change, location checks for serving resources would append
`/` to the location path it didn't already have one.

This commit makes sure not to append a `/` if the provided location is
actually a file.

Issue: SPR-12747
2015-02-26 14:19:59 +01:00
Rossen Stoyanchev 2dd5875964 Support @ControllerAdvice in StandaloneMockMvcBuilder
Issue: SPR-12751
2015-02-25 16:57:58 -05:00
Juergen Hoeller cc33d3fac8 Polishing 2015-02-25 19:05:06 +01:00
Ryan Skow 500179e5c0 Allow custom RequestMappingHandlerMapping
Extract the creation of RequestMappingHandlerMapping into protected
method to allow easier use of custom subclasses.

Issue: SPR-12746
2015-02-24 09:44:32 -05:00
Juergen Hoeller 7191050e26 Revised common validation methods in AbstractMessageConverterMethodArgumentResolver
The protected validation methods are analogous to ModelAttributeMethodProcessor now.

Issue: SPR-12655
2015-02-19 23:37:07 +01:00
Juergen Hoeller 406171c9c0 RequestPartMethodArgumentResolver declares @UsesJava8 now
Issue: SPR-12644
2015-02-18 16:54:10 +01:00
Juergen Hoeller 0c15a54007 Polishing 2015-02-18 16:45:16 +01:00
Juergen Hoeller 6ebac00f32 @RequestPart supports java.util.Optional
Issue: SPR-12644
2015-02-18 16:17:07 +01:00
Juergen Hoeller 61cc3b5bff ServletUriComponentsBuilder.java avoids NPE on scheme check
Issue: SPR-12723
2015-02-18 16:16:28 +01:00
Juergen Hoeller be76da654f Latest dependency updates (POI 3.11, FreeMarker 2.3.21) 2015-02-11 20:38:30 +01:00
Juergen Hoeller 058714b03a Polishing 2015-02-10 19:30:59 +01:00
Juergen Hoeller 7585be85f3 Revised validation javadoc, plus protected validate/isBindingErrorFatal template methods
Issue: SPR-12655
2015-02-10 19:28:30 +01:00
Rossen Stoyanchev f84c458aba Add fromHttpRequest to UriComponentsBuilder
Before this change, detection of X-Forwarded-* headers was only built
into ServletUriComponentsBuilder.

This change adds a new method for creating a UriComponentsBuilder from
an existing HttpRequest. This is equivalent to the fromUri method +
X-Forwarded-* header values.
2015-02-10 06:53:14 +01:00
Rossen Stoyanchev 8f0ddf1b1d Fix type check for ResponseEntity<ResponseBodyEmitter>
Issue: SPR-12693
2015-02-05 11:18:07 -05:00
Brian Clozel 13cdd22f5e Sort handler matches in ResourceUrlProvider
Prior to this change, the `ResourceUrlProvider.getForLookupPath` method
would try to match handlers using the keySet order in the
handlerMappings Map. In case of several matches, the handler used for
the return value could vary, since the registration order in the
handlerMappings can't be guaranteed in the configuration.

This commit now collects all matching handlers and sort them using a
`PatternComparator`, in order to try each handler from the most specific
mapping to the least.

Issue: SPR-12647
2015-02-03 17:07:55 +01:00
Rossen Stoyanchev a32b5e61d0 Add support for Server-Sent Events
This commit adds ResponseBodyEmitter and SseEmitter (and also
ResponseEntity<ResponseBodyEmitter> and ResponseEntity<SseEmitter>) as
new return value types supported on @RequestMapping controller methods.

See Javadoc on respective types for more details.

Issue: SPR-12212
2015-01-29 17:55:09 -05:00
Rossen Stoyanchev 0bfa124a1e Remove ISE in ResourceUrlProvider
Issue: SPR-12630
2015-01-22 17:08:20 -05:00
Rossen Stoyanchev d68fde57cd Support HandlerMethod arg in @ExceptionHandler methods
Issue: SPR-12605
2015-01-21 17:54:40 -05:00
Brian Clozel 2bf6b41bcc Initialize ResourceUrlProvider only once
Prior to this change, the ResourceUrlProvider would listen to
ContextRefreshedEvents and autodetect resource handlers each time. This
can cause issues when multiple contexts are involved and the last one
has no resource handler, thus clearing the previously detected ones.

This commit disables resource handlers auto-detection once some have
been detected with a refreshed context.

Issue: SPR-12592
2015-01-21 11:35:43 +01:00
Rossen Stoyanchev f949b2d3c3 Remove logging statement in ResponseBodyAdviceChain
Issue: SPR-12616
2015-01-20 17:22:51 -05:00
Brian Clozel bb78c76b8c Allow relative paths within resource location path
Prior to this change, location paths used for resource handling would
not allow "non-cleaned, relative paths" such as
`file://home/user/static/../static/`. When checking if the resolved
resource's path starts with the location path, a mismatch would happen
when comparing for example:

* the location `file://home/user/static/../static/`
* and the resource `file://home/user/static/resource.txt`

This commit cleans the location path before comparing it to the resource
path.

Issue: SPR-12624
2015-01-20 17:46:05 +01:00
Brian Clozel 028c0e8b80 Allow protocol relative URLs in CssLink Transformer
This commit allows the use of "protcol relative URLs" (i.e. URLs without
scheme, starting with `//`), often used to serve resources automatically
from https or http with third party domains.

This syntax is allowed by RFC 3986.

Issue: SPR-12632
2015-01-20 15:53:10 +01:00
Brian Clozel 3da9d92bf5 Fix context-relative default value in XML parsing
This commit fixes the default value for the contextRelative attribute of
a RedirectView, when this view is registered via a
RedirectViewController in XML. The value is set to true.

Note that the default value for this is correctly documented in
spring-mvc-4.1.xsd. Also, the documentation and implementation for its
javadoc counterpart also enforces true as a default value.

Issue: SPR-12607
2015-01-16 16:13:02 +01:00
Xiaolong Zuo 47b8ee891e Fix default HandlerMappings class names in javadoc
Fixes #708
2014-12-31 14:19:42 +01:00
Juergen Hoeller 9ac02b319d Remove pre-3.2 deprecated classes and methods
Issue: SPR-12578
2014-12-30 20:05:15 +01:00
Juergen Hoeller fad76336f6 Polishing 2014-12-30 15:26:43 +01:00
Juergen Hoeller 3bfe4dcca7 Switch responseEncodedHtmlEscape default to true
Issue: SPR-12369
2014-12-30 15:01:20 +01:00
Juergen Hoeller 86b8112c90 Polishing 2014-12-29 15:13:40 +01:00
Juergen Hoeller 6b3023c2aa HandlerExecutionChain prevents re-adding the interceptors array to the list (and declares varargs now)
Issue: SPR-12566
2014-12-23 18:27:49 +01:00
Rossen Stoyanchev 189ec75789 Add ability to clone to UriComponentsBuilder hierarchy
Issue: SPR-12494
2014-12-05 12:16:15 -05:00
Sebastien Deleuze 2fccf3ff44 Add support for autowiring Jackson handlers
This commit introduces the SpringHandlerInstantiator
class, a Jackson HandlerInstantiator that allows to autowire
Jackson handlers (JsonSerializer, JsonDeserializer, KeyDeserializer,
TypeResolverBuilder and TypeIdResolver) if needed.

SpringHandlerInstantiator is automatically used with
@EnableWebMvc and <mvc:annotation-driven />.

Issue: SPR-10768
2014-12-05 17:37:28 +01:00
Rossen Stoyanchev ad65119a2c Polish ServletUriComponentsBuilder 2014-12-04 10:30:14 -05:00
Rossen Stoyanchev 7f11c1ee2f Also apply X-Forwarded-Prefix in fromContextPath
Issue: SPR-12500
2014-12-04 10:15:55 -05:00
Rossen Stoyanchev d322bcfbf4 Use X-Forwarded-Prefix in ServletUriComponentsBuilder
Issue: SPR-12500
2014-12-03 13:46:25 -05:00
Rossen Stoyanchev 7aa5e65235 Add info on intercepting static resource requests
Issue: SPR-10655
2014-12-02 15:59:43 -05:00
Stephane Nicoll 1aad4da6b6 Remove compiler warning 2014-12-02 14:18:22 +01:00
Juergen Hoeller 2496d68e9f Relaxed final declarations and protected doInvoke methods
Issue: SPR-12484
2014-12-01 15:07:24 +01:00
Brian Clozel b3bfa95e2b Fix ResourceUrlEncodingFilter with context mapping
Prior to this change, the ResourceUrlEncodingFilter would work well when
the application is mapped to "/". But when mapped to a non-empty servlet
context, this filter would not properly encode URLs and apply
ResourceResolver URL resolution for resources.

This commit makes sure that the lookup path is properly resolved in the
request URI, taking into account the servlet context.

Issue: SPR-12459
2014-11-26 14:56:24 +01:00
Rossen Stoyanchev 24834f6d2f Add extendMessageConverters to WebMvcConfigurer
Issue: SPR-12450
2014-11-25 10:11:10 -05:00
Juergen Hoeller 929cda6790 Allow custom @Validated annotations for handler method parameters
Issue: SPR-12406
2014-11-24 23:34:24 +01:00
Juergen Hoeller 51bed18e61 Resource resolution and message escaping tests pass on Windows again 2014-11-24 15:06:44 +01:00
Brian Clozel 161d3e3049 Fix location checks for servlet 3 resources
SPR-12354 applied new checks to make sure that served static resources
are under authorized locations.

Prior to this change, serving static resources from Servlet 3 locations
such as "/webjars/" would not work since those locations can be within
one of the JARs on path. In that case, the checkLocation method would
return false and disallow serving that static resource.

This change fixes this issue by making sure to call the
`ServletContextResource.getPath()` method for servlet context resources.

Note that there's a known workaround for this issue, which is using a
classpath scheme as location, such as:
"classpath:/META-INF/resources/webjars/" instead of "/webjars".

Issue: SPR-12432
2014-11-24 14:08:54 +01:00
Juergen Hoeller 223d849a14 Polishing 2014-11-23 00:12:02 +01:00
Juergen Hoeller 2675ce7c9f Polishing 2014-11-22 18:05:35 +01:00
Juergen Hoeller ece2c90e91 RequestMappingHandlerAdapter allows for overriding handleInternal
Issue: SPR-12460
2014-11-22 17:37:45 +01:00
Juergen Hoeller 282adeda88 Unit test for JavaBeans introspection against FreeMarker Configuration class
Issue: SPR-12448
2014-11-22 16:47:19 +01:00
Rossen Stoyanchev 9cef8e3001 Apply extra checks to static resource handling
- remove leading '/' and control chars
- improve url and relative path checks
- account for URL encoding
- add isResourceUnderLocation final verification

Issue: SPR-12354
2014-11-11 07:12:44 +01:00
Juergen Hoeller 9ff8a01f29 Polishing 2014-11-07 17:14:50 +01:00
Juergen Hoeller 6a96850aa7 Polishing 2014-11-06 14:29:43 +01:00
Sam Brannen c78fd204df Explicitly mention DelegatingWebMvcConfiguration in @EnableWebMvc Javadoc 2014-11-03 17:42:17 +01:00
Juergen Hoeller 285dca027b Polishing
(cherry picked from commit acefd83)
2014-11-02 11:48:09 +01:00
Juergen Hoeller a9c47df0c1 Polishing 2014-11-01 14:05:32 +01:00
Juergen Hoeller 97ea43681b Polishing 2014-11-01 09:13:34 +01:00
Sebastien Deleuze cfa3d358d5 Add an alwaysInclude property to TilesViewResolver
Issue: SPR-12374
2014-10-31 19:39:29 +01:00
Juergen Hoeller 1146d5ba1d Polishing 2014-10-29 22:44:59 +01:00
Sebastien Deleuze 17b9bde336 Set ResponseStatusExceptionResolver.messageSource in the MVC Java config
Issue: SPR-12380
2014-10-28 13:44:13 +01:00
Rossen Stoyanchev da612d079f Replace "if(" with "if (" 2014-10-27 09:04:23 -04:00
Brian Clozel a0c210457b Use response encoding when escaping HTML
With SPR-9293, it is now possible to HTML escape text while taking into
account the current response encoding. When using UTF-* encodings, only
XML markup significant characters are escaped, since UTF-* natively
support those characters.

This commit adds a new servlet context parameter to enable this fix by
default in a Spring MVC application:

    <context-param>
      <param-name>responseEncodedHtmlEscape</param-name>
      <param-value>true</param-value>
    </context-param>

Issue: SPR-12350, SPR-12132
2014-10-24 11:53:47 +02:00
Juergen Hoeller cb860364dd TilesConfigurer defensively expects null from getResources in case of no resources found
Also includes order preservation for resource results with Tiles 2 as well as retrieval failure logging with Tiles 3.

Issue: SPR-12362
2014-10-23 17:23:52 +02:00
Rossen Stoyanchev 051c5fb66a Update javadoc 2014-10-22 22:28:21 -04:00
Sam Brannen 4412bc68aa Polish Javadoc 2014-10-23 01:06:12 +02:00
Brian Clozel a011b360d1 Polish SPR-12286
Issue: SPR-12286
2014-10-22 21:15:34 +02:00
Brian Clozel 86d97baf65 Allow defining default content negotiation strategy
During the HTTP Content Negotiation phase, the ContentNegotiationManager
uses configured ContentNegotiationStrategy(ies) to define the list of
content types accepted by the client.

When HTTP clients don't send Accept headers, nor use a configured
file extension in the request, nor a request param, developers can
define a default content type using the
ContentNegotiationConfigurer.defaultContentType() method.

This change adds a new overloaded defaultContentType method that takes a
ContentNegotiationStrategy as an argument. This strategy will take the
current request as an argument and return a default content type.

Issue: SPR-12286
2014-10-22 16:32:12 +02:00
Sam Brannen 6e5907ff39 Add missing text to CachingResourceTransformer Javadoc 2014-10-21 16:11:15 +02:00
Juergen Hoeller 8325b10080 Consistent formatting of license headers, package javadocs, and import declarations 2014-10-21 01:44:07 +02:00