Commit Graph

534 Commits

Author SHA1 Message Date
Rossen Stoyanchev 909156e1b6 Fix test failure 2014-09-30 10:57:40 -04:00
Rossen Stoyanchev 77bbfb6e7e Add order attribute to MVC ViewResolver config
The ViewResolverComposite that contains the ViewResolver's registered
throug the MVC Java config and namespace can now be assigned an
explicit order.
2014-09-30 10:38:23 -04:00
Rossen Stoyanchev 3b1d3257d5 Consistent default order for composite ViewResolver
The MVC Java config and namespace now have a consistent default order
or lowest precedence.
2014-09-30 10:38:23 -04:00
Rossen Stoyanchev 27f58db320 Polish ViewResolversBeanDefinitionParser 2014-09-30 10:38:23 -04:00
Sebastien Deleuze 77abe07807 Set Jackson DEFAULT_VIEW_INCLUSION property to false by default
Issue: SPR-12179
2014-09-30 05:18:15 +02:00
Sebastien Deleuze 42aef5f5dc Set Jackson FAIL_ON_UNKNOWN_PROPERTIES property to false by default
Issue: SPR-11891
2014-09-30 05:18:15 +02:00
Sebastien Deleuze 4e24d66ff7 Create a builder for Jackson ObjectMapper
Jackson2ObjectMapperBuilder now allows to create ObjectMapper and XmlMapper
instances easily thanks to its fluent API.

This builder is used in Jackson message converters and views to instantiate default
ObjectMapper and XmlMapper.

This commit also add a createXmlMapper property to
Jackson2ObjectMapperFactoryBean in order to allow to create easily a XmlMapper
instance.

Issue: SPR-12243
2014-09-30 05:18:15 +02:00
Rossen Stoyanchev 803fc20019 Correct check for ViewResolver beans
Check for bean names of type rather than actual beans.

Issue: SPR-12267
2014-09-29 17:59:46 -04:00
Rossen Stoyanchev 49cf30e964 Update default view resolver in MVC Java config
When not ViewResolver's have been registered, detect if the context
contains any other ViewResolver beans. If not, add InternalResourceVR
to match default DispatcherServlet behavior.

Issue: SPR-12267
2014-09-29 17:22:00 -04:00
Juergen Hoeller ae43b17fa0 JsonViewResponseBodyAdvice throws IllegalArgumentException in case of >1 view class specified
Issue: SPR-12270
2014-09-29 22:45:10 +02:00
Juergen Hoeller 1f3e195dac Polishing 2014-09-25 17:00:45 +02:00
Juergen Hoeller cfc821d179 DataBinder unwraps Optional objects and allows for proper handling of Optional.empty()
Issue: SPR-12241
2014-09-25 17:00:36 +02:00
Juergen Hoeller 281b243b88 HttpEntityMethodProcessor supports custom HttpEntity subclasses again
Issue: SPR-12242
2014-09-24 17:56:07 +02:00
Rossen Stoyanchev a9b2a12491 Allow ResponseBodyAdvice to modify null return values
This change defers determination of whether to invoke a message
converter in case of a null @ResponseBody value (or ResponseEntity with
a null body) until after the invocation of the ResponseBodyAdvice
chain. This allows a ResponseBodyAdvice to handle null values
potentially turning them into non-null value.s

Issue: SPR-12152
2014-09-19 14:57:56 -04:00
Juergen Hoeller d3ea242085 Polishing 2014-09-17 15:01:39 +02:00
Juergen Hoeller 15320db414 Polishing 2014-09-17 02:35:41 +02:00
Juergen Hoeller c778868d66 WebMvcConfigurationSupport uses static NoOpValidator instead of anonymous inner class 2014-09-16 23:43:25 +02:00
Juergen Hoeller 5790fc904a Consistent support for java.util.Optional for all applicable handler method arguments
Issue: SPR-12171
2014-09-10 01:27:46 +02:00
Brian Clozel 6aef1a1d17 Fix ResourceUrlProvider path check in getForRequestUrl
Prior to this change, getForRequestUrl implementation would only work
for applications with a non-empty servlet path. So web applications
mapped to "/" would trigger a IllegalStateException while checking the
current request against the request path within the current mapping.

This change relaxes this and only check that the path within mapping is
within the request URL.

Issue: SPR-12158
2014-09-05 22:46:13 +02:00
Sebastien Deleuze 1c2857d15e Add tests for Jackson @JSONView when using XML serialization
This commit also fixes the AbstractMappingJacksonResponseBodyAdvice Javadoc.

Issue: SPR-12149
2014-09-05 17:13:27 +02:00
Juergen Hoeller 7953c5fd88 FrameworkServlet skips HttpServletResponse.getStatus() call on Servlet 2.5
Issue: SPR-12151
2014-09-05 00:37:13 +02:00
Sebastien Deleuze a29e41b9fa Fix Jackson @JSONView when using XML serialization
Issue: SPR-12149
2014-09-04 11:57:54 +02:00
Brian Clozel 7b93cefe64 Fix resource-chain XML syntax for cache
This change moves the resource-cache configuration to the
<resource-chain/> tag, since enabling/disabling resource cache should
be driven by a property or a SpEL expression.

So now that configuration can be set with XML attributes:

  <mvc:resource-chain resource-cache="true"
  cache-manager="resourceCache" cache-name="test-resource-cache">

In order to mirror the JavaConfig behavior, the "resource-cache"
attribute is required.

Issue: SPR-12129
2014-09-04 10:05:33 +02:00
Rossen Stoyanchev d85c1fbdd5 Fix initialization issue in ResourceUrlProvider
Before this change ResourceUrlProvider used getUrlMap to detect
ResourceHttpRequestHandler instances, however the map may contain bean
names as is the case when using <mvc:resources>. Instead it now uses
getHandlerMap.
2014-09-04 00:16:48 -04:00
Rossen Stoyanchev 3e390d1f7f Declare ResourceUrlProvider in MVC namespace
This change adds a ResourceUrlProvider bean to the
ResourceBeanDefinitionParser to match the same in the Java config.
For consistency the name of the bean in the Java config is renamed.

Also a ResourceUrlProviderExposingInterceptor is declares as a global
MappedInterceptor.
2014-09-04 00:16:48 -04:00
Juergen Hoeller d75f128752 Polishing 2014-09-04 03:03:12 +02:00
Juergen Hoeller 86b7118da8 Polishing 2014-09-04 02:30:25 +02:00
Rossen Stoyanchev 801658d362 Rename test class to match name of class being tested 2014-09-03 12:51:26 -04:00
Brian Clozel 125ae99035 Transform absolute links in ResourceTransformers
Prior to this change, ResourceTransformers that transformed resources by
updating the links to other resources, worked only if links were
relative to the resource being transformed.
For example, when the CssLinkResourceTransformer rewrote links within
a "main.css" resource, only links such as "../css/other.css" were
rewritten.

Using relative links is a recommended approach, because it's totally
independent from the application servlet path, context path, mappings...

This change allows absolute links to be rewritten by those Transformers,
provided those links are accurate and point to existing resources.

Issue: SPR-12137
2014-09-03 12:06:12 +02:00
Brian Clozel 2ef20f63bc Remove assertion making locations mandatory
This change finishes work started in SPR-12133.

Issue: SPR-12133
2014-09-02 10:44:08 +02:00
Sebastien Deleuze 36542549fa Add HTTP status to ServletRequestHandledEvent
Issue: SPR-12119
2014-08-29 21:47:03 -04:00
Brian Clozel 76c46fdbe3 Change resource handler XML Namespace
This commit changes the way a <mvc:resource-cache> can be configured
with a user defined Cache instance.

Now a reference to a CacheManager Bean and a Cache name must be
provided. This is a more flexible configuration for typical XML setups.

  <mvc:resource-cache
    cache-manager="resourceCache"
    cache-name="test-resource-cache"/>

Issue: SPR-12129
2014-08-29 18:55:39 +02:00
Rossen Stoyanchev 4df05d1f98 Remove assertion on number of resource locations
With the new ResourceResolver abstraction and resource resolver chain
in 4.1, the assumption that resources are found by checking for the URL
path under the configured locations is no longer accurate.

A custom ResourceResolver could find resources in ways that don't
depend on a list of locations.

Issuse: SPR-12133
2014-08-29 11:29:49 -04:00
Brian Clozel d9f4016c35 Update resource handler XML Namespace
This change introduces a new <mvc:resource-chain/> tag that mirrors
the ResourceChainRegistration java config counterpart.

Resolvers and Transformers can be registered with bean/ref tags, and
specific tags have been created for <mvc:version-resovlver> and
<mvc:resource-cache> in order to make common configurations easier.

Note that a specific "auto-configuration" attribute on the
resource-chain allows to completely disable default registration of
Resolvers and Transformers (sane defaults considered by the Framework).

  <mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/">
      <mvc:resource-chain>
        <mvc:resource-cache cache="resourceCache"/>
        <mvc:resolvers>
          <mvc:version-resolver>
            <mvc:fixed-version-strategy version="abc" patterns="/**/*.js"/>
            <mvc:content-version-strategy patterns="/**"/>
          </mvc:version-resolver>
        </mvc:resolvers>
        <mvc:transformers>
          <bean class="org.springframework.web.servlet.resource.AppCacheManifestTransformer"/>
        </mvc:transformers>
      </mvc:resource-chain>
  </mvc:resources>

This also fixes a typo in the class name of
AppCacheManifestResourceTransfo*r*mer.

Issue: SPR-12129
2014-08-29 16:02:49 +02:00
Rossen Stoyanchev 0b02551e2f Update resource handler Java config
This change separates out resource chain related methods previously in
ResourceHandlerRegistration into a new class ResourceChainRegistration
with the goal of improving readability.

Along with that, the registration of caching resolver and transformer
is now explicitly controled with a boolean flag (on the method used
to obtain the ResourceChainRegistration) and an overloaded method
also allows providing a Cache instance.

Issue: SPR-12124
2014-08-28 22:32:38 -04:00
Rossen Stoyanchev ae48b5f7f2 Move builder methods to VersionResourceResolver
This change moves the VersionStrategy builder-style methods from
ResourceHandlerRegistration to VersionResourceResolver.

This makes the methods more universally usable and also makes use of
ResourceHandlerRegistration more readable, i.e. simply a sequence of
addResource and addTransformer calls.
2014-08-28 14:25:08 -04:00
Rossen Stoyanchev fbfb7a3c48 Add PathResourceResolver conditionally
The ResourceHandlerRegistration now checks if the last resolver is an
instance of PathResourceResolver and if so it skips adding it.

This change also creates and adds the VersionResourceResolver (as well
as CssLinkTransformer) the first time any VersionStrategy is
registered. This ensures that custom resolvers (including an extension
of PathResourceResolver) may be added both before and after the
VersionResourceResolver.

Lastly this change renames addVersion and addVersionHash to be
consistent with addVersionStrategy.

Issue: SPR-12124
2014-08-27 13:30:43 -04:00
Rossen Stoyanchev 8f715a8547 Allow configuration of custom redirect patterns
This change enables the ability to configure
ViewNameMethodReturnValueHandler & ModelAndViewMethodReturnValueHandler
with patterns to use to test for a custom redirect view name.

Issue: SPR-12054
2014-08-25 16:18:09 -04:00
Juergen Hoeller 786fd927fa DispatcherServlet's checkMultipart detects wrapped MultipartRequest as well
Issue: SPR-12114
2014-08-22 16:46:36 +02:00
Juergen Hoeller b5763fe326 Consistent attribute documentation/formatting in spring-context and spring-mvc schemas 2014-08-20 16:36:12 +02:00
Juergen Hoeller 891335a604 FlashMap's equals implementation needs to call super.equals(...) as well 2014-08-19 23:29:12 +02:00
Rossen Stoyanchev 1ca0460534 Add equals/hashcode to FlashMap
Brings consistency with the existing compareTo implementation.
2014-08-19 16:00:55 -04:00
Rossen Stoyanchev bb8be509cd Remove return statements in finally blocks 2014-08-19 15:27:59 -04:00
Rossen Stoyanchev 0e49040707 Fix hashcode/equals issue in HeadersRequestCondition 2014-08-19 15:16:41 -04:00
Sebastien Deleuze 6665634675 Support Jackson based XML serialization/deserialization
This commit adds support for XML serialization/deserialization based on
the jackson-dataformat-xml extension. When using @EnableWebMvc or
<mvc:annotation-driven/>, Jackson will be used  by default instead of JAXB2
if jackson-dataformat-xml classes are found in the classpath.

This commit introduces MappingJackson2XmlHttpMessageConverter and
MappingJackson2XmlView classes, and common parts between JSON
and XML processing have been moved to AbstractJackson2HttpMessageConverter
and AbstractJackson2View classes.

MappingJackson2XmlView supports serialization of a single object. If the model
contains multiple entries, MappingJackson2XmlView.setModelKey() should be
used to specify the entry to serialize.

Pretty print works in XML, but tests are not included since a Woodstox dependency
is needed, and it is better to continue testing spring-web and spring-webmvc
against JAXB2.

Issue: SPR-11785
2014-08-13 16:22:58 +02:00
Juergen Hoeller 92bd240474 Polishing
Issue: SPR-12079
2014-08-13 15:04:58 +02:00
Juergen Hoeller 626a5fe4eb BeanNameViewResolver ignores non-View beans
Issue: SPR-12079
2014-08-13 14:57:40 +02:00
Phillip Webb ac8326d2df Polish mockito usage
Consistent use of BDDMockito rather than standard Mockito.
2014-08-11 16:23:11 -07:00
Juergen Hoeller 4db258b9e3 Polishing 2014-08-11 22:32:03 +02:00
Juergen Hoeller 7c57424b48 Tiles 3 TilesViewResolver allows for specifying custom TilesView subclasses as well
Issue: SPR-12075
2014-08-10 01:08:27 +02:00