Commit Graph

9775 Commits

Author SHA1 Message Date
Juergen Hoeller 918bc3b103 Avoid ConcurrentModificationException in getBeansWithAnnotation
Issue: SPR-12688
2015-02-10 19:24:34 +01:00
Stephane Nicoll 13ccc8ede8 Merge pull request #723 from svolsky/SPR-12653
* SPR-12653:
  Synchronize clear on TransactionAwareCacheDecorator
2015-02-10 14:53:43 +01:00
Stas Volsky ef95fc2f7e Synchronize clear on TransactionAwareCacheDecorator
Previously, a cache decorated with TransactionAwareCacheDecorator would
clear the cache immediately, even when a transaction is running. This
commit updates the decorator to synchronize to the afterCommit phase for
the clear operation as well.

Issue: SPR-12653
2015-02-10 14:53:16 +01:00
Stephane Nicoll 6b3092c236 Clear expression caches on context shutdown
Issue: SPR-12691
2015-02-10 14:47:15 +01:00
Stephane Nicoll 37c04bd9c8 Fix usage of Java8 API 2015-02-10 09:47:34 +01:00
Stephane Nicoll 4741a12fdc Support for transactional event listener
Update the application event listener infrastructure to support events
that are processed according to a transactional phase.

Introduce EventListenerFactory that can be implemented to provide support
for additional event listener types. TransactionalEventListener is a new
annotation that can be used in lieu of the regular EventListener. Its
related factory implementation is registered in the context automatically
via @EnableTransactionManagement or <tx:annotation-driven/>

By default, a TransactionalEventListener is invoked when the transaction
has completed successfully (i.e. AFTER_COMMIT). Additional phases are
provided to handle BEFORE_COMMIT and AFTER_ROLLBACK events.

If no transaction is running, such listener is not invoked at all unless
the `fallbackExecution` flag has been explicitly set.

Issue: SPR-12080
2015-02-10 09:14:33 +01:00
Stephane Nicoll f0fca890bb Annotation-based event listeners
Add support for annotation-based event listeners. Enabled automatically
when using Java configuration or can be enabled explicitly via the
regular <context:annotation-driven/> XML element. Detect methods of
managed beans annotated with @EventListener, either directly or through
a meta-annotation.

Annotated methods must define the event type they listen to as a single
parameter argument. Events are automatically filtered out according to
the method signature. When additional runtime filtering is required, one
can specify the `condition` attribute of the annotation that defines a
SpEL expression that should match to actually invoke the method for a
particular event. The root context exposes the actual `event`
(`#root.event`) and method arguments (`#root.args`). Individual method
arguments are also exposed via either the `a` or `p` alias (`#a0` refers
to the first method argument). Finally, methods arguments are exposed via
their names if that information can be discovered.

Events can be either an ApplicationEvent or any arbitrary payload. Such
payload is wrapped automatically in a PayloadApplicationEvent and managed
explicitly internally. As a result, users can now publish and listen
for arbitrary objects.

If an annotated method has a return value, an non null result is actually
published as a new event, something like:

@EventListener
public FooEvent handle(BarEvent event) { ... }

Events can be handled in an aynchronous manner by adding `@Async` to the
event method declaration and enabling such infrastructure. Events can
also be ordered by adding an `@Order` annotation to the event method.

Issue: SPR-11622
2015-02-10 09:13:02 +01:00
Stephane Nicoll 6d6422acde Support for generics-based events
Update the event publishing infrastructure to support generics-based
events, that is support ApplicationListener implementations that define
a generic event, something like:

public class MyListener
        implements ApplicationListener<GenericEvent<String>> { ... }

This listener should only receive events that are matching the generic
signature, for instance:

public class StringEvent extends GenericEvent<String> { ... }

Note that because of type erasure, publishing an event that defines the
generic type at the instance level will not work. In other words,
publishing "new GenericEvent<String>" will not work as expected as type
erasure will define it as GenericEvent<?>.

To support this feature, use the new GenericApplicationListener that
supersedes SmartApplicationListener to handle generics-based even types via
`supportsEventType` that takes a ResolvableType instance instead of the
simple Class of the event. ApplicationEventMulticaster has an additional
method to multicast an event based on the event and its ResolvableType.

Issue: SPR-8201
2015-02-10 09:08:12 +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
Sebastien Deleuze 9b3319b3b3 Fix SockJS origin check
This commit introduces the following changes:
 - Requests without Origin header are not rejected anymore
 - Disable Iframe when allowedOrigins is not empty and not equals to *
 - The Iframe is not cached anymore in order to have a reliable origin check
 - allowedOrigins must not be null or empty
 - allowedOrigins format is now validated (should be * or start by http(s)://)

Issue: SPR-12660
2015-02-09 11:56:51 +01:00
Stephane Nicoll 29a6d24d65 Clarify the use of @Cacheable in PostConstruct code
Update documentation to explicitly mention that the cache interceptor
must be fully initialized to provide the expected behavior and therefore
initialization code should not rely on this feature, i;e. typically in
PostConstruct callback.

Since the Transactional infrastructure has the exact same infrastructure,
update that section of the doc as well.

Issue: SPR-12700
2015-02-09 10:09:12 +01:00
Stephane Nicoll 982f9ce6c9 Allow MBeans to be excluded additively
Previously, one could only set the list of bean names to exclude from
auto-detection and there was no way to add additional bean names.

MBeanExporter now exposes a addExcludedBean method that can be invoked
during the initialization phase to add bean names to ignore.

Issue: SPR-12686
2015-02-09 09:41:03 +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
Ralph Schaer e0d407dad0 Fix javadoc 2015-02-03 10:41:56 -05:00
Sebastien Deleuze b215d4c29e Add modulesToInstall(Modules...) to Jackson builder
This commit also adds a modules(Module...) method in addition to
modules(List<Module> modules) in order to be consistent with other
parts of the API.

Issue: SPR-12634
2015-02-03 11:58:21 +01:00
Rossen Stoyanchev 78f3a3cb11 Update javadoc for MultipartFile.transferTo
Issue: SPR-12650
2015-02-02 17:29:39 -05:00
Rossen Stoyanchev fd426aaa4d Update Netty4ClientHttpRequestFactory buffer size
Before this change, the maxRequestSize property was used (incorrectly)
to limit both the size of the request and response. The change:

- removes maxRequestSize and therefore no longer places limits on the
size of the request thus matching to AbstractBufferingClientHttpRequest
which is the base class for other buffering client implementations.

- adds maxResponseSize property required to create Netty's
HttpObjectAggregator for aggregating responses.

Issue: SPR-12623
2015-02-02 15:50:22 -05:00
Rossen Stoyanchev f017cc3feb DefaultSubscriptionRegistry returns safe to iterate Map
Prior to this change when adding subscriptions
DefaultSubscriptionRegistry (incorrectly) made a copy of the given map
for its "access" cache rather than for its "update" cache.

Issue: SPR-12665
2015-02-02 13:52:12 -05:00
Stephane Nicoll d8cec8534e Allow subclasses to configure the Yaml instance
Provide an additional hook-point for YamlProcessor subclasses willing to
change how the Yaml instance is configured. Also expose the default
StrictMapAppenderConstructor so that  they can compose a custom instance
with it.

Issue: SPR-12671
2015-02-02 11:28:54 +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
Sebastien Deleuze ccb1c13951 Use UTC timezone in Jackson builder and factory tests
Issue: SPR-12634
2015-01-26 15:59:15 +01:00
Stephane Nicoll c7b324b89b Move cached expression evaluation abstraction
Move MethodCacheKey and related classes to the expression package so that
other parts of the framework can benefit ot it.

CacheExpressionEvaluator is a base class that can be used to cache SpEL
expressions based on its annotation source (i.e. method). Sub-classing
that base class provides a simple to use API to retrieve Expression
instances efficiently.

Issue: SPR-12622
2015-01-26 14:44:14 +01:00
Brian Clozel cf86ecddb5 Avoid loss of body content in AbstractRequestLoggingFilter
Prior to this commit, the `ContentCachingRequestWrapper` class would
cache the response content only if the reponse would be consumed using
its InputStream. In case of a Form request, Spring MVC consumes the
response using the `getParameter*` Servlet API methods. This causes the
cached content to never be written.

This commit makes the `ContentCachingResponseWrapper` write the request
body to the cache buffer by using the `getParameter*` API, thus avoiding
those issues.

Issue: SPR-7913
2015-01-26 11:41:34 +01:00
Sebastien Deleuze 5fb6d6d89c Allow Jackson builder modules configuration to be customized
Modules (well-known or user provided) registration is now performed
first in order to allow their configuration to be customized by more
specific ones like custom serializers or deserializers.

Issue: SPR-12634
2015-01-26 11:08:08 +01:00
Sam Brannen 6e10f7c8cf Update TODOs for SPR-11598 2015-01-24 18:01:43 +01:00
Sam Brannen 2d918380f0 Support @Configuration as meta-annotation in the TCF
Spring Framework 4.0 introduced support for using test-related
annotations as meta-annotations in the Spring TestContext Framework
(TCF) in order to create custom composed annotations within a test
suite; however, the detection of default @Configuration classes in test
classes was not updated to search for @Configuration declared as a
meta-annotation. Specifically, AnnotationConfigContextLoaderUtils
invokes Class.isAnnotated() which only searches for annotations
declared directly on the class in question.

This commit addresses this issue by refactoring the
isDefaultConfigurationClassCandidate() method in
AnnotationConfigContextLoaderUtils so that it uses
AnnotationUtils.findAnnotation() instead of Class.isAnnotated() for
detecting the presence of the @Configuration annotation, either
directly or as a meta-annotation.

Issue: SPR-12659
2015-01-23 22:13:04 +01:00
Sam Brannen c5c32ec206 Refer to static nested classes, not static inner classes
Various parts of the reference manual as well as the Javadoc for
AnnotationConfigContextLoaderUtils improperly refer to "static inner
classes" even though this terminology does not exist in Java. The Java
Language Specification explicitly refers to such classes as "static
nested classes." An "inner class" must be non-static by definition.
2015-01-23 21:41:12 +01:00
Sam Brannen e97712b95b Update copyright headers in IdGenerators 2015-01-23 21:12:45 +01:00
Rossen Stoyanchev 52b8f34468 Add JdkIdGenerator and use it in SockJS client
Issue: SPR-12658
2015-01-22 21:27:36 -05:00
Rossen Stoyanchev 0bfa124a1e Remove ISE in ResourceUrlProvider
Issue: SPR-12630
2015-01-22 17:08:20 -05:00
Stephane Nicoll 3f6f6d5f70 Merge pull request #722 from mgooty/master
* pull722:
  Fix method documentation typo
2015-01-22 19:23:23 +01:00
mgooty 9b24cc5035 Fix method documentation typo
Issue: SPR-12639
2015-01-22 19:22:57 +01:00
Juergen Hoeller 8ec0da083a Upgrade to Groovy 2.4 2015-01-22 19:16:08 +01:00
Juergen Hoeller 1cd4433621 Polishing 2015-01-22 18:44:07 +01:00
Juergen Hoeller 0479ca68fe ScheduledAnnotationBeanPostProcessor registers tasks in ContextRefreshedEvent phase (again)
Issue: SPR-12641
2015-01-22 18:42:30 +01:00
Brian Clozel a4fe49e6ff Update Jetty version to 9.2.7.v20150116 2015-01-22 10:19:16 +01: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
Juergen Hoeller 49e31c302b Allow schedulerWithHsqlDataSource to pass through reducing it to the trigger table check
Issue: SPR-12618
2015-01-21 11:11:07 +01:00
Rossen Stoyanchev f949b2d3c3 Remove logging statement in ResponseBodyAdviceChain
Issue: SPR-12616
2015-01-20 17:22:51 -05:00
Rossen Stoyanchev 497944f0dd Fix minor test issues
Issue: SPR-12615
2015-01-20 17:14:20 -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
Juergen Hoeller 4141bf35b4 Latest dependency updates (Jackson 2.5, Hibernate 4.3.8, Netty 4.0.25) 2015-01-20 16:02:20 +01:00
Juergen Hoeller d34402d3ba OperatorMatches caches compiled patterns
Issue: SPR-12610
2015-01-20 16:02:11 +01:00
Juergen Hoeller 11bf3b3524 AbstractBeanDefinitionParser allows for skipping evaluation of XML "name" attribute
Issue: SPR-12643
2015-01-20 16:02:01 +01:00
Juergen Hoeller d4dac250a8 AbstractRequestLoggingFilter allows for dedicated shouldLog check in CommonsRequestLoggingFilter
Issue: SPR-12609
2015-01-20 16:01:53 +01:00
Juergen Hoeller 0ddf8dde12 AnnotationUtils explicitly handles null parameters
Issue: SPR-12604
2015-01-20 16:01:44 +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
Sebastien Deleuze bf7a9754d5 Avoid using Java 8 ZoneId class
Issue: SPR-12594
2015-01-20 15:24:55 +01:00