Commit Graph

962 Commits

Author SHA1 Message Date
Rossen Stoyanchev a2fcf0a821 ReactorNettyWebSocketSession uses correct frame size
See gh-22367
2019-03-19 15:42:06 -04:00
Sam Brannen 3e2dbd03b9 Merge branch '5.1.x' 2019-03-19 19:00:12 +01:00
Sam Brannen ef11aa4583 Update documentation for WebJar support
Prior to this commit, documentation for WebJar support referenced the
webjars-locator artifact; however, Spring now uses the
webjars-locator-core artifact.

This commit updates the documentation to reflect this.

Closes gh-22613
2019-03-19 18:59:03 +01:00
Rossen Stoyanchev e6d206b45a Extra information in WebFlux stacktraces
Use the checkpoint operator at various places in WebFlux to insert
information that Reactor then uses to enrich exceptions, via suppressed
exceptions, when error signals flow through the operator.

Closes gh-22105
2019-03-15 16:25:43 -04:00
Sebastien Deleuze 495ba2f58c Remove static import from InvocableHandlerMethod
See gh-19975
2019-03-15 19:38:14 +01:00
Sebastien Deleuze 9a81d0276e Fix checkstyle issue 2019-03-15 19:02:33 +01:00
Sebastien Deleuze 1c9cbaf399 Introduce coroutinesVersion
See gh-19975
2019-03-15 18:22:06 +01:00
Sebastien Deleuze 22cf83edba Add support for suspending handler methods in WebFlux
This commit turns Coroutines suspending methods to `Mono` which can be
handled natively by WebFlux.

See gh-19975
2019-03-15 18:21:50 +01:00
stsypanov 29f382b04e Simplify String concatenation 2019-03-14 17:24:33 +01:00
Arjen Poutsma 88ca255c95 Fix checkstyle issue 2019-03-13 11:00:07 +01:00
Rossen Stoyanchev 2d4247b2da Polish 2019-03-12 15:58:25 -04:00
Usman 9f617be909 maxFramePayloadLength property in ReactorNettyWebSocketClient
Closes gh-22367
2019-03-12 15:41:45 -04:00
Juergen Hoeller ac4c37d8e2 Merge branch '5.1.x' 2019-03-07 18:05:46 +01:00
Juergen Hoeller 6c87ef09c1 Polishing 2019-03-07 17:55:32 +01:00
stsypanov cb4d6f097c Use StringJoiner where possible to simplify String joining 2019-03-07 16:51:18 +01:00
Juergen Hoeller 5c1776ae8f Merge branch '5.1.x' 2019-03-06 16:26:00 +01:00
Juergen Hoeller b8f29962ac Upgrade to SLF4J 1.7.26, H2 1.4.198, OkHttp 3.13.1, WebJars Locator 0.37
Includes Mockito 2.25, Undertow 2.0.19, OpenPDF 1.2.10, JRuby 9.2.6.
2019-03-06 16:24:14 +01:00
Johnny Lim 625e210676 Polish 2019-02-25 12:17:53 +01:00
Juergen Hoeller 0652e4b485 Merge branch '5.1.x' 2019-02-22 14:51:00 +01:00
Juergen Hoeller c3fa900672 Upgrade to Hibernate Validator 5.4.3 and 6.0.15 2019-02-22 14:18:08 +01:00
Brian Clozel fb66619187 Merge branch '5.1.x' 2019-02-21 17:52:17 +01:00
Brian Clozel e47f7ef7b5 Remove response content-type before error handling
Prior to this commit, the negotiated content-type during the request
mapping phase would be kept as the response content-type header; this
information is used when rendering the error response and prevents a new
round of content negotiation to choose the media type that fits best.

This commit removes the response content type information at the
beginning of the error handling phase.

Fixes gh-22452
2019-02-21 17:44:03 +01:00
Sebastien Deleuze 19f792db66 Add Coroutines support for WebClient and WebFlux.fn
This commit is the first part of a more complete Coroutines
support coming in Spring Framework 5.2. It introduces suspendable
Kotlin extensions for Mono based methods in WebFlux classes like
WebClient, ServerRequest, ServerResponse as well as a Coroutines
router usable via `coRouter { }`.

Coroutines extensions use `await` prefix or `AndAwait` suffix,
and most are using names close to their Reactive counterparts,
except `exchange` in `WebClient.RequestHeadersSpec`
which translates to `awaitResponse`.

Upcoming expected changes are:
 - Leverage `Dispatchers.Unconfined` (Kotlin/kotlinx.coroutines#972)
 - Expose extensions for `Flux` based API (Kotlin/kotlinx.coroutines#254)
 - Introduce interop with `CoroutineContext` (Kotlin/kotlinx.coroutines#284)
 - Support Coroutines in `ReactiveAdapterRegistry`
 - Support Coroutines for WebFlux annotated controllers
 - Fix return type of Kotlin suspending functions (gh-21058)

See gh-19975
2019-02-18 09:23:31 +01:00
Sebastien Deleuze 1d866053ed Leverage RouterFunctions.Builder in RouterFunctionDsl
Closes gh-22423
2019-02-17 17:20:11 +01:00
Sebastien Deleuze 175c27657e Merge branch '5.1.x' 2019-02-17 10:39:15 +01:00
Ryan Scheidter 6e7c3f2893 Fix a typo in RouterFunctionDsl Javadoc
Closes gh-22419
2019-02-17 09:50:06 +01:00
Brian Clozel d463598c09 Defer ExchangeFilterFunction to subscription time
Prior to this commit, the `ExchangeFilterFunction` instances configured
on a `WebClient` instance would be executed as soon as the `exchange`
method would be called. This behavior is not consistent with the server
side and can confuse filter developers as they'd need to manually
`Mono.defer()` their implementations if they want to record metrics.

This commit defers all `ExchangeFilterFunction` processing at
subscription time.

Fixes gh-22375
2019-02-12 10:52:49 +01:00
Sebastien Deleuze 0b9522c84e Migrate Kotlin Mockito tests to Mockk
Closes gh-22345
2019-02-05 15:47:08 +01:00
Brian Clozel 862fa557bd Avoid java.util.stream.Stream usage in hot paths
Prior to this commit, profiling sessions would show that using
`java.util.stream.Stream` in some hot code paths creates significant
garbage.

Where streams aren't really required, this commit turns those snippets
into imperative logic  because those are likely to be called once or
multiple times per request.

Closes gh-22341
2019-02-05 12:14:51 +01:00
Juergen Hoeller 165d2511b9 Upgrade to Apache HttpClient 4.5.7 and Commons FileUpload 1.4
Includes RxJava 2.2.6, Netty 4.1.33, Undertow 2.0.17.
2019-02-05 00:46:07 +01:00
Juergen Hoeller c700ccbc00 Upgrade to Apache HttpClient 4.5.7
Includes Hibernate ORM 5.4.1 for integration tests.
2019-02-05 00:10:40 +01:00
Juergen Hoeller 85ec9b9df2 Avoid Class.getPackage() in favor of plain Class.getName() checks
Fixes #22306
2019-01-25 15:35:49 +01:00
Juergen Hoeller 493e9c1ff0 Consistent upgrade to Rome 1.12 and WebJars Locator 0.36 2019-01-24 15:18:43 +01:00
Brian Clozel d6aa589c50 Wrap DecodingException in DefaultServerRequest
Prior to this commit, Spring WebFlux function would let
`DecodingException` thrown by codecs bubble up to the web handler level.
Since this exception is not handled by default there, the response would
be turned into a HTTP 500 status.

In the annotation model, `ArgumentResolver` implementations wrap this
exception with a `ServerWebInputException`, which itself extends
`ResponseStatusException`. The latter is supported by the error handling
infrastructure as a HTTP 400 response.

This commit ensures that `DecodingException` instances are properly
wrapped in `ServerWebInputException` at the `ServerRequest` level
directly, thus supporting all setup modes ("standalone" and through the
`DispatcherHandler`).

Fixes #22290
2019-01-22 14:54:44 +01:00
Juergen Hoeller f56fa91430 Polishing 2019-01-08 17:11:34 +01:00
Juergen Hoeller d37a18ff03 Upgrade to Hibernate Validator 6.0.14 and Apache Johnzon 1.1.11
Includes OkHttp MockWebServer 3.12.1.
2019-01-08 00:50:44 +01:00
Rossen Stoyanchev 4b24bcb799 More accurate checks for presence of MediaType.ALL
Typically a straight up equals as well as Collections#contains
checks for MediaType.ALL is susceptible to the presence of
media type parameters.

This commits adds equalsTypeAndSubtype as well as an
isPresentIn(Collection<MimeType>) methods to MimeType to faciliate
with checks for MediaType.ALL.

Issue: SPR-17550
2019-01-02 14:32:50 -05:00
Rossen Stoyanchev 1cb9f2c7b2 Explicit HEAD sorted higher than implicit one
Same fix as #7cdcc1 but for WebFlux.

Issue: SPR-14182
2019-01-02 09:23:05 -05:00
Juergen Hoeller 8d1de75b60 Upgrade to WebJars Locator 0.36 and OkHttp 3.12.1
Includes JRuby 9.2.5 and Jetty Reactive HttpClient 1.0.2.
2018-12-25 13:22:17 +01:00
Brian Clozel 6361b0cb23 Write CharSequence instances to DataBuffers
Prior to this commit, one could write a `CharSequence` to an existing
`DataBuffer` instance by turning it into a byte array or `ByteBuffer`
first. This had the following disadvantages:

1. Memory allocation was not efficient (not leveraging pooled memory
when available)
2. Dealing with `CharsetEncoder` is not always easy
3. `DataBuffer` implementations, like `NettyDataBuffer` can use
optimized implementations in some cases

This commit adds a new `DataBuffer#write(CharSequence, Charset)` method
for those cases and also an `ensureCapacity` method useful for checking
that the current buffer has enough capacity to write to it..

Issue: SPR-17558
2018-12-20 21:33:33 +01:00
Juergen Hoeller 0e8ed5931d Revised backport version 5.0.11
Issue: SPR-17410
Issue: SPR-17433
2018-12-17 18:19:21 +01:00
Juergen Hoeller a240cfcf2f Consistent support for if-(un)modified-since as ZonedDateTime/Instant
Includes DefaultRequestBodyUriSpec pre-resolving URI for HttpRequest.

Issue: SPR-17571
2018-12-17 16:21:39 +01:00
Rossen Stoyanchev 8eef97da33 HTTP header adapters print header values
Issue: SPR-17546
2018-12-12 11:40:33 -05:00
Arjen Poutsma 058608021e Fix invalid String representation for composed RequestPredicates
Issue: SPR-17594
2018-12-12 15:33:33 +01:00
Juergen Hoeller 5bbbc82e19 Consistent handling of null header values in HttpHeaders
Issue: SPR-17588
2018-12-12 11:16:45 +01:00
Kamil Szymanski 894044cea0 Optimize ResourceUrlProvider
Closes gh-2008
2018-12-11 12:12:15 +01:00
Arjen Poutsma f15bd88211 Fix checkstyle 2018-12-07 15:06:56 +01:00
Arjen Poutsma 3258ac1ec4 Expose request in WebClientResponseException
This commit exposes the request that lead to it in
WebClientResponseException, as a HttpRequest object.

Issue: SPR-17087
2018-12-07 11:08:02 +01:00
Juergen Hoeller 6a012147c4 Consistent support for last-modified argument as Instant/ZonedDateTime
Issue: SPR-17571
2018-12-06 15:53:47 +01:00
Rossen Stoyanchev 7a5f8e03bc Refine check for multiple subscribers
Commit #c187cb2 introduced proactive rejection of multiple subscribers
in ReactorClientHttpResponse, instead of hanging indefinitely as per
https://github.com/reactor/reactor-netty/issues/503.

However FluxReceive also rejects subsequent subscribers if the response
is consumed fully, as opposed to being canceled, e.g. as with
bodyToMono(Void.class). In that case, a subsequent subscriber causes
two competing error signals to be sent, and one gets dropped and
logged by reactor-core.

This fix ensures that a rejection is raised in
ReactorClientHttpResponse only after a cancel() was detected.

Issue: SPR-17564
2018-12-04 21:27:37 -05:00
Juergen Hoeller 77ab88b144 Polishing 2018-11-23 13:56:02 +01:00
Juergen Hoeller ae8f680d2e Polishing 2018-11-22 18:21:56 +01:00
Juergen Hoeller bf272b0b21 Nullability fine-tuning based on IntelliJ IDEA 2018.3 inspection
Issue: SPR-15540
2018-11-22 16:12:38 +01:00
Juergen Hoeller b1b28d4641 ToStringVisitor consistently returns platform-independent line breaks
Issue: SPR-17322
2018-11-22 16:11:59 +01:00
Johnny Lim 17b2b8af86 Remove an unnecessary local variable 2018-11-22 13:56:22 +01:00
Rossen Stoyanchev 548126ddd8 Consistently pass param info to ServerWebInputException
Issue: SPR-17232
2018-11-21 14:41:42 -05:00
Arjen Poutsma 88cb126511 Add RequestPredicate Visitor to WebFlux.fn
This commit introduces RequestPredicates.Visitor, an implementation of
the visitor pattern for RequestPredicates.

Issue: SPR-17322
2018-11-20 14:05:17 +01:00
Rossen Stoyanchev abf9ce8a34 Improve handling of empty response with Mono<T>
Issue: SPR-17560
2018-11-19 16:48:38 -05:00
Juergen Hoeller ce5c65c0b0 Upgrade to JAXB 2.3.1, Groovy 2.5.4, Jetty 9.4.14, Tomcat 9.0.13
Includes JAX-WS 2.3.1, Awaitility 3.1.3, OkHttp 3.12, Woodstox 5.2.
2018-11-19 12:41:26 +01:00
Hanope bfb49c7249 Fix typos
See gh-2019
2018-11-19 08:41:21 +01:00
HeemangHan 729ce4108d Correct typos (#2018) 2018-11-17 16:31:01 +01:00
Rossen Stoyanchev c89e6c616a Improve logging of request mapping information
Issue: SPR-17450
2018-11-16 17:30:18 -05:00
Rossen Stoyanchev 9f857c1f16 Replace constant exceptions with inlined ones
Issue: SRP-17475
2018-11-13 14:49:23 -05:00
Juergen Hoeller 40148c0560 Consistent use of ResolvableType.toClass() for assignability checks
Issue: SPR-17086
2018-11-12 20:29:37 +01:00
Juergen Hoeller 3a66927bd2 Polishing 2018-11-12 16:43:43 +01:00
Juergen Hoeller 818c2aa3b9 ServerRequest.attribute(name) defensively accesses concurrent map
Issue: SPR-17486
2018-11-12 16:22:42 +01:00
Juergen Hoeller d96a7b4bfc ClientRequest.attribute(name) defensively handles null value
Issue: SPR-17486
2018-11-12 11:52:21 +01:00
Rossen Stoyanchev a5339d71ea WebClient handles no Content-Type with data correctly
Issue: SPR-17482
2018-11-09 16:16:03 -05:00
Rossen Stoyanchev f5da737bd4 Polish 2018-11-08 23:13:48 -05:00
Rossen Stoyanchev c187cb2fa1 Ensure client response is drained with onStatus hook
Issue: SPR-17473
2018-11-08 22:41:22 -05:00
Rossen Stoyanchev 133b8b0b5a Polish 2018-11-02 16:19:53 -04:00
Rossen Stoyanchev 48654c6483 Polish 2018-11-01 14:21:00 -04:00
Rossen Stoyanchev 9da9bb9652 Fix since tag 2018-10-31 10:56:17 -04:00
Rossen Stoyanchev 3f42e16172 Increase sharing among InvocableHandlerMethod variants
In particular between reactive and non-reactive web variants, but
also preparing for a messaing reactive variant.
2018-10-30 17:15:09 -04:00
Rossen Stoyanchev 7c36549e3a Consistent InvocableHandlerMethod implementations
This commit makes the 3 existing InvocableHandlerMethod types more
consistent and comparable with each other.

1. Use of consistent method names and method order.

2. Consistent error formatting.

3. Explicit for loops for resolving argument values in webflux variant
because that makes it more readable, creates less garabage, and it's
the only way to bring consistency since the other two variants cannot
throw exceptions inside Optional lambdas (vs webflux variant which can
wrap it in a Mono).

4. Use package private HandlerMethodArgumentComposite in webflux
variant in order to pick up the resolver argument caching that the
other two variants have.

5. Polish tests.

6. Add missing tests for messaging variant.
2018-10-30 16:36:01 -04:00
Brian Clozel fc957e95bb Configure ResourceUrlProvider in WebFlux
Prior to this commit, no `ResourceUrlProvider` was configured
in WebFlux (no bean was contributed by the WebFlux infrastructure).
Also, several `ResourceTransformer` instances that extend the
`ResourceTransformerSupport` base class need a `ResourceUrlProvider`
to resolve absolute URLs when rewriting resource URLs. At this point,
no `ResourceUrlProvider` was configured and they could only resolve
relative URLs.

This commit contributes a new `ResourceUrlProvider` to the WebFlux
configuration; this bean can be reused by the WebFlux infrastructure and
application code.

This also automatically configure this shared `ResourceUrlProvider`
instance on the resource chain where needed.

Issue: SPR-17433
2018-10-26 13:56:00 +02:00
Juergen Hoeller 3fee8cb625 Polishing 2018-10-26 11:43:46 +02:00
Vikash Tiwari 8df3fd3f1d Remove unnecessary null check 2018-10-26 10:17:04 +02:00
Brian Clozel 2146e13787 Fix absolute paths when transforming resources
Prior to this commit, `ResourceTransformerSupport.toAbsolutePath`
would call `StringUtils.applyRelativePath` in all cases. But this
implementation is prepending the given path even if the relative path
starts with `"/"`.

This commit skips the entire operation if the given path is absolute,
i.e. it starts with `"/"`.

Issue: SPR-17432
2018-10-25 16:42:47 +02:00
Rossen Stoyanchev 42b7c5a79b Upgrade to Californium snapshots
Towards Californium SR2 to confirm fix for SPR-17306.
2018-10-23 15:52:05 -04:00
Brian Clozel 28cf7b728f Relax handler supports checks in RequestMappingHandlerAdapter
Issue: SPR-17420
2018-10-22 20:31:41 +02:00
Rossen Stoyanchev 862dd23975 Server adapters release buffers on error/cancel
Review and update Servlet and Undertow adapters to release any data
buffers they be holding on to at the time of error or cancellation.

Also remove onDiscard hooks from Reactor and Undertow request body.
For Reactor we expect it to be handled. For Undertow there isn't
any Reactor Core upstream for the callback to be useful.

Issue: SPR-17410
2018-10-19 21:45:14 -04:00
Arjen Poutsma d303c8a20f Store PathPattern instead of String in attributes
This commit changes the attributes stored under
RouterFunctions.MATCHING_PATTERN_ATTRIBUTE and
HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE from a String to a
PathPattern, similar to what annotated controllers set.

Issue: SPR-17395
2018-10-18 14:48:45 +02:00
Juergen Hoeller 93bb78ec23 Avoid private bean classes in integration tests (for CGLIB on JDK 11)
Issue: SPR-16391
2018-10-15 12:26:38 +02:00
Juergen Hoeller 608fd766cb Upgrade to Checkstyle 8.13, Groovy 2.5.3, Aalto XML 1.1.1 2018-10-15 00:01:45 +02:00
Arjen Poutsma 8de5c05af0 Set BEST_MATCHING_HANDLER_ATTRIBUTE in WebFlux.fn
SPR-17367
2018-10-11 13:44:06 +02:00
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
Juergen Hoeller 053820c4ff Polishing 2018-10-09 23:14:49 +02:00
Juergen Hoeller 2b986af310 BasicAuthenticationInterceptor with HttpHeaders.setBasicAuth alignment
Issue: SPR-17326
2018-10-09 23:13:46 +02:00
dmrachkovskyi 983bce125f Defer obtaining argument resolver default value
Issue: SPR-17338
2018-10-05 11:39:19 -04: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
Rossen Stoyanchev 7481d73456 WebFlux HandshakeInfo exposes the remoteAddress
Issue: SPR-17192
2018-09-19 16:53:57 -04:00
Rossen Stoyanchev 288a9ecd18 Exposes maxFramePayloadLength for Reactor Netty
Issue: SPR-16228
2018-09-19 16:28:57 -04:00
Brian Clozel d0ada5653f Polish
See: SPR-17054
2018-09-18 11:20:33 +02:00
Arjen Poutsma 88ab911cf1 Provide matched pattern information in WebFlux fn
This commit stores the first matching path pattern in the attribute
`RouterFunctions.MATCHING_PATTERN_ATTRIBUTE`.

Issue: SPR-17098
2018-09-17 14:50:05 +02:00
Arjen Poutsma a680880a9b Restore attributes for failed AND/OR request predicates
This commit restores the attributes when either of the predicates in
an AND/OR conjunction is false.

Issue: SPR-17210
2018-09-17 10:34:52 +02:00
Rossen Stoyanchev db8e9eafb2 Add LogFormatUtils
1. Helper method to eliminate duplication in formatting (de-)serialized
   values for logging introduced with prior commit #e62298.

2. Helper method for TRACE vs DEBUG logging with different details.

Issue: SPR-17254
2018-09-14 18:06:46 -04:00
Juergen Hoeller 66c66baa8f Upgrade to Rhino 1.7.10
Includes reordering of web dependency declarations.
2018-09-14 14:03:53 +02:00
Juergen Hoeller cbc0fad961 Upgrade to Kotlin 1.2.70
Includes Hibernate ORM 5.1.16 and Hibernate Validator 6.0.13.
2018-09-13 18:23:42 +02:00
Sebastien Deleuze 48c660fa41 Add support for empty router in RouterFunctionDsl
Issue: SPR-17247
2018-09-05 16:53:59 +02:00
Sebastien Deleuze f8a0e3d084 Support RenderingResponse in RouterFunctionDsl
Issue: SPR-17244
2018-09-05 16:46:12 +02:00
Brian Clozel 482115f3ce Revert "Make DispacherServlet attributes protected"
This reverts commit 253ffd719d.
2018-08-23 16:52:16 +02:00
Brian Clozel 253ffd719d Make DispacherServlet attributes protected
Since the `initStrategies` method is there to be extended, the related
attributes should be `protected` as well.
2018-08-23 15:09:12 +02:00
Sam Brannen a8fbac8472 Polish JavaDoc
Issue: SPR-17174
2018-08-18 18:15:05 +02:00
Juergen Hoeller 6bcb454a0d Polishing 2018-08-16 19:31:10 +02:00
Juergen Hoeller 84300b796c Fix recent javadoc errors
Issue: SPR-17174
2018-08-16 18:51:31 +02:00
Brian Clozel f2506ca7a1 Revert "Infer HTTP 404 from empty Optional/Publisher types"
This reverts commit 7e91733502.
2018-08-15 15:15:35 +02:00
Brian Clozel 7e91733502 Infer HTTP 404 from empty Optional/Publisher types
This commit handles "empty" cases for `ResponseEntity` controller
handler return types when wrapped with a `java.util.Optional` in Spring
MVC or a single `Publisher` like `Mono`.

Given the following example for Spring MVC:

```
@GetMapping("/user")
public Optional<ResponseEntity<User>> fetchUser() {
	Optional<User> user = //...
	return user.map(ResponseEntity::ok);
}
```

If the resulting `Optional` is empty, Spring MVC will infer a
`ResponseEntity` with an empty body and a 404 HTTP response status.

The same reasoning is applied to Spring WebFlux with Publisher types:

```
@GetMapping("/user")
public Mono<ResponseEntity<User>> fetchUser() {
	Mono<User> user = //...
	return user.map(ResponseEntity::ok);
}
```

This feature is only valid for `HttpEntity` return types and does not
apply to `@ResponseBody` controller handlers.

Issue: SPR-13281
2018-08-15 11:59:16 +02:00
Juergen Hoeller de38af6843 Upgrade to JUnit Jupiter 5.3 RC1 (and Jetty 9.4.12 RC1)
Includes Groovy 2.5.2, Undertow 2.0.12, Hibernate Validator 6.0.12.

Issue: SPR-17129
2018-08-14 20:33:30 +02:00
Sam Brannen 8126ffbc8c Fix broken links in JavaDoc
Issue: SPR-17174
2018-08-13 12:22:52 +02:00
Sam Brannen cfb1ed1009 Clean up warnings and delete dead code 2018-08-12 15:55:11 +02:00
Rossen Stoyanchev aef39e8954 Remove test class added by mistake 2018-08-10 16:57:46 +03:00
Rossen Stoyanchev 61c52d64c5 Polish ConcurrentWebSocketSessionDecoratorTests 2018-08-10 16:15:21 +03:00
Sebastien Deleuze 6b6384a09e Improve WebFlux Protobuf support
- Update javadoc for decoding default instances
 - Refactor and simplify tests
 - Add missing tests
 - Refactor decoding with flatMapIterable instead of
   concatMap and avoid recursive call

Issue: SPR-15776
2018-08-09 15:47:45 +02:00
Juergen Hoeller 58e9706991 Polishing 2018-08-09 02:26:36 +02:00
Juergen Hoeller 247ec572b2 Consistent hasAnnotation check for findMergedAnnotation lookup
Issue: SPR-16933
2018-08-08 23:54:56 +02:00
Rossen Stoyanchev a0dfdfcac3 Hierarchy under WebClientResponseException
Issue: SPR-17145
2018-08-08 15:34:08 +03:00
Sebastien Deleuze 7e9b7102b7 Support custom CorsConfigurationSource in AbstractHandlerMapping
This commit allows to specify a custom CorsConfigurationSource
in AbstractHandlerMapping (both Servlet and Reactive variants).

AbstractHandlerMapping#getCorsConfigurations method is now
deprecated.

Issue: SPR-17067
2018-08-08 10:08:55 +02:00
Juergen Hoeller 34ddb88851 ConcurrentModel.addAttribute(String, Object) ignores null value
Issue: SPR-17141
2018-08-07 20:35:34 +02:00
Rossen Stoyanchev 4a18488f30 Update deprecated basic auth client filters.
1. Update ExchangeFilterFunctions to delegate internally to
HttpHeaders.setBasicAuth(user, password).

2. Remove deprecation from
ExchangeFilterFunctions.basicAuthentication(String user, String password)
It is still useful as a filter to insert the header.

3. Update deprecation notes.

Issue: SPR-17099
2018-08-07 10:10:27 +03:00
Juergen Hoeller 943b394992 Polishing 2018-08-06 18:34:00 +02:00
Sebastien Deleuze 2054fa2191 Upgrade to Jetty reactive HTTP client 1.0.1
Issue: SPR-17124
2018-08-06 12:01:29 +02:00
Juergen Hoeller 821ab62492 Upgrade to RxJava 2.2 and Kotlin 1.2.60
Includes latest dependency updates (Mockito 2.21, Log4J 2.11.1, Hibernate ORM 5.3.4, Protobuf 3.6.1, JRuby 9.2, HtmlUnit 2.32, Selenium 3.14) for Spring Framework 5.1.

Issue: SPR-16388
Issue: SPR-16239
2018-08-03 23:18:10 +02:00
Rossen Stoyanchev a8a1fc6de5 Earlier processing of forwarded headers
Forwarded headers are now processed before ServerWebExchange is created
through ForwardedHeaderTransformer which has the same logic as the
ForwardedHeaderFilter but works on the request only.

ForwardedHeaderFilter is deprecated as of 5.1 but if registered it is
removed from the list of filters and ForwardedHeaderTransformer is used
instead.

Issue: SPR-17072
2018-08-03 15:16:09 +03:00
Rossen Stoyanchev aec98268fe maxResponseBody client filter
Issue: SPR-16989
2018-08-02 21:19:22 +03:00
Juergen Hoeller 217aa38cbb Polishing 2018-08-02 18:00:42 +02:00
Juergen Hoeller 2474c48749 Polishing 2018-08-02 16:55:53 +02:00
stsypanov b5c691bdac SPR-17074 Replace pointless wrapping with Arrays.asList with iteration over array 2018-08-02 12:07:00 +02:00
Juergen Hoeller 589b7048ec Avoid synthesizable annotation creation for @Bean/@Scope processing
Includes consistent (non-)use of AnnotationUtils/AnnotatedElementUtils.

Issue: SPR-16933
2018-08-01 11:43:28 +02:00
Сергей Цыпанов f8340838b3 Use lambda expressions for lazy instantiation (#1911)
Issue: SPR-17074
2018-07-31 13:03:18 +02:00
Juergen Hoeller 4a147d26fc Initialize pre-filled HashMaps with large enough capacity
Empty Maps are preferably initialized without capacity (not initializing them at all or lazily initializing with default capacity when needed).

Issue: SPR-17105
2018-07-30 22:07:31 +02:00
Rossen Stoyanchev 91d17cf628 Add notes on future deprecation of the RestTemplate
Issue: SPR-16993
2018-07-27 08:41:20 -04:00
Rossen Stoyanchev f5ff1dc3f9 Comment on difference in matrix variable test
Based on discussion under
https://github.com/spring-projects/spring-framework/pull/1901
2018-07-27 08:40:36 -04:00
Juergen Hoeller 2b2bf27933 Polishing 2018-07-25 15:26:52 +02:00
Juergen Hoeller 3881a4aded Polishing 2018-07-25 14:16:02 +02:00
Juergen Hoeller fd8e4abe5d Introduce ResolvableType.toClass() shortcut
Issue: SPR-17086
2018-07-25 14:15:19 +02:00
Sebastien Deleuze d3b244a81b Optimize class detection by sharing the ClassLoader
Issue: SPR-17083
2018-07-25 11:09:42 +02:00
Rossen Stoyanchev 32faf09a80 Add check for mixing @EnableWebMvc and @EnableWebFlux
Issue: SPR-16609
2018-07-24 20:47:26 -04:00
Rossen Stoyanchev 0be8c20fca Consistent logging of selected media types 2018-07-24 20:47:26 -04:00
sdeleuze 36a07aa897 Support Protobuf serialization in WebFlux
This commit introduces Protobuf support in WebFlux via dedicated
codecs.

Flux<Message> are serialized/deserialized using delimited Protobuf
messages with the size of each message specified before the message
itself. In that case, a "delimited=true" parameter is added to the
content type.

Mono<Message> are expected to use regular Protobuf message
format (without the size prepended before the message).

Related HttpMessageReader/Writer are automatically registered when the
"com.google.protobuf:protobuf-java" library is detected in the classpath,
and can be customized easily if needed via CodecConfigurer, for example
to specify protocol extensions via the ExtensionRegistry based
constructors.

Both "application/x-protobuf" and "application/octet-stream" mime types
are supported.

Issue: SPR-15776
2018-07-25 01:17:06 +02:00
Brian Clozel 195f3f07e7 ResponseEntityResultHandler overwrites headers
Prior to this commit, controller handlers (regular and exception
handlers as well) would not overwrite existing HTTP response headers on
the exchange. This would lead to situations where Content-Type values
set during the initial handling phase would not be overwritten when
handling an error later on.

This commit aligns the implementation of that result handler on the
Spring MVC one in that regard.

Issue: SPR-17082
2018-07-24 22:21:30 +02:00
Juergen Hoeller 11881ff211 Polishing 2018-07-24 18:45:52 +02:00
Juergen Hoeller dd4468a74a Polishing 2018-07-24 16:16:52 +02:00
Juergen Hoeller 3c65c17053 Correctly determine and propagate validation hints to DataBinder
Issue: SPR-17073
2018-07-21 12:19:37 +02:00
Juergen Hoeller 9a43d2ec20 Revised log levels: less WARN and INFO, fine-tuned DEBUG vs TRACE
Issue: SPR-16946
2018-07-20 15:05:16 +02:00
Brian Clozel a410d90439 Drain client response body consistenly
Prior to this commit, the `DefaultClientResponse` implementation would
handle HTTP client cases where the server response body would need to be
consumed (pooled resources need to be released) and the body publisher
cancelled right away. This is done to avoid reading the whole response
body and returning the connection to the pool, now that this connection
cannot be reused.

This was done already when the `WebClient` is asked for a `Void` type
for the response body.

SPR-17054 brought a new case for that: whenever no message reader is
able to decode the response body, an `UnsupportedMediaTypeException`
error signal is sent. Prior to this commit, the response body would not
be consumed and cancelled for that case.

This commit refactors all those cases from the `DefaultClientResponse`
directly into the `BodyExtractors`, since most of the logic and
knowledge for that belongs there. We only need to only apply this
behavior when the HTTP client is involved, as the server does not want
this to happen.

Issue: SPR-17054
2018-07-20 14:01:34 +02:00
Juergen Hoeller 867b3d233d Upgrade to OkHttp 3.11, Apache HttpClient 4.5.6, Hibernate Validator 6.0.11 2018-07-19 17:52:08 +02:00
Rossen Stoyanchev 66d73017d5 PathVariable consistently reflects value up to 1st ";"
Given "/{foo}" and "/a=42;c=b", previously that would be treated as a
sequence of matrix vars with an empty path variable. After the change
the path variable "foo" is "a=42".

This should be ok for backawards compatibility since it's unlikely for
anything to rely on an empty path variable.

Issue: SPR-11897
2018-07-18 22:14:02 -04:00
sdeleuze a87764f1fd Add support for Jetty Reactive Streams HTTP client
Leverage https://github.com/jetty-project/jetty-reactive-httpclient
to add support for Jetty in WebClient via JettyClientHttpConnector.

Implemented with buffer copy instead of optimized buffer wrapping
because the latter hangs since Callback#succeeded doesn't allow
releasing the buffer and requesting more data at different times
(required for Mono<DataBuffer> for example).
See https://github.com/eclipse/jetty.project/issues/2429.

Issue: SPR-15092
2018-07-18 14:49:49 +02:00
Sebastien Deleuze 3c9049d530 Leverage Jetty BOM
Issue: SPR-17058
2018-07-18 14:49:49 +02:00
Brian Clozel a7f97a1669 Avoid null signals when resolving handler arguments
Prior to this commit, resolving an argument for a WebFlux controller
that's missing from the request and not required by the handler would
throw a NullPointerException in some cases.

This involves the conversion of the parameter (a `String` parameter type
might not trigger this behavior) and sending a `null` within a reactive
stream, which is illegal per the RS spec.

We now rely on a `Mono.justOrEmpty()` to handle those specific cases.

Issue: SPR-17050
2018-07-18 14:41:43 +02:00
Brian Clozel 75fa9c4266 Fix checkstyle issues 2018-07-12 21:54:32 +02:00
Brian Clozel 038af9a303 Improve unknown status codes handling by WebClient
Prior to this commit, `WebClient` would throw `IllegalArgumentException`
when receiving an HTTP response with an unknown HTTP status code.

This commit is a follow up of SPR-16748 (supporting non-standard HTTP
status codes on the reactive `ClientHttpResponse`), and is mirroring
SPR-15978 (supporting non-standard HTTP status codes in `RestTemplate`).

With this change, `WebClient` now tolerates unknown status codes in some
cases, while not offering that choice as a first class citizen:
`HttpStatus` is still the preferred way to deal with HTTP status codes.

Here's how `WebClient` will behave when fetching the full response:

```
// Given a remote endpoint returning a "123" HTTP status code
Mono<ClientResponse> result = this.webClient.get()
				.uri("/status/123")
				.exchange();

// will still throw an IllegalArgumentException
HttpStatus status = result.block().statusCode();

// is safe and will return 123
int statusCode = result.block().rawStatusCode();
```

Resolving directly the response body with `retrieve()` is different.

```
// will send an error signal with a UnknownHttpStatusCodeException
Mono<String> result = this.webClient.get()
				.uri("/status/123")
				.retrieve()
				.bodyToMono(String.class);
```

In general, `WebClient` will provide high-level support
for well-known HTTP status codes, like error handling with
`WebClient.ResponseSpec#onStatus`.

For such support with unknown status codes, it is better to rely
on lower level constructs such as `ExchangeFilterFunction`.

Issue: SPR-16819
2018-07-12 19:08:08 +02:00
Rossen Stoyanchev 1b1bc7f5b5 Switch defaults and model for logging sensitive data
Issue: SPR-17029
2018-07-11 11:10:03 -04:00
xiexed d5df097e0e Small typo fixes in WebSocketHandler doc 2018-07-09 14:27:23 -04:00
Arjen Poutsma a663454fad Changed Basic Authentication consumer to setBasicAuth method
This commit changes the Basic Authentication Consumer<HttpHeaders> to
a basic setBasicAuth(String, String) method.

Issue: SPR-16913
2018-07-09 16:41:51 +02:00
Rossen Stoyanchev 2874dd75ca Fine-tune WebFlux logging at HTTP/WebSocket level
1. Use special category prefix "spring-web.reactivestreams" for logging
of reactive streams signals in spring-web, since those are quite
verbose would fill the logs at TRACE.

2. Add and use loggers in request and websocket session implementations
separate from reactive streams bridge for regular TRACE logging.

3. Improve log messages and add where missing (e.g. for Reactor)

Issue: SPR-16898
2018-07-06 17:33:16 -04:00
Rossen Stoyanchev bc3cf0eeb8 Expose request id at the ServerHttpRequest level
Hiding it (at AbstractServerHttpRequest) complicates matters since
requests are often mutated and decorated, plus it's also possible to
implement the interface directly (we've one, albeit corner case).

Issue: SPR-16966
2018-07-06 15:44:24 -04:00
Rossen Stoyanchev 5dc49b16ea Correlated messages at HTTP adapter + WebSocket level
Issue: SPR-16966
2018-07-06 15:44:18 -04:00
Rossen Stoyanchev 7be2943c03 Simplify WebSocket client implementationss in WebFlux
1. Eliminate WebSocketClientSupport base class whose main value was
to provide logging but those methods get in the way of inserting a
log prefix.

2. Remove checks and synchronization in lifecycle methods of Jetty
client since underlying Jetty client already has that.
2018-07-06 15:17:11 -04:00
Sebastien Deleuze fd69c90fcb Add ServerResponse extensions for json, xml and html
Issue: SPR-17017
2018-07-06 14:52:11 +02:00
Juergen Hoeller 2cd006923c Polishing 2018-07-06 14:38:29 +02:00
Sebastien Deleuze c0264072ab Avoid ServerResponse static imports in WebFlux router DSL
Provide functions like ok() in RouterFunctionDsl to avoid
ServerResponse static imports.

Issue: SPR-17009
2018-07-06 13:50:27 +02:00
Arjen Poutsma 37a3765a4e Fix checkstyle errors 2018-07-06 13:38:17 +02:00
Arjen Poutsma 490302ebf8 Added RequestPredicates.methods(HttpMethod...)
Added a predicate that tests for multiple HTTP methods.
2018-07-06 12:01:16 +02:00
Arjen Poutsma 91e96d8084 Improve RouterFunction builder
This commit improves the RouterFunctions.Builder based on conversations
had during the weekly team meeting.

Issue: SPR-16953
2018-07-06 12:01:08 +02:00
Rossen Stoyanchev 5cdc26770e Correlated WebClient log messages
Issue: SPR-16966
2018-07-05 08:30:23 -04:00
Rossen Stoyanchev 82310660fd Correlated encoding/decoding log messages via hints
Issue: SPR-16966
2018-07-05 08:28:15 -04:00
Rossen Stoyanchev fd90b73748 Correlated WebFlux server log messages
Issue: SPR-16966
2018-07-05 08:27:13 -04:00
Rossen Stoyanchev 8bffb6a798 Add defaultRequest option to WebClient.Builder
Issue: SPR-16873
2018-07-03 12:44:29 -04:00
Rossen Stoyanchev da5b705328 Polish default headers/attributes in WebClient 2018-07-03 12:44:29 -04:00
Rossen Stoyanchev 907a306ee2 Fix locally failing test in FlushingIntegrationTests 2018-06-29 18:15:52 -03:00
Juergen Hoeller e22466e9d5 Polishing 2018-06-29 19:44:15 +02:00
Juergen Hoeller df6b01a329 Remove deprecated classes and methods from early 5.0.x phase 2018-06-29 19:44:08 +02:00
Juergen Hoeller d34e6f7f70 Polishing 2018-06-28 18:02:07 +02:00
Juergen Hoeller 8ad5299f4a Polishing 2018-06-28 17:12:29 +02:00
Juergen Hoeller 40efcc933c Polishing 2018-06-28 14:51:33 +02:00
Arjen Poutsma 794693525f Polishing 2018-06-28 14:09:34 +02:00
Arjen Poutsma a691065d05 Polishing 2018-06-28 11:27:30 +02:00
Arjen Poutsma 8202052b38 Introduce RouterFunction builder
This commit introduces RouterFunctions.Builder, a new way to build
router functions that does not require static imports, thus being more
discoverable and convenient.

Issue: SPR-16953
2018-06-28 11:23:38 +02:00
Phillip Webb a89e716cc7 Use tabs rather than spaces in tests
Update tests to ensure that tabs are used instead of spaces. Also
consistently apply a new line at the end of each file.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 1c25cec44f Polish test code
Polish a few issue identified when adding checkstyle to the
build. Although checkstyle is not enforcing rules on tests,
these are a few minor changes that are still worth making.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 81451aa800 Organize imports
Reorganize imports to ensure consistent ordering. This commit also
expands any `.*` static imports in favor of using fully-qualified
method references.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb b220d94cc2 Never use parenthesis for single lambda arguments
Update all lambdas that take a single argument so that parenthesis
are never used.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 5cedd0d5d4 Consistently use tabs rather than spaces
Update code that has accidentally used spaces instead of tabs.
Also remove all trailing whitespace.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 0b53c1096a Always use 'this.' when accessing fields
Ensure that `this.` is used consistently when accessing class
fields.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb eeebd51f57 Use consistent class design
Update all classes so that inner classes are always last. Also
ensure that utility classes are always final and have a private
constructor and make exceptions final whenever possible.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb 0ad0f341bd Don't use single letter catch variables
Update existing catch blocks to ensure that `ex` is always used
in preference to `e` or `t` as the variable name.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb e9d1b39aff Apply consistent copyright header
Add copyright header to `package-info.java` files and fix a few
malformed headers on existing java files.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb c3a17dfd47 Ensure all files end with a newline
Update all files to ensure that they always end with a new line.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Phillip Webb e0480f75ac Fix javadoc checkstyle issues
Fix checkstyle violations for javadoc.

Issue: SPR-16968
2018-06-28 10:28:44 +02:00
Napster 8aa6e5bfea Undertow WebSocket sessions use shared ByteBufferPool
Issues: SPR-16957
2018-06-25 17:46:25 -03:00
Rossen Stoyanchev 7ccd2b024d Refine logging for async requests
Issue: SPR-16898
2018-06-25 14:42:29 -03:00
Rossen Stoyanchev 900bc8a2e3 Logging improvements for WebFlux
Issue: SPR-16898
2018-06-22 22:44:24 -04:00
Brian Clozel 4a26f93a0d WebClient writes Content-Length for Mono bodies
In SPR-16892, the `EncoderHttpMessageWriter` has been improved to write
`"Content-Length"` HTTP response headers if the response body is of type
`Mono` (i.e. the actual content length is easily accessible without
buffering a possibly large response body). That change was relying on
the fact that the server side is using a `ChannelSendOperator` to delay
the writing of the body until the first signal is received.

This strategy is not effective on the client side, since no such channel
operator is used for `WebClient`. This commit improves
`EncoderHttpMessageWriter` and delays, for `Mono` HTTP message bodies
only, the writing of the body so that we can write the
`"Content-Length"` header information once we've got the body resolved.

Issue: SPR-16949
2018-06-19 11:51:45 +02:00
Rossen Stoyanchev 03c305136d Fix failing tests 2018-06-18 20:20:32 -04:00