Commit Graph

17348 Commits

Author SHA1 Message Date
Brian Clozel ce7278aaf4 Optimize HTTP headers management
Several benchmarks underlined a few hotspots for CPU and GC pressure in
the Spring Framework codebase:

1. `org.springframework.util.MimeType.<init>(String, String, Map)`
2. `org.springframework.util.LinkedCaseInsensitiveMap.convertKey(String)`

Both are linked with HTTP request headers parsing and response headers
writin during the exchange processing phase.

1) is linked to repeated calls to `HttpHeaders.getContentType`
within a single request handling. The media type parsing operation
is expensive and the result doesn't change between calls, since
the request headers are immutable at that point.

This commit improves this by caching the parsed `MediaType` for the
`"Content-Type"` request header in the `ReadOnlyHttpHeaders` class.
This change is available for both Spring MVC and Spring WebFlux.

2) is linked to insertions/lookups in the `LinkedCaseInsensitiveMap`,
which is the data structure behind `HttpHeaders`.
Those operations are creating a lot of garbage (including a lot of
`String` created by `toLowerCase`). We could choose a more efficient
data structure for storing HTTP headers data.

As a first step, this commit is focusing on Spring WebFlux and
introduces `MultiValueMap` implementations mapped by native HTTP headers
for the following servers: Tomcat, Jetty, Netty and Undertow.
Such implementations avoid unnecessary copying of the headers
and leverages as much as possible optimized operations provided by the
native implementations.

This change has a few consequences:

* `HttpHeaders` can now wrap a `MultiValueMap` directly
* The default constructor of `HttpHeaders` is still backed by a
`LinkedCaseInsensitiveMap`
* The HTTP request headers for the websocket HTTP handshake now need to
be cloned, because native headers are likely to be pooled/recycled by
the server implementation, hence gone when the initial HTTP exchange is
done

Issue: SPR-17250
2018-10-11 12:11:47 +02:00
volkovandr 61403e3bd3 Updated Javadoc: date format patterns SPR-17366 2018-10-11 10:52:32 +02:00
Brian Clozel cc172bcedc Upgrade to Reactor Californium SNAPSHOTs
Preparing for Californium-SR1
2018-10-11 10:46:01 +02:00
Juergen Hoeller e18149878c Upgrade to Mockito 2.23
Includes JSON-P 1.1.3.
2018-10-10 23:53:33 +02:00
Juergen Hoeller c89e3e6e0d Restore original factory method caching (addressing Boot regressions)
Issue: SPR-17358
2018-10-10 23:53:13 +02:00
Rossen Stoyanchev d05924165b Refactor FilterWebHandler and DefaultWebFilterChain
The chain is initialized once and re-used vs creating the "next" chains
on every request.
2018-10-10 14:33:51 -04:00
Stephane Nicoll 82a211fa96 Fix checkstyle violation 2018-10-10 10:45:08 +02:00
Stephane Nicoll 062805fcb3 Recursively process DeferredImportSelector properly
Previously, if a DeferredImportSelector was identified at a later stage
as part of processing the collected set of deferred imports, such
selector was processed as a regular import selector.

Semantically, it makes sense as we already are in the deferred phase at
this point and it doesn't make much sense to bother about the extra
contract.

However, Spring Framework 5 introduced the notion of Group that a
deferred import selector can define. When it does, the container has to
honour the contract of the Group rather than calling the simpler
ImportSelector parent contract.

This commit restructures the processing of such case. When a deferred
import selector is detected while processing deferred import selectors,
a group is created with only that selector and the group API is invoked.

Issue: SPR-17351
2018-10-10 10:19:11 +02:00
Juergen Hoeller 053820c4ff Polishing 2018-10-09 23:14:49 +02:00
Juergen Hoeller f662e3b85e BeanFactoryAnnotationUtils provides qualifiedBeansOfType method
Includes consistent upfront resolution of factory method annotations.

Issue: SPR-8891
2018-10-09 23:14:27 +02:00
Juergen Hoeller 44afed426a ObjectProvider stream consistently includes beans from parent context
Issue: SPR-17356
2018-10-09 23:14:19 +02:00
Juergen Hoeller 83909e6e1e Consistent exposure of empty attribute arrays in AnnotationMetadata
Issue: SPR-17347
2018-10-09 23:14:13 +02:00
Juergen Hoeller fdf340306d Defensively use Class.forName instead of ClassLoader.loadClass
Issue: SPR-17333
2018-10-09 23:14:05 +02:00
Juergen Hoeller d9e7253532 SpringBeanContainer exposes bean instance returned from initializeBean
Issue: SPR-17332
2018-10-09 23:13:58 +02:00
Juergen Hoeller 2b986af310 BasicAuthenticationInterceptor with HttpHeaders.setBasicAuth alignment
Issue: SPR-17326
2018-10-09 23:13:46 +02:00
Juergen Hoeller c8c0737ce7 AbstractApplicationContext.getApplicationListeners() exposes all statically registered listeners
Issue: SPR-17324
2018-10-09 23:13:37 +02:00
Juergen Hoeller 19f3347932 SpringBeanJobFactory supports autowiring through ApplicationContext
Issue: SPR-17323
2018-10-09 23:13:25 +02:00
Juergen Hoeller efdbddd358 Full alignment of spring-test vs spring-web MockCookie variants
Issue: SPR-17321
2018-10-09 23:13:18 +02:00
Juergen Hoeller cf3635b42d Resource.lastModified() propagates 0 value if target resource exists
Includes use of Files.getLastModifiedTime for NIO Paths, preservation of NIO-based resolution on createRelative, deprecation of PathResource, and consistent use of getContentLengthLong over getContentLength.

Issue: SPR-17320
2018-10-09 23:13:11 +02:00
Juergen Hoeller 1e0de072f9 Upgrade to ASM 7.0 beta release
Issue: SPR-17267
2018-10-09 23:13:02 +02:00
Rossen Stoyanchev bb5c8ed4e8 Correct Javadoc in ServletUriComponentsBuilder
Replace all method level comments related to forwaded headers, some
current and some outdated, with a single class-level comment.

Issue: SPR-17317
2018-10-09 16:51:41 -04:00
Rossen Stoyanchev c01f350abe Move MonoToListenableFutureAdapter to spring-core
This was a package private class in spring-messaging since 5.0, and was
recently made public in 5.1. This commit promotes it to spring-core
where it belongs next to all other ListenableFuture support classes.

Follow-up refactoring for SPR-17336
2018-10-09 16:26:24 -04:00
Rossen Stoyanchev 928c541401 Simplify MonoToListenableFutureAdapter
Collapse the package private AbstractMonoToListenableFutureAdapter into
its only sub-class MonoToListenableFutureAdapter. There is no need for
such an abstract class that makes it possible to adapt from one source
to a different target type. That's already covered by
ListenableFutureAdapter.

Follow-up refactoring for SPR-17336.
2018-10-09 15:22:19 -04:00
Rossen Stoyanchev bef22ec9b5 Consistent MonoToListenableFutureAdapter.cancel()
Issue: SPR-17336
2018-10-09 14:55:04 -04:00
Rossen Stoyanchev 29ff8a8d12 More defensive check for MockAsyncContext
Avoid automatically unwrapping the request in TestDispatcherServlet,
if we find the MockAsyncContext.

Issue: SPR-17353
2018-10-09 11:56:47 -04:00
Sebastien Deleuze af6a5566a3 Replace context by provider<T>() in Kotlin bean DSL
Spring Framework 5.1.0 exposed by mistake context in the Kotlin bean DSL
API in order to fix SPR-16269. Now that BeanFactory#getBeanprovider is
available, it should be exposed via a provider<Foo>() function in order
to provide a more clean API instead.

Issue: SPR-17352
2018-10-08 14:00:12 +02:00
Stephane Nicoll 635d2146db Merge pull request #1983 from nfadeev
* pr/1983:
  Fix bullet list layout
2018-10-07 13:46:13 +02:00
Mykola Fadieiev ccce61e2b2 Fix bullet list layout
Closes gh-1983
2018-10-07 13:45:46 +02:00
Rossen Stoyanchev 9630445253 Add sections on form and multipart codecs
Explain the need for consistent use of ServerWebExchange for access to
the parsed (and cached) form data or multipart data.

Issue: SPR-17291
2018-10-05 21:27:07 -04:00
Rossen Stoyanchev 1c90d481d5 Rename Motivation to Overview and restore sub-sections 2018-10-05 16:37:56 -04:00
Rossen Stoyanchev d16a710d13 Polish WebFlux codecs section in the docs 2018-10-05 16:36:19 -04:00
Rossen Stoyanchev 4d24503317 Restore sub-section headings in web content
Headings are optimized for how they appear in the left-hand side
navitation menu, with context provided by parent headings, and not
necessarily for how they read on their own.

At 2nd and 3rd level of nesting, which is where most headings are,
the wrapping becomes too distracting and the left-hand side navigation
sprawling.
2018-10-05 15:54:38 -04:00
Rossen Stoyanchev 1489457025 Restore calls to setLocale in MockHttpServletResponse
Issue: SPR-17284
2018-10-05 13:50:41 -04:00
Rossen Stoyanchev 9064ef59f9 Workaround for Synchronoss content-length limitation
Issue: SPR-17345
2018-10-05 12:12:49 -04:00
dmrachkovskyi 983bce125f Defer obtaining argument resolver default value
Issue: SPR-17338
2018-10-05 11:39:19 -04:00
Sam Hubbard 80e7819d6f Fix construction of NullSafeComparator in nullsLow
Previously, both nullsLow(Comparator<T>) and
nullsHigh(Comparator<T>) returned a
NullSafeComparator which treated nulls as being
high. This commit corrects this typo.
2018-10-05 13:20:28 +02:00
Stephane Nicoll cb4fa3795a Merge pull request #1979 from rupertw
* pr/1979:
  Fix formatting
2018-10-05 09:21:23 +02:00
www 9d5aced8c5 Fix formatting
Prefix the opening brace with a single space in some classes.
Replace tab character with space in javadoc of AttributeAccessor.
Also fix some other trivial formatting errors.

Closes gh-1979
2018-10-05 09:20:47 +02:00
Arjen Poutsma ff7ccf0d4e Only clear request attribute when different
With this commit, we now make sure that the attributes are not cleared
if they are same as the nested request.

Issue: SPR-17304
2018-10-04 16:50:11 +02:00
Arjen Poutsma 9975646ffb Add more RequestPredicate tests for attributes
This commit adds test for delegating request predicates that verify
whether the request attributes are properly restored when a delegate
fails.
2018-10-04 15:18:08 +02:00
Arjen Poutsma 38e5c01c3c Move negating RequestPredicate to RequestPredicates 2018-10-04 15:15:36 +02:00
Sebastien Deleuze 3ff5731429 Leverage ObjectProvider instead of autowired containers
In order to be able to leverage WebFlux configuration in a functional
way, WebHttpHandlerBuilder and RouterFunctionMapping should leverage
new ObjectProvider capabilities to get a sorted list of beans by type
instead of using autowired containers.

Issue: SPR-17327
2018-10-03 14:14:47 +02:00
Rossen Stoyanchev 1320fed7fe Use WebsocketOutbound#sendClose
Switch to using the sendClose method available since Reactor Netty 0.8
vs explicitly sending a CloseWebSocketFrame.

Related to SPR-17306, but does not address the root cause.
2018-10-02 09:37:32 -04:00
Sam Brannen e63bffcfa0 Introduce not-null precondition for MockCookie parsing 2018-10-02 13:07:20 +02:00
Sam Brannen 77205ca165 Polish MockCookie contribution
Issue: SPR-17321, #1974
2018-10-02 13:06:16 +02:00
Sam Brannen 31095f1d4e Move MockCookie parsing tests to correct class
Issue: SPR-17321, #1974
2018-10-02 12:43:17 +02:00
Sam Brannen 49bc746640 Polish MockCookie[Tests] 2018-10-02 12:41:07 +02:00
Michael Bell 1b8421c7fe Fix MockCookie parsing when attribute is omitted
Issue: SPR-17321, #1974
2018-10-02 06:18:45 -04:00
0xflotus 00353a073c fixed further typo 2018-10-01 21:48:49 +02:00
0xflotus 9fed4d0375 do you mean 'compose'? 2018-10-01 21:48:02 +02:00