Commit Graph

10070 Commits

Author SHA1 Message Date
Sam Brannen 502fa1796e Polish Javadoc for ClassUtils 2015-03-30 17:34:36 +02:00
Sam Brannen a4af5b8a3e Verify which factory methods are invoked in DefaultConversionServiceTests 2015-03-30 17:34:14 +02:00
Sam Brannen bddc4373fb Refactor ObjectToObjectConverter & improve exception msg
- The exception message now mentions lacking to-Object method as well.

- Documented explicit lacking support for toString() for conversions.

- Introduced dedicated has*() methods for greater clarity and to reduce
  code duplication.

- Static factory methods (i.e., of, from, valueOf) are now supported for
  conversion to a String.
2015-03-30 17:32:59 +02:00
Sam Brannen db96113bcf Polish Javadoc for converters 2015-03-30 16:24:24 +02:00
Sam Brannen 72d7963b30 Polish ConversionService tests
- Now correctly using @Test(expected=...) where appropriate.

- Renamed DefaultConversionTests to DefaultConversionServiceTests.

- Moved all tests related to DefaultConversionService from
  GenericConversionServiceTests to DefaultConversionServiceTests.

- No longer printing to System.out.

- Removed all duplicate instantiation of conversion services.

- Now using Java 8 streams to simplify implementations of custom test
  converters. Also using streams in tests where appropriate.
2015-03-30 15:58:29 +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
Stephane Nicoll 073c176400 Fix test
The rework of 314b069 in a7fec6a has created a lazy proxy to make sure
that the need for an exception cache resolver come as late as possible.

Unfortunately, the test that was only failing on CI because of an early
lookup has not been updated accordingly. This is now the case.

Issue: SPR-12850
2015-03-28 12:23:30 +01:00
Stephane Nicoll a7fec6a459 Lazily resolve the default exception CacheResolver
This is a rework of 314b069 that may still lead to issue if a Cacheable
annotated bean is inspected on startup. Instead of resolving the default
exception CacheResolver if a cache operation is parsed, we resolve it as
late as possible (i.e. when an exception is thrown and the relevant
exception cache needs to be resolved)

Issue: SPR-12850
2015-03-27 09:42:06 +01:00
Rossen Stoyanchev 867971de89 Add STOMP client documentation
Issue: SPR-12814
2015-03-26 22:45:15 -04:00
Rossen Stoyanchev 73d6d30951 Add flag whether to create HTTP session
Issue: SPR-12840
2015-03-26 17:28:26 -04:00
Rossen Stoyanchev ae3417133b Add public access to PathMatcher in WebSocket config
Issue: SPR-12845
2015-03-26 16:50:33 -04:00
Juergen Hoeller beae336627 Polishing 2015-03-25 15:22:41 +01:00
Juergen Hoeller e7dde740b9 Reduced DefaultListableBeanFactory's override logging to debug level for equivalent bean definition
Issue: SPR-7607
2015-03-25 15:21:58 +01:00
Stephane Nicoll 314b069fd8 Only require an exception CacheResolver if necessary
Previously, a cache infrastructure with only a CacheResolver would have
worked fine until the JSR-107 API is added to the classpath. When this is
the case, the JCache support kicks in and an exception cache resolver is
all of the sudden required.

The CacheResolver _is_ different as the default implementation does look
different attributes so if a custom CacheResolver is set, it is not
possible to "reuse" it as a fallback exception CacheResolver.

Now, an exception CacheResolver is only required if a JSR-107 annotation
with an "exceptionCacheName" attribute is processed (i.e. the exception
CacheResolver is lazily instantiated if necessary).

The use case of having a CachingConfigurerSupport with only a
CacheResolver was still broken though since the JCache support only looks
for a JCacheConfigurer bean (per the generic type set on
AbstractCachingConfiguration). This has been fixed as well.

Issue: SPR-12850
2015-03-25 15:12:08 +01:00
Juergen Hoeller d23893fd25 Consistent javadoc param declarations for type variables 2015-03-25 00:44:01 +01:00
Juergen Hoeller 22670b7fad Fixed addConverterFactory assertion 2015-03-25 00:42:51 +01:00
Juergen Hoeller 4e28da439d TcpConnection extends java.io.Closeable
Issue: SPR-12849
2015-03-25 00:42:14 +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 4e1af7d195 Deprecated MatcherAssertionErrors in favor of the original org.hamcrest.MatcherAssert (v1.3)
As of JUnit 4.9 / Hamcrest 1.3, there is no real need for a custom copy of that class anymore.
2015-03-25 00:04:47 +01:00
Rossen Stoyanchev e81862eed6 Allow modifying HandshakeInterceptor list
The getter in TransportHandlingSockJsService now returns a mutable
List. The immutable wrapper doesn't make sense since it's possible
anyway to modify the list by creating a new list and calling the
setter again. It's also consistent with the same field on
WebSocketHttpRequestHandler.

This is related to work for SPR-12845.
2015-03-24 18:03:15 -04:00
Rossen Stoyanchev b620f34ad8 Minor doc update 2015-03-24 16:45:51 -04: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 209e8de188 Document async request processing enhancements
Generally update chapter and add documentation for 4.2 including
the return value types ResponseBodyEmitter, SseEmitter, and
StreamingResponseBody.

Issue: SPR-12672
2015-03-24 16:05:28 -04:00
Juergen Hoeller 5b09723bb4 Polishing 2015-03-24 19:20:34 +01:00
Juergen Hoeller 26d4f91835 Compatibility with EhCache 3.0 M1 (as a JCache provider)
Issue: SPR-12847
2015-03-24 19:20:26 +01:00
Juergen Hoeller 09027f7972 ResolvableType.forRawClass as a straight wrapper for Class.isAssignableFrom
Issue: SPR-12846
2015-03-24 19:20:15 +01:00
Juergen Hoeller b2308926bc Restored isTypeMatch null behavior and refined typeToMatch parameter name
Issue: SPR-12147
2015-03-23 21:57:03 +01:00
Rossen Stoyanchev 44e8f7b333 Revert "Support {/var} syntax in UriComponentsBuilder"
This reverts commit a57d42829c after the
realization of a weaknesses with the proposed approach.

For example if a path segment contains both a /-prefixed and a regular
URI variable, there is no way to split that into a sequence of path
and path segments. The solution will have to be on the side of
UriComponents at the time of encoding.
2015-03-23 16:44:03 -04: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
Juergen Hoeller 1a8c6fa5ee Deferred import processing reliably detects late registration attempts
Issue: SPR-12838
2015-03-23 19:58:02 +01:00
Brian Clozel 7f845f7b5e Fix failing HeaderAssertionTests
Since SPR-11792, Last-Modified and ETag headers are also written in
`HTTP 304 Not Modified` responses. This is expected as per
https://tools.ietf.org/html/rfc7232#section-4.1 .

Those tests expected "Last-Modified" to be missing in case of HTTP 304
responses, which is not the case anymore since 953608ec .

Issue: SPR-11792
2015-03-23 18:50:32 +01:00
Brian Clozel 90ed0cf04c Document HTTP caching features in 4.2
Issue: SPR-11792
2015-03-23 18:05:53 +01:00
Brian Clozel 7fa4ac1cf8 Externalize javadoc-baseurl asciidoctor attribute
The `javadoc-baseurl` asciidoctor attribute is now externalized
(i.e. not included directly in the document anymore).

This allows to properly render javadoc links in single pages, whereas
those URLs were previoulsy only supported in the single page version.
2015-03-23 18:05:53 +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
Markus Malkusch 953608ec49 Improve ETag & Last-Modifed support in WebRequest
This change improves the following use cases with
`WebRequest.checkNotModified(String etag)` and
`WebRequest.checkNotModified(long lastModifiedTimeStamp)`:

1) Allow weak comparisons for ETags

Per rfc7232 section-2.3, ETags can be strong or weak;
this change allows comparing weak forms `W/"etagvalue"` but does
not make a difference between strong and weak comparisons.

2) Allow multiple ETags in client requests

HTTP clients can send multiple ETags values in a single header such as:
`If-None-Match: "firstvalue", "secondvalue"`
This change makes sure each value is compared to the one provided by
the application side.

3) Extended support for ETag values

This change adds padding `"` to the ETag value provided by
the application, if not already done:
`etagvalue` => `"etagvalue"`

It also supports wildcard values `*` that can be sent by HTTP clients.

4) Sending validation headers for 304 responses

As defined in https://tools.ietf.org/html/rfc7232#section-4.1
`304 Not Modified` reponses must generate `Etag` and `Last-Modified`
HTTP headers, as they would have for a `200 OK` response.

5) Providing a new method to validate both Etag & Last-Modified

Also, this change adds a new method
`WebRequest.checkNotModified(String etag, long lastModifiedTimeStamp)`
in order to support validation of both `If-None-Match` and
`Last-Modified` headers sent by HTTP clients, if both values are
supported by the application code.

Even though this approach is recommended by the HTTP rfc (setting both
Etag and Last-Modified headers in the response), this requires more
application logic and may not apply to all resources produced by the
application.

Issue: SPR-11324
2015-03-23 17:36:06 +01:00
Sam Brannen e086a637d5 Introduce BEFORE METHOD/CLASS modes in @DirtiesContext
Prior to this commit, @DirtiesContext could only be used to close a
test ApplicationContext after an entire test class or after a test
method; however, there are some use cases for which it would be
beneficial to close a test ApplicationContext before a given test class
or test method -- for example, if some rogue (i.e., yet to be
determined) test within a large test suite has corrupted the original
configuration for the ApplicationContext.

This commit provides a solution to such testing challenges by
introducing the following modes for @DirtiesContext.

 - MethodMode.BEFORE_METHOD: configured via the new methodMode attribute

 - ClassMode.BEFORE_CLASS and ClassMode.BEFORE_EACH_TEST_METHOD: both
   configured via the existing classMode attribute

Issue: SPR-12429
2015-03-22 21:33:20 +01:00
Sam Brannen 6028a64444 Polish Javadoc for TestContext 2015-03-22 21:33:06 +01:00
Stephane Nicoll 9172a6d05e Restore proper use of CacheLoader
Since Guava 11, CacheLoader is only invoked with a LoadingCache but the
GuavaCache wrapper is always invoking getIfPresent(), available on the
main Guava Cache interface.

Update GuavaCache#get to check for the presence of a LoadingCache and
call the appropriate method.

Issue: SPR-12842
2015-03-22 10:02:36 +01:00
Juergen Hoeller 7513bd5757 Latest dependency updates (Groovy 2.4.2, Hibernate Validator 5.2 beta 1) 2015-03-21 01:19:16 +01:00
Juergen Hoeller 56273a8ff3 Polishing 2015-03-21 01:19:01 +01:00
Sam Brannen 3d2bde7156 Add tests that use the new generate-name attribute
This commit updates the Spr8849Tests test suite to include XML
configuration that guarantees that a unique database name is always
automatically generated (via the new 'generate-name' attribute that was
introduced in SPR-8849) while reusing the same bean name (i.e.,
'dataSource').

Issue: SPR-8849
2015-03-21 00:39:54 +01:00
Sam Brannen c0fbe0ae5a Support unique names for embedded databases
Development teams often encounter errors with embedded databases if
their test suite inadvertently attempts to recreate additional
instances of the same database. This can happen quite easily if an XML
configuration file or @Configuration class is responsible for creating
an embedded database and the corresponding configuration is then reused
across multiple testing scenarios within the same test suite (i.e.,
within the same JVM process) -- for example, integration tests against
embedded databases whose ApplicationContext configuration only differs
with regard to which bean definition profiles are active.

The root cause of such errors is the fact that Spring's
EmbeddedDatabaseFactory (used internally by both the
<jdbc:embedded-database> XML namespace element and the
EmbeddedDatabaseBuilder for Java Config) will set the name of the
embedded database to "testdb" if not otherwise specified. For the case
of <jdbc:embedded-database>, the embedded database is typically
assigned a name equal to the bean's id. Thus, subsequent attempts to
create an embedded database will not result in a new database. Instead,
the same JDBC connection URL will be reused, and attempts to create a
new embedded database will actually point to an existing embedded
database created from the same configuration.

This commit addresses this common issue by introducing support for
generating unique names for embedded databases. This support can be
enabled via:

 - EmbeddedDatabaseFactory.setGenerateUniqueDatabaseName()

 - EmbeddedDatabaseBuilder.generateUniqueName()

 - <jdbc:embedded-database generate-name="true" ... >

Issue: SPR-8849
2015-03-21 00:21:59 +01:00
Rossen Stoyanchev 0c9cd4cc32 SubProtocolWebSocketHandler checks if session is open
Issue: SPR-12812
2015-03-20 17:45:27 -04:00
Rossen Stoyanchev 4886edd10b Send STOMP ERROR if external broker not available
Issue: SPR-12820
2015-03-20 17:34:31 -04:00
Rossen Stoyanchev 18039785ae Update Javadoc of AsyncHandlerInterceptor
Issue: SPR-12608, SPR-12720
2015-03-20 16:58:01 -04:00
Rossen Stoyanchev f06dffb714 Improve MockHttpServletRequest/Response charset parsing
Issue: SPR-12677
2015-03-20 16:12:46 -04:00