Commit Graph

1700 Commits

Author SHA1 Message Date
Sam Brannen 3dc84c2d92 Merge branch '5.3.x' 2021-09-28 11:48:50 +02:00
Sam Brannen bfdc99ab79 Fix Javadoc errors
See gh-27480
2021-09-28 11:44:12 +02:00
Sam Brannen 16bf39ea1b Merge branch '5.3.x' 2021-09-28 10:35:18 +02:00
Sam Brannen 2567b20949 Upgrade to spring-javaformat 0.0.28 and downgrade to Checkstyle 8.41
In order to be able to use text blocks and other new Java language
features, we are upgrading to a recent version of Checkstyle.

The latest version of spring-javaformat-checkstyle (0.0.28) is built
against Checkstyle 8.32 which does not include support for language
features such as text blocks. Support for text blocks was added in
Checkstyle 8.36.

In addition, there is a binary compatibility issue between
spring-javaformat-checkstyle 0.0.28 and Checkstyle 8.42. Thus we cannot
use Checkstyle 8.42 or higher.

In this commit, we therefore upgrade to spring-javaformat-checkstyle
0.0.28 and downgrade to Checkstyle 8.41.

This change is being applied to `5.3.x` as well as `main` in order to
benefit from the enhanced checking provided in more recent versions of
Checkstyle.

Closes gh-27481
2021-09-28 10:29:31 +02:00
Rossen Stoyanchev 01426481ea Enforce timeout in WebFlux multipart tests 2021-09-17 14:53:45 +01:00
Rossen Stoyanchev 513cc1576e Fix Jetty WebSocket test failures for WebFlux
See gh-27424
2021-09-17 14:53:17 +01:00
Juergen Hoeller d84ca2ba90 Jakarta EE 9 migration
Upgrades many dependency declarations; removes old EJB 2.x support and outdated Servlet-based integrations (Commons FileUpload, FreeMarker JSP support, Tiles).

Closes gh-22093
Closes gh-25354
Closes gh-26185
Closes gh-27423
See gh-27424
2021-09-17 09:14:07 +02:00
Rossen Stoyanchev caf88ff2cc Improve HandlerMethod#bridgedMethod initialization
Ensure makeAccessible is called once when the bridgedMethod is
initialized.

Closes gh-19795
2021-09-14 14:58:11 +01:00
Phillip Webb 52b03e3326 Migrate CoroutinesUtils to Java
Migrate `CoroutinesUtils` from Kotlin code to Java and drop the
`kotlin-coroutines` module.

This update removes the need for Kotlin tooling IDE plugins to be
installed.

Closes gh-27379
2021-09-13 17:39:45 +02:00
Mustafa Ulu db424d0bc5 Replace word "request" with "response" 2021-09-13 11:35:21 +01:00
Mustafa Ulu a087d13aea Fix wording in Javadoc of ClientResponse.mutate()
Removed an extra "the".
2021-09-13 11:35:21 +01:00
Brian Clozel cecc0849a8 Upgrade to Gradle 7.2
This commit upgrades Gradle to 7.2.
Gradle configuration names are updated accordingly.
This also upgrades Gradle build plugins.

See gh-26870
2021-09-13 09:37:35 +02:00
Rossen Stoyanchev b6037d0d07 Correctly format class name in default package
Closes gh-27247
2021-09-10 10:38:48 +01:00
Sam Brannen 9f7a94058a Update copyright date
See gh-27298
2021-08-19 16:23:38 +02:00
LEE Juchan caf6760ddd
Fix grammatical errors in Javadoc
Closes gh-27298
2021-08-19 16:21:15 +02:00
Sanghyuk Jung ac72277258 Fix duplicate "the" in Javadoc and XSD
See gh-27291
2021-08-19 08:44:03 +02:00
Rossen Stoyanchev ce6217be85 Polishing contribution
Closes gh-27220
2021-08-04 10:32:16 +01:00
Alexej Timonin e290ae285c Improve Javadoc for ClientRequest#from
See gh-27220
2021-08-04 09:21:43 +01:00
Rossen Stoyanchev bb816c123c Use MessageSource in HandlerMethod for error reason
Closes gh-27156
2021-07-13 19:38:58 +01:00
Rossen Stoyanchev 25131ebf6f Resource handler initialized only once
Closes gh-27153
2021-07-13 11:44:06 +01:00
Sam Brannen a2ef6badc4 Use StringBuilder.append(char) where possible
To slightly improve performance, this commit switches to
StringBuilder.append(char) instead of StringBuilder.append(String)
whenever we append a single character to a StringBuilder.

Closes gh-27098
2021-06-25 10:44:28 +02:00
Sam Brannen df588e030f Avoid duplicated documentation of validation annotations
See gh-27042, gh-27043, gh-27050
2021-06-15 17:30:41 +02:00
Sam Brannen b677206159 Polish Javadoc 2021-06-15 17:22:11 +02:00
Gabriel e24b2e6b5d Add awaitExchangeOrNull extension function to reactive webclient
Closes gh-26778
2021-06-08 12:06:53 +02:00
Sam Brannen f0f450a18d Polishing 2021-06-07 13:24:46 +02:00
Brian Clozel ac0e71745b Set best matching pattern attribute in WebMvc.fn
Prior to this commit, the `RouterFunctionMapping` WebFlux.fn variant
would set the `HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE` as an
exchange attribute. This is useful for instrumentation purposes.
The WebMvc.fn variant would not do the same; this would lead to
"UNKNOWN" path metrics tags.

This commit ensures that the `RouterFunctionMapping` WebMvc.fn variant
does set the `BEST_MATCHING_PATTERN_ATTRIBUTE` and
`BEST_MATCHING_HANDLER_ATTRIBUTE` request attributes.

Closes gh-26963
2021-05-21 11:54:06 +02:00
Sébastien Deleuze 3dba3691a7 Upgrade to Coroutines 1.5.0
This commit upgrades to Coroutines 1.5.0 while retaining
Coroutines 1.4.x compatibility.

Closes gh-26897
2021-05-17 11:37:02 +02:00
ShindongLee 07ba95739b Fix parameter bug of handler inside the filterFunction DSL
Co-authored-by: hojongs <hojong.jjh@gmail.com>
Co-authored-by: bjh970913 <bjh970913@gmail.com>

Closes gh-26838
2021-05-10 09:35:56 +02:00
Rossen Stoyanchev 582b94d50e Allow charset input in WebClientResponseException
Closes gh-26866
2021-05-06 16:58:42 +01:00
Rossen Stoyanchev 443c34cc90 CorsRegistry implements combine correctly
Closes gh-26877
2021-05-05 21:02:25 +01:00
Sam Brannen 5b96c9b87e Update @since tag due to backport
See gh-26856
2021-05-04 10:59:49 +02:00
Sam Brannen 66cd979ce4 Support @ModelAttribute(binding=false) with WebFlux
Prior to this commit, @ModelAttribute(binding=false) was honored with
Spring Web MVC but not with WebFlux.

This commit adds support for disabling binding via @ModelAttribute with
WebFlux by adding a check to resolveArgument(...) in
ModelAttributeMethodArgumentResolver.

Closes gh-26856
2021-05-03 15:22:43 +02:00
Johnny Lim 98770b15e7
Polishing
Closes gh-26878
2021-04-29 16:53:53 +02:00
Christoph Dreis e7cbe23771 Avoid exceptions when evaluating validation hints
Prior to this commit, evaluating validation hints for
@javax.validation.Valid caused exceptions being raised when getting the
value of this annotation, which does not exist. Bypassing
AnnotationUtils.getValue() in those cases can improve performance by
avoiding the cost incurred by raising exceptions.

See gh-26787
2021-04-22 11:19:30 +02:00
Rossen Stoyanchev d25ae4b02c Add advice on using exchange from an ExchangeFilterFunction
Closes gh-26819
2021-04-21 17:04:10 +01:00
Stephane Nicoll 5226a67161 Update copyright year of changed file
See gh-26807
2021-04-15 09:50:54 +02:00
Mustafa Ulu 1694274e32 Remove leftover Javadoc from WebClient
See gh-26807
2021-04-15 09:50:39 +02:00
Rossen Stoyanchev 27c4e74e24 Update CORS Javadoc in spring-websocket
Closes gh-26753
2021-04-13 17:43:40 +01:00
Juergen Hoeller 04ce8e0ac4 Make URL path tests compatible with Windows
See gh-26775
2021-04-13 09:52:23 +02:00
Rossen Stoyanchev 0a6a6d48e2 Avoid CI failures with UTF-8 chars in test filenames
See gh-26775
2021-04-12 20:14:48 +01:00
Rossen Stoyanchev a08593b44b Correct matching of static resources with parsed patterns
Closes gh-26775
2021-04-12 19:54:20 +01:00
Arjen Poutsma a2d91a562d Support "Accept-Patch" for unsupported media type
This commit introduces support in both servlet and webflux for the
"Accept-Patch" header, which is sent when the client sends unsupported
data in PATCH requests.
See  section 2.2 of RFC 5789.

Closes gh-26759
2021-04-08 14:46:59 +02:00
Arjen Poutsma 97f3846971 Support "Accept-Patch" for OPTIONS requests
This commit introduces support in both servlet and webflux for the
"Accept-Patch" header in OPTIONS requests, as defined in section 3.1 of
RFC 5789.

See gh-26759
2021-04-08 14:43:49 +02:00
Johnny Lim aec151e014 Add since to WebClient.ResponseSpec.awaitBodyOrNull()
See gh-26755
2021-04-02 17:45:57 +02:00
Valentin 58e40d1aa2 Add awaitBodyOrNull to WebClient.ResponseSpec
Such variant is already provided for ClientResponse but not
for WebClient.ResponseSpec.

Closes gh-26731
2021-04-01 17:06:48 +02:00
Rossen Stoyanchev b8d75c3139 Polishing contribution
Closes gh-26674
2021-03-15 18:07:13 +00:00
sokomishalov d92c74d923 Add cookies to the WebSocket HandshakeInfo
See gh-26674
2021-03-15 17:36:47 +00:00
Rossen Stoyanchev 55aa8e914e Expose id from ClientHttpResponse
Closes gh-26656
2021-03-10 17:33:04 +00:00
Juergen Hoeller 530fb0808d Polishing 2021-03-08 23:45:56 +01:00
Sam Brannen 01c2e12fef Polish contribution
See gh-26619
2021-03-02 13:54:01 +01:00
GungnirLaevatain 90de1ab6d1 Ensure local @CrossOrigin maxAge overrides global value
Prior to this commit, a method-level @CrossOrigin maxAge value did not
override a class-level @CrossOrigin maxAge value. This contradicts the
Javadoc for @CrossOrgin which states the following.

    For those attributes where only a single value can be accepted such
    as allowCredentials and maxAge, the local overrides the global
    value.

This commit ensures that a method-level @CrossOrigin maxAge value
overrides a class-level @CrossOrigin maxAge value.

Closes gh-26619
2021-03-02 13:21:35 +01:00
Juergen Hoeller 4af7a6863b Polishing 2021-02-26 17:49:10 +01:00
Rossen Stoyanchev aa73f6733e Lenient treatment of malformed Accept header for @ExceptionHandler
Closes gh-24539
2021-02-25 17:58:32 +00:00
Rossen Stoyanchev ec5774e748 Polishing
Closes gh-26577
2021-02-24 09:37:20 +00:00
fengyuanwei 962ec38a61 Improve Javadoc of ExchangeFunction
See gh-26577
2021-02-24 09:37:20 +00:00
Rossen Stoyanchev 3ec0452fed Dedicated, "_"-prefixed log category for request mappings
Closes gh-26539
2021-02-24 09:36:43 +00:00
Rossen Stoyanchev 1dd7d53de0 More precise mapping for WebSocket handshake requests
Closes gh-26565
2021-02-19 11:49:44 +00:00
Brian Clozel 947387b4cd Fix ResourceUrlProvider handler auto-detection
Prior to this commit, `ResourceUrlProvider` would listen and consider
all `ContextRefreshedEvent` and use the given context to detect
`SimpleUrlHandlerMapping`.

This could lead to situations where a `ResourceUrlProvider` uses another
application context than its own (in a parent/child context setup) and
detect the wrong set of handlers.

Because `ResourceUrlProvider` locks itself once the auto-detection is
done, we need to ensure that it considers only events sent by its
application context.

Fixes gh-26561
2021-02-17 22:04:39 +01:00
gaerfield b00c7075a5 Introduce WebClient.ResponseSpec.awaitBodilessEntity()
This commit also allows awaitBody<Unit>() to be used.

Closes gh-26504
2021-02-15 17:46:18 +01:00
Rossen Stoyanchev 0fc8bf654b Expose DispatcherHandler as PreFlightRequestHandler
Closes gh-26257
2021-02-15 12:59:03 +00:00
Juergen Hoeller df977a2fd2 Nullability refinements and related polishing 2021-02-14 17:57:32 +01:00
Rossen Stoyanchev ab94c7c016 Update WebMvcConfigurer Javadoc for message converters
Closes gh-26388
2021-02-05 13:04:44 +00:00
Rossen Stoyanchev eb7b206142 Expose ChannelId from ReactorNettyWebSocketSession
Closes gh-26485
2021-02-05 11:53:46 +00:00
Rossen Stoyanchev 0d16c9100a MIME types by Class for Encoder, Decoder, HttpMessageReader|Writer
Closes gh-26212
2021-02-04 16:12:57 +00:00
Rossen Stoyanchev 6fde28be98 Fix checkstyle violations 2021-02-03 12:24:45 +00:00
Rossen Stoyanchev df4ba742cb Apply global CORS settings to static resources in WebFlux
Closes gh-26495
2021-02-03 11:17:59 +00:00
Rossen Stoyanchev 996c86f448 Suppress PREFLIGHT_AMBIGUOUS_MATCH if matches have no CORS config
Closes gh-26490
2021-02-03 10:43:08 +00:00
Rossen Stoyanchev 95752ef1c9 Improve handling for pre-flight requests
1. Update the HandlerMapping contract to state that CORS checks are expected
to be applied before returning a handler.

2. DispatcherHandler checks explicitly for pre-flight requests or CORS failed
requests and skips handling for both. Technically no change since
AbstractHandlerMapping already returns a NO_OP_HANDLER for those cases.
The purpose however is for the DispatcherHandler to also guarantee more
explicitly that no such handling can take place for such cases.

As one consequence, this makes it possible to invoke the DispatcherHandler from
anywhere in the WebFilter chain in order to "handle" a pre-flight request, and
then skip the rest of the WebFilter chain.

See gh-26257
2021-01-29 22:12:10 +00:00
Rossen Stoyanchev ec5f99f981 Add mutate() to RequestMappingInfo
Closes gh-26428
2021-01-26 11:44:20 +00:00
Rossen Stoyanchev aa7584d252 Support for Jetty 10
Closes gh-26123
2021-01-21 20:16:21 +00:00
Rossen Stoyanchev cfae40afb4 Return 415 for form data with @RequestBody in WebFlux
Closes gh-26386
2021-01-14 21:23:49 +00:00
Rossen Stoyanchev 994a35d691 Mutated ServerHttpRequest returns native request correctly
Closes gh-26304
2021-01-04 21:40:25 +00:00
Mattison chao bd2edf26df Fix implementation of isOpen() in ReactorNettyWebSocketSession
See gh-26332 for details.

Closes gh-26341
2021-01-04 17:13:39 +01:00
Sam Brannen ef6a582c78 Clean up warnings in Gradle build 2020-12-15 22:47:02 +01:00
Rossen Stoyanchev a11d1c8510 Enrich WebSocketHandler context
Closes gh-26210
2020-12-15 21:34:16 +00:00
mplain a1d134b086 Add missing Kotlin extensions for WebClient.ResponseSpec
Closes gh-26030
2020-12-07 10:34:39 +01:00
Rossen Stoyanchev e7b0b65244 Support for MediaType mappings in ResourceWebHandler
Closes gh-26170
2020-11-30 17:16:55 +00:00
Rossen Stoyanchev 23006d417b Deprecate context method in WebClient
See gh-25710
2020-11-23 21:46:14 +00:00
Rossen Stoyanchev c4d7e6ff46 Fix checkstyle violations
See gh-26117
2020-11-19 21:25:21 +00:00
Spindler, Justin 922d5d271a Add ResponseSpec#toEntityFlux overload with BodyExtractor
See gh-26114
2020-11-19 21:12:56 +00:00
Rossen Stoyanchev 8c3a05bbcf Allow "*" for Access-Control-Expose-Headers
Closes gh-26113
2020-11-19 09:20:55 +00:00
Rossen Stoyanchev 42d3bc47c9 toEntityFlux methods apply error status handling
Closes gh-26069
2020-11-12 18:43:36 +00:00
Rossen Stoyanchev 94fcb37d30 Re-order methods in DefaultResponseSpec
See gh-26069
2020-11-12 18:43:36 +00:00
Rossen Stoyanchev ba9325446c Optimize WebClientUtils
Use constant Predicate for exception wrapping.
Use ResponseEntity constructor instead of builder.

See gh-26069
2020-11-12 18:43:36 +00:00
Rossen Stoyanchev 2899652d8e Fix checkstyle violation 2020-11-09 22:30:35 +00:00
Rossen Stoyanchev 560a504a83 Polishing in DefaultWebClient 2020-11-09 22:07:31 +00:00
Rossen Stoyanchev 79f79e9306 WebClient method to populate the Reactor Context
The alternative is to use a filter but this makes it a little easier
and also guarantees that it will be downstream from all filters
regardless of their order, and therefore the Context will be visible
to all of them.

Closes gh-25710
2020-11-09 22:07:31 +00:00
Rossen Stoyanchev 6bb3ad793e Add isOpen to WebSocketSession in WebFlux
Closes gh-26043
2020-11-09 14:06:43 +00:00
Juergen Hoeller e592634290 Polishing 2020-11-09 13:32:41 +01:00
Rossen Stoyanchev 41bdde5d6b Polishing 2020-11-03 19:31:02 +00:00
Rossen Stoyanchev 2e2d662158 Add toEntityFlux methods
Closes gh-26023
2020-11-03 19:31:02 +00:00
Arjen Poutsma 885a5048c1 Copy default headers, cookies in WebClient builder
This commit makes copies of the default headers and cookies when a
WebClient is built, so that subsequent changes to these do not affect
previously built clients.

Closes: gh-25992
2020-10-29 13:37:25 +01:00
Arjen Poutsma e981bf34b3 Removed unused sample code 2020-10-29 13:37:25 +01:00
Rossen Stoyanchev 24cef14683 Merge branch '5.2.x' into master 2020-10-27 11:21:41 +00:00
Rossen Stoyanchev bb4e802af5 Full header support HTTP HEAD Resource requests
Allow the body to be written in order for all headers to be set
as they would be on HTTP GET. The body content is ignored as a
lower level.

See gh-25976
2020-10-27 11:14:37 +00:00
Rossen Stoyanchev d91b66a04c Allow Resource to add headers for range requests
Closes gh-25976
2020-10-27 10:15:56 +00:00
Sam Brannen d1e6883d5d Fix issues in Javadoc 2020-10-27 11:05:31 +01:00
Sam Brannen 705cf09ad7 Merge branch '5.2.x' 2020-10-26 15:05:35 +01:00
Sam Brannen 449377908f Fix JUnit 4 to AssertJ migration bugs
The migration from JUnit 4 assertions to AssertJ assertions resulted in
several unnecessary casts from int to long that actually cause
assertions to pass when they should otherwise fail.

This commit fixes all such bugs for the pattern `.isNotEqualTo((long)`.
2020-10-26 14:53:09 +01:00
Sébastien Deleuze efe933ad83 Polish Coroutines detection 2020-10-25 18:33:57 +01:00
Arjen Poutsma 417e7e03d4 Introduce RouterFunction attributes
This commit introduces support for router function attributes, a
way to associate meta-data with a route.

Closes: gh-25938
2020-10-23 14:58:49 +02:00
Juergen Hoeller 621295dbd8 Deprecate StringUtils.isEmpty(Object) and replace remaining usage
Closes gh-25945
2020-10-21 16:09:26 +02:00
Juergen Hoeller 23211c784e Upgrade to Netty 4.1.53 and Tomcat 9.0.39
Correct version declaration for Apache HttpClient 5 and its reactive module.
2020-10-16 12:20:15 +02:00
Rossen Stoyanchev a2ff139edd Resolve UriComponentsBuilder argument with contextPath
Closes gh-25822
2020-10-15 22:08:32 +01:00
Sébastien Deleuze 3ed8813bbf Upgrade to Coroutines 1.4.0-M1 and use awaitSingle()
This commit raises the minimum Coroutines version supported
to 1.4.0-M1 and above, and changes usages of awaitFirst() or
awaitFirstOrNull() to awaitSingle() or awaitSingleOrNull()
to fix gh-25007.

Closes gh-25914
Closes gh-25007
2020-10-13 15:26:39 +02:00
Juergen Hoeller e9cd37a4ee Merge branch '5.2.x'
# Conflicts:
#	spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java
2020-10-13 00:25:04 +02:00
Juergen Hoeller f3f19504c6 Polishing 2020-10-13 00:21:07 +02:00
Juergen Hoeller 72b2dda17f Avoid creation of unused logger instance in AbstractMediaTypeExpression
Closes gh-25901
2020-10-13 00:20:06 +02:00
Juergen Hoeller a9d458f5fc Merge branch '5.2.x' 2020-10-12 19:54:21 +02:00
Juergen Hoeller e176c4e799 Polishing 2020-10-12 19:40:50 +02:00
Juergen Hoeller 66a67ec807 Polishing 2020-10-12 18:26:14 +02:00
Juergen Hoeller 50b9542402 Apply handleMissingValue in case of null conversion result as well
Closes gh-23939
2020-10-12 18:07:17 +02:00
Rossen Stoyanchev 5b1b20c8c0 Polishing and minor refactoring
See gh-25884
2020-10-12 11:55:20 +01:00
Rossen Stoyanchev e73e489fd8 Remove use of MonoProcessor.fromSinks
See gh-25884
2020-10-09 20:46:21 +01:00
Sébastien Deleuze cdd48ddd7f Improve Coroutines support consistency 2020-10-09 12:51:08 +02:00
Sébastien Deleuze 94a42a3086 Support suspending handler methods in Spring MVC
This commit adds support for Kotlin Coroutines suspending functions to
Spring MVC, by converting those to a Mono that can then be handled by
the asynchronous request processing feature.

It also optimizes Coroutines detection with the introduction of an
optimized KotlinDetector.isSuspendingFunction() method that does not
require kotlin-reflect.

Closes gh-23611
2020-10-09 12:25:32 +02:00
Rossen Stoyanchev d49a7a105d Fix failing tests from Reactor snapshot changes
See gh-25884
2020-10-08 18:38:05 +01:00
Sébastien Deleuze 7d7ed88739 Provide WebClient#exchange() alternative for Coroutines
This commit adds awaitExchange { } and
exchangeToFlow { } extensions as Coroutines variants for
exchangeToMono() and exchangeToFlux().

Closes gh-25751
2020-10-07 11:09:12 +02:00
Sébastien Deleuze e899397438 Add missing ClientResponse Coroutines extensions
This commit adds awaitBodilessEntity() and
createExceptionAndAwait() missing ClientResponse
Coroutines extensions.

Closes gh-25866
2020-10-07 11:06:43 +02:00
Juergen Hoeller f5d9babfd2 Avoid reflection when creating instances of well-known View classes
Closes gh-25847
2020-10-06 16:55:42 +02:00
Brian Clozel a0af552d0f Add option for ignoring last-modified for static resources
Prior to this commit, the resource handler serving static resources for
Spring MVC and Spring WebFlux would always look at the
`Resource#lastModified` information, derive the `"Last-Modified"` HTTP
response header and support HTTP conditional requests with that
information.

In some cases, builds or packaging tools choose to set this last
modification date to a static date in the past. This allows tools to
have reproducible builds or to leverage caching given the static
resources content didn't change.

This can lead to problems where this static date (e.g. "1980-01-01") is
used literally in HTTP responses and will make the HTTP caching
mechanism counter-productive: the content of the resources changed, but
the application insists on saying it didn't change since the 80s...

This commit adds a new configuration option to disable this support -
there is no way to automatically discard those dates: there is no
standard for that and many don't use he "EPOCH 0 date" as it can lead to
compatibility issues with different OSes.

Closes gh-25845
2020-10-06 16:30:35 +02:00
Arjen Poutsma 392895e256 Revert errorhandler order in RouterFunctionBuilder
Prior to this commit, error handlers in the WebMvc.fn and WebFlux.fn
router function builders had to be registered in an unintuitive, reverse
order, due to the filter chain composition model used.
This commit reverses the error handler order, so that more specific
error handlers can come before generic ones.

Closes gh-25541
2020-10-06 15:32:22 +02:00
Arjen Poutsma 200b33b26a Add no path HTTP method variants for route builder
This commit adds two overloaded methods for each HTTP method in the
WebFlux.fn and WebMvc.fn route builders: one method taking just a
handler function, the other a request predicate and handler function.

After this commit, it is no longer required to provide a String path,
which is particularly useful when nesting routes, and the path would be
"".

Closes gh-25752
2020-10-06 11:00:17 +02:00
Rossen Stoyanchev b9ef5416b9 Expose combine method in CorsConfiguration
Closes gh-25716
2020-09-25 21:36:18 +01:00
Rossen Stoyanchev db9190e0e6 Remove use of WebClient#exchange from WebTestClient
The exchange() method is now deprecated because it is not safe for
general use but that doesn't apply to the WebTestClient because it
exposes a different higher level API for response handling that
ensures the response is consumed. Nevertheless WebTestClient cannot
call WebClient.exchange() any more.

To fix this WebTestClient no longer delegates to WebClient and thus
gains direct access to the underlying ExchangeFunction. This is
not a big deal because WebClient and WebTestClient do the same
only when it comes to gathering builder options and request input.

See gh-25751
2020-09-25 21:16:44 +01:00
Rossen Stoyanchev 1404dd768f Add exchangeToMono and exchangeToFlux + deprecate exchange()
See gh-25751
2020-09-25 21:16:44 +01:00
Sébastien Deleuze 84b1efa4b8 Merge branch '5.2.x' 2020-09-25 15:23:31 +02:00
Sébastien Deleuze b322cbd625 Add missing @Nullable to WebFlux RequestMappingHandlerMapping
Closes gh-25657
2020-09-25 14:22:53 +02:00
Igor Manushin 9ad5a8ead0 Add KClass variant to Coroutines web API
Closes gh-24967
2020-09-25 11:32:20 +02:00
Rossen Stoyanchev 1061bcdba2 Set sameSite in ClientHttpResponse implementations
Closes gh-25785
2020-09-22 07:36:29 +01:00
Juergen Hoeller e4a3d5bf66 Deprecation wording with suggested alternative and without removal hint
See gh-25733
See gh-25736
2020-09-15 13:22:34 +02:00
Arjen Poutsma 74f64c4e3b Wrap exceptions in WebClient
This commit makes sure that exceptions emitted by WebClient are wrapped
by WebClientExceptions:

- Exceptions emitted by the ClientHttpConnector are wrapped in a new
  WebClientRequestException.

- Exceptions emitted after a response is received are wrapped in a
  WebClientResponseException

Closes gh-23842
2020-09-14 15:06:46 +02:00
Rossen Stoyanchev ef10ac6b29 Align WebFlux with WebMvc for pathWithinHandlerMapping
See gh-25174
2020-09-13 21:53:51 +01:00
Rossen Stoyanchev 3295034839 Merge branch '5.2.x' into master 2020-09-13 21:30:02 +01:00
Rossen Stoyanchev 852718ec0e Minor fix in PathResourceResolverTests
Closes gh-25671
2020-09-13 21:09:08 +01:00
Brian Clozel 93f201a414 Deprecate AppCacheManifestTransformer
This commit deprecates the `AppCacheManifestTransformer` implementations
since the appcache feature is being removed from the browsers.

Closes gh-25733
2020-09-08 14:46:48 +02:00
Arjen Poutsma d550d344d5 Respect context path in WebMvc.fn & WebFlux.fn
This commit makes several changes in both WebMvc.fn as well as
WebFlux.fn.

 - ServerRequest now exposes a RequestPath through requestPath(), and
   pathContainer() has been deprecated.

 - The PathPredicate and PathResourceLookupFunction now respects this
   RequestPath's pathInApplication() in their path-related
   functionality.

 - When nesting, the PathPredicate now appends the matched part of the
   path to the current context path, instead of removing the matched
   part (which was done previously). This has the same result: the
   matched part is gone, but now the full path stays the same.

Closes gh-25270
2020-09-03 15:10:56 +02:00
Rossen Stoyanchev e02ccc9374 Optional WebSocket engine presence in WebFlux config
Closes gh-22587
2020-09-02 10:05:58 +01:00
Juergen Hoeller e20bff9c64 Consistent data class constructor resolution with clear error message
MVC data class processor constructs target instance even in case of binding failure, as long as the corresponding method parameter is not marked as optional.

Closes gh-24372
2020-09-01 19:10:32 +02:00
Rossen Stoyanchev 591ab8a00a @EnableWebFlux setup supports WebSocketHandler
Closes gh-22587
2020-08-31 21:15:17 +01:00
Rossen Stoyanchev c4e1e4ee1e WebFlux AbstractUrlHandlerMapping support URI vars
Closes gh-25648
2020-08-28 21:56:28 +01:00
Juergen Hoeller d37eaa5941 Introduce DataClassRowMapper with record-style constructor binding support
Closes gh-24695
2020-08-28 18:52:35 +02:00
Violeta Georgieva 1fe2ea5a87 Add logPrefix to the log statement
Add logPrefix to the log statement to provide better debugging experience
2020-08-28 10:53:07 +01:00
Juergen Hoeller cf2e0c7959 Selected use of ArrayList instead of LinkedList in common places
See gh-25652
2020-08-27 14:14:44 +02:00
Juergen Hoeller 874574513c Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes gh-25650
2020-08-26 18:32:08 +02:00
Juergen Hoeller ff11467a0c Avoid resizing of fixed-size HashMap/LinkedHashMap variants
Closes gh-25349
2020-08-25 19:26:18 +02:00
Juergen Hoeller 7324140d20 Merge branch '5.2.x' 2020-08-25 16:21:00 +02:00
Juergen Hoeller 6f0461c569 Polishing 2020-08-25 16:17:22 +02:00
Rossen Stoyanchev 7adeb461e0 WebClient exposes API for access to native request
Closes gh-25115, gh-25493
2020-08-24 07:58:35 +01:00
Sam Brannen 4d3dd9b9f6 Clean up warnings in Gradle build 2020-08-11 17:20:27 +02:00
Sam Brannen 596936f18c Polishing 2020-08-11 16:42:18 +02:00
Sam Brannen d0cf90bb8e Update tests due to deprecations in Reactor 2020-08-08 12:40:23 +02:00
Brian Clozel 617ec359bd Update after MonoProcessor deprecation in Reactor
This commit adapts the usage of `MonoProcessor` after deprecations
introduced in reactor/reactor-core#1053
2020-08-07 18:59:21 +02:00
Juergen Hoeller f4c0ceb1cc Merge branch '5.2.x'
# Conflicts:
#	build.gradle
#	spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java
#	spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
2020-08-07 13:15:36 +02:00
Juergen Hoeller 8dd285f877 Polishing 2020-08-07 13:02:43 +02:00
Juergen Hoeller d61c0ee57d Consistent support for path variable and multipart binding
Closes gh-24107
Closes gh-22169
Closes gh-25265
2020-08-06 18:28:09 +02:00
Brian Clozel 9aae5ed3fa Update Reactor Netty modules
Since reactor/reactor-netty#739, the `reactor-netty` module is now split
into two: `reactor-netty-core` and `reactor-netty-http`.

This commit updates the Spring Framework build accordingly.
2020-08-01 11:49:15 +02:00
Sébastien Deleuze 2d08c76ab5 Bring back kotlin-script-runtime dependency
See gh-24171
2020-07-30 10:57:53 +02:00
Sébastien Deleuze 5c456db3cc Upgrade to Kotlin 1.4 RC
- The compiler is configured to retain compatibility with Kotlin 1.3.
- Explicit API mode is not yet enabled but could be in the future.
- Some exceptions thrown by Kotlin have changed to NullPointerException,
  see https://youtrack.jetbrains.com/issue/KT-22275 for more details.

Closes gh-24171
2020-07-30 10:18:33 +02:00
Rossen Stoyanchev 683cc2eb7f Add NDJSON and deprecate application/stream+json
Closes gh-21283
2020-07-28 17:53:37 +03:00
Rossen Stoyanchev a4c157fc09 Check for native WebSocket message
In addition to the changes in
313a7836b0 to support passing on a
the underlying WebSocket message, this commits checks for its
availability.

Closes gh-25099
2020-07-27 21:20:50 +03:00
Sam Brannen 335c3d5db6 Polish contribution
See gh-25445
2020-07-22 17:26:59 +02:00
XenoAmess ab859fcc96 Refine use of substring operations
Closes gh-25445
2020-07-22 17:26:42 +02:00
Sam Brannen a8901e3cf8 Polish contribution
See gh-25445
2020-07-22 16:36:14 +02:00
XenoAmess edfc6c0293 Refine use of substring operations
Closes gh-25445
2020-07-22 16:28:58 +02:00
XenoAmess e71f702bb9
Use `static private` instead of `private static` for method declarations
Closes gh-25452
2020-07-21 18:26:28 +02:00
Rossen Stoyanchev 7ce4d150ce Merge branch '5.2.x' 2020-07-20 18:02:22 +03:00
Rossen Stoyanchev 913eca9e14 ReactorNettyRequestUpgradeStrategy uses unique builder per request
See gh-25315
2020-07-20 17:55:23 +03:00
Juergen Hoeller e0d05153aa Merge branch '5.2.x'
# Conflicts:
#	build.gradle
2020-07-17 19:30:03 +02:00
Juergen Hoeller 0b697a3068 Polishing 2020-07-17 19:24:23 +02:00
Juergen Hoeller 198d64d539 Merge branch '5.2.x'
# Conflicts:
#	build.gradle
2020-07-17 17:52:08 +02:00
Juergen Hoeller e9898f7d52 Polishing 2020-07-17 17:48:33 +02:00
Rossen Stoyanchev 313a7836b0 Provide access to Netty's WebSocketFrame
Closes gh-25099
2020-07-09 15:42:28 +03:00
Rossen Stoyanchev 37366e0c91 Support for custom status in ResponseStatusException
Closes gh-20336
2020-07-09 15:06:33 +03:00
Rossen Stoyanchev 4d7418841c AbstractHandlerMethodMapping refactoring
Remove convenience Map that is to avoid. The only downside is that
getHandlerMethods requires a transformation but that should not be used frequently.

See gh-22961
2020-07-09 12:11:15 +03:00
Rossen Stoyanchev 0584c289ab Support for direct path lookups in WebFlux
Closes gh-22961
2020-07-09 11:26:04 +03:00
Rossen Stoyanchev 0e4e25d227 Updates to CORS patterns contribution
Closes gh-25016
2020-07-08 13:18:46 +03:00
Rossen Stoyanchev 1181bb1852 Rename originsPattern to originPatterns
See gh-25016
2020-07-08 13:18:46 +03:00
Ruslan Akhundov 8632118e8d CorsConfiguration now supports pattern based origins.
Closes gh-24763
2020-07-08 13:18:46 +03:00
Arjen Poutsma 20254f02d2 Polishing 2020-06-30 11:33:12 +02:00
Arjen Poutsma e9d9de5f99 RouterFunction honors PathPatternParser in config
This commit introduces a way to change the PathPatternParser used in
PathPredicates, by way of a ChangePathPatternParserVisitor. This
visitor is used by both WebFluxConfigurationSupport and
WebMvcConfigurationSupport to make sure the configured parser is used.

Closes gh-23236
2020-06-30 11:33:12 +02:00
Rossen Stoyanchev b16f6fa456 Shared static instance of DefaultDataBufferFactory 2020-06-24 16:12:56 +01:00
Arjen Poutsma 973ee9b852 (Re)introduce DefaultMultipartMessageReader
This commit introduces the DefaultMultipartMessageReader, a fully
reactive multipart parser without third party dependencies.

An earlier version of this code was introduced in fb642ce, but removed
again in 77c24aa because of buffering issues.

Closes gh-21659
2020-06-24 10:31:48 +02:00
Rossen Stoyanchev 22bf62def1 Replace remaining use of deprecated Processors in tests
See gh-25085
2020-06-23 20:29:35 +01:00
Rossen Stoyanchev ff9daa9377 Adjust WebFlux behavior for @RequestPart List<T>
List<T> support was added relatively late, incorrectly decoding each
part to T which means no way to decode a single part to List<T> and
thatis the most common case (vs multipart parts with the same name).
This behavior was further misaligned with Spring MVC as well as with
the behavior for T[].

Closes gh-22973
2020-06-22 05:40:13 +01:00
Sam Brannen 9d5881e0ad Suppress warnings, remove unused code, etc. 2020-06-20 17:15:35 +02:00
Sébastien Deleuze 6b355df903 Revert "Upgrade to Kotlin 1.4 M2"
This reverts commit 2a74eff10f.

Some regressions require to wait at least Kotlin 1.4 M3.
2020-06-18 14:06:39 +02:00
Sam Brannen 9984a335ca Merge branch '5.2.x' 2020-06-17 14:01:36 +02:00
Sam Brannen 972c01cbbd Replace "blacklist" with alternative words
See gh-25262
2020-06-17 14:00:26 +02:00
Сергей Цыпанов 7949937655 Remove redundant assignment of default values to volatile fields 2020-06-17 10:50:51 +02:00
Sébastien Deleuze 2a74eff10f Upgrade to Kotlin 1.4 M2
- The compiler is configured to retain compatibility with Kotlin 1.3.
- Explicit API mode is not yet enabled but could be in the future.
- A workaround for Gradle build is required for now, see
  https://youtrack.jetbrains.com/issue/KT-39610 for more details.
- Some exceptions thrown by Kotlin have changed to NullPointerException,
  see https://youtrack.jetbrains.com/issue/KT-22275 for more details.

Closes gh-24171
2020-06-16 15:21:57 +02:00
Rossen Stoyanchev 5225a57411 Support for parsed PathPatterns in Spring MVC
See gh-24945
2020-06-15 11:25:35 +01:00
Juergen Hoeller 9c1c787ee9 Polishing 2020-06-08 19:27:38 +02:00
Juergen Hoeller a34f1e3759 Merge branch '5.2.x'
# Conflicts:
#	build.gradle
#	spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java
#	spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java
2020-06-06 18:52:51 +02:00
Juergen Hoeller 65154170d3 Polishing 2020-06-06 18:49:32 +02:00
Juergen Hoeller d71957ce7c Polishing 2020-06-06 17:45:12 +02:00
Juergen Hoeller 98030f3794 Avoid unnecessary copy of cookies map in DefaultWebClientBuilder
See gh-25034
2020-06-06 17:44:02 +02:00
Juergen Hoeller 65b09be669 Polishing 2020-06-06 16:10:20 +02:00
Juergen Hoeller 5051d7302d Merge branch '5.2.x'
# Conflicts:
#	build.gradle
#	spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java
#	spring-web/src/main/java/org/springframework/http/HttpHeaders.java
#	spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java
2020-06-06 15:27:15 +02:00
Juergen Hoeller d14140da69 Polishing 2020-06-06 13:21:46 +02:00
Rossen Stoyanchev a7f8120164 Merge branch '5.2.x' 2020-06-03 06:14:20 +01:00
Rossen Stoyanchev 8dc8d88f88 Pre-calculated RequestMappingInfo hashcode
See gh-25143
2020-06-03 06:11:35 +01:00
Rossen Stoyanchev 1e25556049 Shared PathPatternParser instance
See gh-25143
2020-06-03 05:58:10 +01:00
Johnny Lim 30351c257c Deprecate methods in ReactorNettyWebSocketClient
Closes gh-25049
2020-05-29 16:24:52 +01:00
Rossen Stoyanchev 6d6269f1ee Switch to Reactor 2020.0.0 snapshots
A switch to RSocket 1.0.1 snapshots is also required to pick up a
for froward compatibility with Reactor Netty 1.0.

See gh-25085
2020-05-29 15:14:01 +01:00
Rossen Stoyanchev d706899b7e Merge branch '5.2.x' 2020-05-28 06:52:23 +01:00
Rossen Stoyanchev a92f425529 Also use constant for custom mapping condition
See gh-25143
2020-05-28 06:51:57 +01:00
Rossen Stoyanchev 90ccabd60b Merge branch '5.2.x' 2020-05-27 19:12:57 +01:00
Rossen Stoyanchev e9a9883aa9 Optimal initialization of empty request mapping conditions
Closes gh-25143
2020-05-27 18:57:02 +01:00
Rossen Stoyanchev b5d9f27ca4 Merge branch '5.2.x' 2020-05-24 21:20:12 +01:00
Rossen Stoyanchev d7a29bbcef DefaultClientResponseBuilder copies logPrefix
Closes gh-25069
2020-05-23 10:41:07 +01:00
Sam Brannen 59443bfe18 Merge branch '5.2.x' 2020-05-20 14:28:56 +02:00
Sam Brannen 4f2b6473ac Honor attributes configured in ServerRequest.from() builder
Prior to this commit, if attributes were configured in the builder
returned by `ServerRequest.from(...)`, those attributes were not
available in the `ServerRequest` built by the builder. In addition, any
attributes in the original `ServerRequest` supplied to
`ServerRequest.from(...)` were also ignored.

This commit addresses this issue by ensuring that the attributes
configured via DefaultServerRequestBuilder are used as the attributes
in the resulting `ServerRequest`.

This commit also polishes the Javadoc in `ServerRequest` and
`ClientResponse` and avoids the use of lambda expressions in the
constructors for `DefaultServerRequestBuilder` and
`DefaultClientResponseBuilder`.

Closes gh-25106
2020-05-20 14:10:44 +02:00
Rossen Stoyanchev de378599d3 Provide access to CloseStatus in WebSocketSession
Closes gh-22079
2020-05-14 15:42:43 +01:00
Brian Clozel b883aad1f1 Use weak ETags in VersionResourceResolver
Prior to this commit, the `VersionResourceResolver` implementations
would write a strong ETag HTTP response header with the resolved version
of the resource (the actual value depending on the chosen strategy).

This approach doesn't work well when combined with HTTP compression.
Web servers disable HTTP response copression in the presence of strong
ETags since mutating the response body would break the contract.

This commit changes this semantic and ensures that weak ETags are used
instead.

Closes gh-24898
2020-05-11 21:25:54 +02:00
Rossen Stoyanchev 94824e30a4 Avoid parse cookies when mutating request or response
When mutating a ServerHttpRequest or ClientResponse, the respective
builders no longer access cookies automatically which causes them to
be parsed and does so only if necessary. Likewise re-applying the
read-only HttpHeaders wrapper is avoided.

See gh-24680
2020-05-11 08:49:28 +01:00
Rossen Stoyanchev 0e9ecb6c99 Shortcut handling of bodyToFlux(DataBuffer.class)
Given that the body is a Flux<DataBuffer> there probably could be a
Flux<DataBuffer> body();

At least bodyToFlux(DataBuffer.class) which is used when mutating and
is a common case should not incur overhead.

See gh-24680
2020-05-11 08:49:28 +01:00
Rossen Stoyanchev 67a06f5edc Add mutate() to ClientResponse and deprecate from()
from() has the flaw of ignoring the body and it can't be fixed because
applications are guaranteed to be setting it already and if set twice
the builder drains the first body.

mutate() is a better fit in any case for what needs to be done in a
filter chain. It can be done more efficiently and is consistent with
similar options on the server side.

See gh-24680
2020-05-11 08:49:28 +01:00
Rossen Stoyanchev df99889aa6 Avoided repeated creation of ReadOnlyHttpHeaders wrapper
See gh-24680
2020-05-11 08:49:28 +01:00
Rossen Stoyanchev 3276f81851 Avoid one layer of HttpHeaders wrapping
See gh-24680
2020-05-11 08:49:28 +01:00
Rossen Stoyanchev 7f59381c7d Add support for RxJava 3
Closes gh-24170
2020-05-11 08:48:48 +01:00
Rossen Stoyanchev 1da903dd59 Add PartHttpMessageWriter
Closes gh-24535
2020-05-08 07:54:50 +01:00
Rossen Stoyanchev f28e08eceb Improving contribution
See gh-24406
2020-05-06 10:50:51 +01:00
Rossen Stoyanchev a7c736915a Polishing and completing contribution
See gh-24866
2020-05-05 18:20:45 +01:00
martin-tarjanyi 3bc1d42dcd Integrate Apache http client with WebClient
This commit introduces a ClientHttpConnector implementation backed by
Apache HttpComponents HttpClient 5.0.

Fixes gh-24700
2020-04-29 15:02:09 +02:00
Sam Brannen c3f439417e Disable remaining JavaScript-based tests on Java 15+
This commit disables all remaining JavaScript-based tests on Java 15 or
higher since the Nashorn JavaScript engine is no longer part of the JDK.
2020-04-28 17:22:22 +02:00
Juergen Hoeller af65b1ca62 Polishing 2020-04-25 16:37:16 +02:00
mattbertolini 21887ad23b Allow override of data binder binding
Motivation
----------
The Spring MVC ModelAttributeMethodProcessor includes many helpful
extension methods that allow developers to extend and enhance the data
binding capabilities of the class. Unfortunately, Spring WebFlux's
equivalent class, the ModelAttributeMethodArgumentResolver, does not
include these same extension methods. I am leveraging these extension
methods, specifically the bindRequestParameters method, to provide
valuable enhancements to my application. I would like to provide these
same enhancements to the WebFlux portion of my application and am
unable to do so at this time. I would like to update the WebFlux
ModelAttributeMethodArgumentResolver to add the bindRequestParameters
method.

Modifications
-------------
I created a new method called bindRequestParameters and encapsulated
the WebExchangeDataBinder bind call inside of it. This method is
marked as protected as it should only be used by children of this
class. This change mirrors the behavior in the equivalent Spring MVC
class (ModelAttributeMethodProcessor).

Result
------
The WebFlux ModelAttributeMethodArgumentResolver can now accept
alternative data binding implementations mirroring the Web MVC
behavior.
2020-04-25 16:27:36 +02:00
Rossen Stoyanchev d9262b8a0c Suppress deprecated Reactor Netty call
See gh-24892
2020-04-24 12:57:16 +01:00
Rossen Stoyanchev 0520ee0fb6 Use the Reactor Netty WebsocketServerSpec
Closes gh-24959
2020-04-23 13:50:00 +01:00
Sam Brannen e26764d249 Remove duplicate words in documentation and polish Javadoc 2020-03-31 12:17:58 +02:00
Rossen Stoyanchev a606fb4b21 Fix checkstyle errors 2020-03-26 22:02:32 +00:00
Rossen Stoyanchev 3175f0771e Remove dumpString from DataBufferTestUtils
See gh-24786
2020-03-26 21:42:12 +00:00
Сергей Цыпанов f17b0125ff Simplify conversion of DataBuffer to String
See gh-24786
2020-03-26 21:42:12 +00:00
Rossen Stoyanchev 1822f272c7 toBodilessEntity() actually drains response body
See gh-24788
2020-03-26 15:59:28 +00:00
Rossen Stoyanchev 5309757026 WebClientIntegrationTests refactoring
- consistent test naming
- grouping by category and logical ordering within category
- consolidate overlapping tests
- polishing

See gh-24788
2020-03-26 15:59:04 +00:00
Rossen Stoyanchev d1cf16320b Minor refactoring and polishing in WebClientUtils
See: gh-24788
2020-03-26 15:59:04 +00:00
Rossen Stoyanchev 9685380334 Fix typos 2020-03-20 21:14:56 +00:00
Sam Brannen 331b14bb0b Fix NoHttp violation 2020-03-20 19:43:00 +01:00
Rossen Stoyanchev 2ca93cbe1c Update Javadoc for WebClient onStatus handlers
Closes gh-24736
2020-03-20 18:02:18 +00:00
Rossen Stoyanchev 0d42a1bd7f Add retry for flaky test (suspected Tomcat issue) 2020-03-19 14:32:56 +00:00
Arjen Poutsma 7c4f0318bb Improve efficiency of built RouterFunction
This commit changes the way RouterFunctions registered to the builder
are composed in both WebFlux.fn and WebMvc.fn.
Prior to this commit, all routes added to the build were composed with
`reduce`.
After this commit, all routes are stored in a special router function,
allowing for more efficient execution and smaller stack traces.

Closes gh-24652
2020-03-13 16:09:41 +01:00
Arjen Poutsma 54e2df2e0e Improve RouterFunction composition
This commit changes the way two RouterFunctions are composed in
WebFlux.fn. Prior to this commit, two were composed with
`switchIfEmpty()`, switching from the first to the second route if the
first did not provide an element.
After this commit, two router functions are compose using `concat`,
which results in a smaller stack trace.

See gh-24652
2020-03-13 16:09:41 +01:00
Rossen Stoyanchev 7b7dfcaaed Polishing contribution
See gh-24691
2020-03-13 14:58:01 +00:00
Arjen Poutsma 0dc1c7eb8b Add ServerRequest::checkNotModified
This commit adds the checkNotModified method to ServerRequest in both
WebFlux.fn and WebMvc.fn. Unlike other checkNotModified methods found
in the framework, this method does not return a boolean, but rather
a response wrapped in a Mono/Optional. If the resource has
not been changed, the not-modified response can be returned directly;
if the resource has changed, the user can create a corresponding
response using switchIfEmpty/orElse(Get).

Closes gh-24173
2020-03-11 16:45:00 +01:00
Arjen Poutsma 61569003b5 CORS support in HTTP header predicate
This commit introduces CORS support for the HeadersPredicate in
WebMvc.fn and WebFlux.fn.

Closes gh-24564
2020-03-10 17:22:26 +01:00
Arjen Poutsma 3cbea86335 Deprecate MockServerRequest
Deprecate MockServerRequest in favor of ServerRequest::create
combined with a MockServerWebExchange.
2020-03-10 15:45:11 +01:00
Arjen Poutsma c03cdbac21 CORS support in HTTP method predicate
This commit introduces CORS support for the HttpMethodPredicate in
WebMvc.fn and WebFlux.fn.

Closes gh-24564
2020-03-10 15:45:11 +01:00
Arjen Poutsma fc12891006 Add ServerRequest::firstHeader
This commit introduces the method firstHeaderiin both WebMvc.fn and
WebFlux.fn, which return the first header value of a given header name,
if any.
2020-03-10 15:45:11 +01:00
Christoph Dreis 2093e35f27 Avoid unnecessary sorting 2020-03-04 19:10:14 +00:00
陈其苗 8a7bb49436 Improve WebClient.Builder Javadoc 2020-02-28 17:07:58 +00:00
Rossen Stoyanchev 5f1e4ffc4f WebClient.Builder javadoc updates
Closes gh-24611
2020-02-28 15:55:53 +00:00
Juergen Hoeller c0fbf6fca1 Polishing 2020-02-24 19:50:12 +01:00
Brian Clozel f048f27d80 Configure Reactor Netty quiet shutdown period in tests
See gh-24538
2020-02-24 18:15:59 +01:00
Hyunjin Choi ede2a1d4b2 Remove unnecessary semicolon in some enum classes 2020-02-24 14:56:12 +01:00
Rossen Stoyanchev 68b980f849 Remove producible request attribute before mapping
The attribute was previously removed only before exception resolution
in the DispatcherServlet in order to allow error rendering to make an
independent choice on content negotation.

However, Boot rendering happens later in an ERROR dispatch which could
also be a nested dispatch on some servers. So the attribute must also
generally be removed prior to mapping.

We also move the methods where this is done to the base
RequestMappingInfoHandlerMapping class which also deals with the
produces condition and where the producible attribute is added in the
first place.

Closes gh-24466
2020-02-18 21:50:38 +00:00
Rossen Stoyanchev fb6ee01281 Consistently call setComplete before WS upgrade
Even thought Tomcat and Jetty, which commit the response more lazily,
were not impacted by this issue, it still makes sense for them to
complete the WebFlux response (and pre-commit actions) at the same time
as for other servers for consistent behavior.

See gh-24475
2020-02-18 09:44:04 +00:00
Brian Clozel 13f23dc32b Mark response as complete before WebSocket upgrade
Prior to this commit, some WebSocket `RequestUpgradeStrategy` reactive
implementations would prevent the application from writing HTTP headers
and cookies to the response.

For Reactor Netty and Undertow, handling the upgrade and starting the
WebSocket communication marks the response status and headers as sent
and the application cannot update HTTP response headers after that.

This commit ensures that the `RequestUpgradeStrategy` implementations
mark the responses as "complete", so that headers are written before we
delegate to the server implementation.

Fixes gh-24475
2020-02-13 21:42:31 +01:00
Rossen Stoyanchev 28a95e89f3 Upgrade to Dysprosium SR5 snapshots
See gh-24355
2020-02-11 12:52:04 +00:00
Rossen Stoyanchev f5df422de9 Polishing contribution
See gh-24470
2020-02-03 20:32:36 +00:00
Hyunjin Choi 273812f9c5 Remove unnecessary escapes in regular expressions
See gh-24470
2020-02-03 20:22:40 +00:00
Rossen Stoyanchev 547342b27d Status code as Integer methods in ServerHttpResponse
Closes gh-24400
2020-01-30 10:06:58 +00:00
Rossen Stoyanchev 992e75303d Improve support for generics in Jackson codecs
Closes gh-23791
2020-01-23 12:31:00 +00:00
Rossen Stoyanchev a234b90abb Explicit content-type for resources
BodyInserters.ofResource now respects the Content-Type, if specified on
the client request or server response.

Closes gh-24366
2020-01-20 17:09:47 +00:00
Rossen Stoyanchev b1d93bb307 Polishing contribution
See gh-24367
2020-01-16 16:01:31 +00:00
Jacob Severson 8e67b7b2cf Expose proxyPing Reactor Netty WebSocket
See gh-24331
2020-01-16 16:01:31 +00:00
Sébastien Deleuze bc7d010485 Update CORS support
This commit updates CORS support in order to check Origin header
in CorsUtils#isPreFlightRequest which does not change how Spring
MVC or WebFlux process CORS request but is more correct in term
of behavior since it is a public API potentially used in another
contexts.

It also removes an unnecessary check in
AbstractHandlerMethodMapping#hasCorsConfigurationSource and processes
every preflight request with PreFlightHandler.

Closes gh-24327
2020-01-13 08:33:14 +01:00
Brian Clozel a31a4f8148 Copy strategiesConfigurers when cloning WebClient.Builder
This commit fixes the missing `strategiesConfigurers` copy when the
`WebClient.Builder` is cloned.

Fixes gh-24329
2020-01-10 15:59:59 +01:00
Rossen Stoyanchev 34d32402d3 Return 500 if producible attribute present
When a request is mapped through a producible condition on an
@RequestMapping, then a failure to find a converter/decoder should be
a 500 because the return type + media type pair were declared by the
controller and that should be possible to render.

Closes gh-23287
2020-01-09 11:10:44 +00:00
Sam Brannen ef6b1ba034 Update copyright date 2020-01-07 17:15:23 +01:00
stsypanov c480a99a77 Trim line from LineInfo only once 2020-01-07 14:44:09 +01:00
Brian Clozel ffc1f960f9 Polish
See gh-24238
2020-01-07 09:05:49 +01:00
Brian Clozel f9c1565f4e Remove Content-* response headers for error handling
Prior to this commit, when WebFlux handlers added `"Content-*"` response
headers and an error happened while handling the request, all those
headers would not be cleared from the response before error handling.

This commit clears those headers from the response in two places:
* when invoking the handler and adapting the response
* when writing the response body

Not removing those headers might break HTTP clients since they're given
wrong information about how to interpret the HTTP response body: the
error response body might be very different from the original one.

Fixes gh-24238
2020-01-06 16:55:08 +01:00
Sam Brannen 081b3d304d Move JavaUtilLoggingConfigurer to spring-core test fixtures
See gh-23550
2020-01-03 14:34:29 +01:00
Sam Brannen 7b6d83a106 Use Gradle test fixture support for spring-web
See gh-23550
2020-01-02 16:01:35 +01:00
Sam Brannen 7cd4ddf5fc Rename test fixture package in spring-beans
See gh-23550
2020-01-02 16:01:35 +01:00
Sam Brannen 4260c34b47 Rename test fixture package in spring-core
See gh-23550
2020-01-02 16:01:34 +01:00
Sam Brannen 61d4ee594d Use Gradle test fixture support for spring-beans and spring-context
See gh-23550
2020-01-02 16:01:34 +01:00
Sam Brannen 5718bf424b Use Gradle test fixture support for spring-core
See gh-23550
2020-01-02 16:01:34 +01:00
Brian Clozel 75fd391fc7 Remove quality parameter from selected media type
Prior to this commit, WebFlux application would keep the quality
parameter from the "Accept" request header when selecting a media type
for the response. It would then echo it back to the client.

While strictly not wrong, this is unnecessary and can confuse HTTP
clients. This commit aligns WebFlux's behavior with Spring MVC.

Fixes gh-24239
2020-01-02 11:29:04 +01:00
Rossen Stoyanchev a1b8b18282 Polishing logPrefix Javadoc in ClientRequest|Response
Closes gh-23791
2019-12-20 09:27:40 +00:00
Rossen Stoyanchev 7456fb9c65 Add failing test to be fixed
See gh-23791
2019-12-20 09:15:44 +00:00
Arjen Poutsma 09b6730f3d Expose logPrefix in ClientResponse
This commit exposes the logPrefix field in the ClientResponse interface.

Closes gh-24146
2019-12-13 10:59:53 +01:00
Rossen Stoyanchev dd9b6287b4 Expose ClientCodecConfigurer in WebClient.Builder
Using Consumer<ClientCodecConfigurer> instead of
Consumer<ExchangeStrategies> eliminates one level of nesting that is
also unnecessary since codecs are the only strategy at present.

Closes gh-24124
2019-12-12 21:58:14 +00:00
Rossen Stoyanchev 11e321b8e7 Add register methods to CodecConfigurer.CustomCodecs
The new register methods replace the now deprecated
encoder, decoder, reader, and writer methods, and also offer a choice
to opt into default properties such maxInMemorySize, if configured.

See gh-24124
2019-12-12 21:58:14 +00:00
Rossen Stoyanchev 1b172c1d20 Expose localAddress in WebFlux server
Closes gh-24174
2019-12-10 15:10:13 +00:00
Rossen Stoyanchev 828fe39523 Consistently use releaseBody in DefaultWebClient
See gh-24125
2019-12-04 18:19:52 +00:00
Rossen Stoyanchev 3a48682226 Replace ReadCancellationException with takeWhile
Closes gh-24125
2019-12-04 18:19:52 +00:00
Rossen Stoyanchev fcbc437825 Polishing (follow-up on acfeb7) 2019-12-02 17:14:13 +00:00
Rossen Stoyanchev 50ac8ad8b7 Fix checkstyle violation 2019-12-02 14:25:00 +00:00
Rossen Stoyanchev acfeb77d41 Polishing
See gh-23961
2019-12-02 14:12:59 +00:00
Brian Clozel d4209392d2 Allow ExchangeStrategies customizations in WebClient
Prior to this commit, developers could configure their WebClient to use
their custom `ExchangeStrategies`, by providing it in the
`WebClient.Builder` chain.
Once created, an `ExchangeStrategies` instance is not mutable, which
makes it hard for further customizations by other components. In the
case of the reported issue, other components would override the default
configuration for the codecs maxInMemorySize.

This commit makes the `ExchangeStrategies` mutable and uses that fact to
further customize them with a new `WebClient.Builder#exchangeStrategies`
`Consumer` variant. This commit is also deprecating those mutating
variants in favor of a new `WebClient.Builder#exchangeStrategies` that
takes a `ExchangeStrategies#Builder` directly and avoids mutation issues
altogether.

Closes gh-23961
2019-12-02 14:12:59 +00:00
Brian Clozel 1560bbd81e Revert "Allow ExchangeStrategies customizations in WebClient"
This reverts commit b3020bc484.
2019-12-02 10:39:53 +01:00
Juergen Hoeller 567c7695dd Polishing 2019-12-01 00:20:00 +01:00
Brian Clozel b3020bc484 Allow ExchangeStrategies customizations in WebClient
Prior to this commit, developers could configure their WebClient to use
their custom `ExchangeStrategies`, by providing it in the
`WebClient.Builder` chain.
Once created, an `ExchangeStrategies` instance is not mutable, which
makes it hard for further customizations by other components. In the
case of the reported issue, other components would override the default
configuration for the codecs maxInMemorySize.

This commit makes the `ExchangeStrategies` mutable and uses that fact to
further customize them with a new `WebClient.Builder#exchangeStrategies`
`Consumer` variant. This commit is also deprecating those mutating
variants in favor of a new `WebClient.Builder#exchangeStrategies` that
takes a `ExchangeStrategies#Builder` directly and avoids mutation issues
altogether.

Closes gh-23961
2019-11-29 22:26:52 +01:00
Rossen Stoyanchev b44daa8b71 Remove the few remaining usages of UriTemplate
Also update Javadoc of UriTemplate to point to UriComponentsBuilder and
UriBuilderFactory as more flexible options.

See gh-24094
2019-11-28 11:28:49 +00:00
Rossen Stoyanchev 70a3dbff24 WebSession creation does not block
Closes gh-24027
2019-11-26 10:48:39 +00:00
Arjen Poutsma a79eaded5d Javadoc 2019-11-25 16:23:27 +01:00
Sébastien Deleuze 6c7250b0ae Make Kotlin DSL class constructors internal
Closes gh-24059
2019-11-22 16:10:42 +01:00
Sébastien Deleuze 712eac2915 Refine Coroutines annotated controller support
This commit refines Coroutines annotated controller support
by considering Kotlin Unit as Java void and using the right
ReactiveAdapter to support all use cases, including suspending
functions that return Flow (usual when using APIs like WebClient).

It also fixes RSocket fire and forget handling and adds related tests
for that use case.

Closes gh-24057
Closes gh-23866
2019-11-22 14:13:17 +01:00
Arjen Poutsma e8b81ffc16 Improve documentation of WebClient.Builder::filter
Closes gh-23342
2019-11-20 11:55:25 +01:00
Arjen Poutsma 9f7dd9f352 Add test for usage of bodyToMono in WebClient.ResponseSpec::onStatus
See gh-23365
2019-11-19 10:22:54 +01:00
Sam Brannen d38b07b450 Move JavaUtilLoggingConfigurer to web.reactive.fixtures package 2019-11-14 15:50:04 +01:00
Sam Brannen 7991066345 Fix classpath 2019-11-14 15:25:26 +01:00
Sam Brannen 89b3a9cef2 Introduce JavaUtilLoggingConfigurer to configure JUL for tests 2019-11-14 14:30:21 +01:00
Sébastien Deleuze 6fa9871a70 Provide orNull extensions for WebFlux ServerRequest
Closes gh-23761
2019-11-13 17:59:51 +01:00
Arjen Poutsma a7a88371e7 Allow for decode method to return null in AbstractJackson2Decoder
Prior to this commit, the decoder did not allow for a null value
returned from the Jackson object reader.

Closes: gh-23935
2019-11-11 16:48:30 +01:00
Biju Kunjummen 5ee990e045 Use Function.identity
Closes gh-2024
2019-11-11 15:04:29 +00:00
Sam Brannen d03ab79531 Polish contribution
See gh-23970
2019-11-11 15:16:07 +01:00
Andy Wilkinson f7bc8c8268 Tidy up classpath pollution caused by resource creation in the tests
Previously, spring-webmvc and spring-webflux both contained tests
that would create gzipped files, write them to the filesystem
alongside the project's compiled test classes, and configure them to
be deleted on JVM exit. The output location placed the files on the
classpath, polluting it for every subsequent test that used the same
ClassLoader. The test-sources plugin combined with Gradle's use of
worker JVMs, broadens the scope of this pollution to other, downstream
projects in the same build. For example, the tests for
spring-websocket will have a different classpath depending on whether
or not the tests for spring-webmvc have already been run on the same
worker as part of the current build.

This commit updates the spring-webmvc and spring-webflux modules to
introduce a new JUnit Jupiter extension, GzipSupport. This extension
allows gzipped files to be created via an injectable GzippedFiles
class and automatically deletes each created file in an after-each
callback. This ensures that a gzipped file only exists on the
classpath for the duration of the test that needs it, avoiding the
pollution of the classpath of any subsequent tests.

Closes gh-23970
2019-11-11 15:11:10 +01:00
Rossen Stoyanchev 0e1a237139 Polishing 2019-11-08 09:17:25 +00:00
Johnny Lim 91f5f42d13 Add tests for PrincipalMethodArgumentResolver 2019-11-08 08:48:56 +00:00
Rossen Stoyanchev 203977972b Fix issue with path matching options
Closes gh-23907
2019-11-06 17:54:39 +00:00
Sam Brannen 1a13700f8b Polish contribution
See gh-23923
2019-11-06 12:57:01 +01:00
stsypanov 9da15ee23a Improve usage of String.substring()
Closes gh-23923
2019-11-06 12:57:01 +01:00
wonwoo 8855056395 Polish 2019-11-04 10:10:49 +00:00
Rossen Stoyanchev 3691c187ef Preserve order of onStatus handlers
Closes gh-23880
2019-10-31 14:13:44 +00:00
Christoph Dreis 3c17178b16 Fix Mockito deprecations 2019-10-30 18:30:05 +01:00
Stephane Nicoll 8d88e29173 Add qualified injection points for MVC and WebFlux infrastructure
Previously, the infrastructure provided by WebMvcConfigurationSupport
and WebFluxConfigurationSupport can lead to unexpected results due to
the lack of qualifier for certain dependencies. Those configuration
classes refer to very specific beans, yet their injection points do not
define such qualifiers. As a result, if a candidate exists for the
requested type, the context will inject the existing bean and will
ignore a most specific one as such constraint it not defined. This can
be easily reproduced by having a primary Validator whereas a dedicated
"mvcValidator" is expected. Note that a parameter name is in no way a
constraint as the name is only used as a fallback when a single
candidate cannot be determined.

This commit provides explicit @Qualifier metadata for such injection
points, renaming the parameter name in the process to clarify that it
isn't relevant for the proper bean to be resolved by the context.

Closes gh-23887
2019-10-30 15:07:23 +01:00
Juergen Hoeller 2861fc65bd Polishing 2019-09-27 10:17:56 +02:00
Sebastien Deleuze 091c512f0d Upgrade to Coroutines 1.3.2
Closes gh-23663
2019-09-25 21:51:04 +02:00
Sebastien Deleuze a4b278a269 Polishing 2019-09-25 17:02:05 +02:00
Andy Wilkinson 853d4c38ae Run webflux's tests in parallel to shorten long tail of builds (#23701)
When built in an environment where many Gradle build workers are
available, :spring-webflux:test is regularly the only task running at
the end of the build. Therefore, the build's overall execution time
can be reduced by running its tests in parallel, spreading the tests'
execution across the available workers. The configured number of forks
is a maximum with Gradle reducing this as necessary for environments
with low numbers of cores where multiple workers will not improve
build performance.

Closes gh-23701
2019-09-25 13:44:14 +02:00
Rossen Stoyanchev 30e1257dda Merge branch '5.1.x' 2019-09-24 13:39:42 +01:00
Sam Brannen 402046f3c7 Polish data buffer allocation tests 2019-09-24 14:24:36 +02:00
Sam Brannen 48c8d3a551 Polishing 2019-09-24 13:57:14 +02:00
Sam Brannen 38052e77b7 Fix bug in WebClientDataBufferAllocatingTests
Prior to this commit, the parameterized DataBufferFactory was never
actually used when setting up the WebClient for each test. This was due
to an oversight when migrating from JUnit 4 to JUnit Jupiter.

See: https://github.com/reactor/reactor-netty/issues/860

This commit fixes this by converting the existing @BeforeEach method to
a local setup method that is invoked from each
@ParameterizedDataBufferAllocatingTest method.

In addition, in order to avoid the 2 second "quiet period" that is
incurred when destroying the ReactorResourceFactory, this commit moves
the setup and destruction of the ReactorResourceFactory to new
@BeforeAll and @AfterAll methods.

The test instance lifecycle has also been switched to PER_CLASS to avoid
static state in the test class.
2019-09-24 13:45:50 +02:00
Rossen Stoyanchev 2794264480 Fix JettyRequestUpgradeStrategy initialization bug
Closes gh-23313
2019-09-24 11:34:46 +01:00
Sam Brannen f0e160fc67 Execute WebClientDataBufferAllocatingTests during all builds
This commit reverts b2704e1db6 and
configures the ReactorResourceFactory not to use global resources,
thereby allowing all tests in WebClientDataBufferAllocatingTests to
execute within approximately 2 seconds again on Mac OS.
2019-09-20 14:09:00 +02:00
Sam Brannen b2704e1db6 Execute WebClientDataBufferAllocatingTests only during PERFORMANCE build 2019-09-19 18:35:35 +02:00
Brian Clozel 74897bc52a Use Reactor's new Schedulers.boundedElastic()
Prior to this commit, Spring Framework would use `Schedulers.elastic()`
in places where we needed to process blocking tasks in a reactive
environment.

With reactor/reactor-core#1804, a new `Schedulers.boundedElastic()`
scheduler is available and achieves the same goal with added security;
it guarantees that resources are bounded.

This commit uses that new scheduler in the standard websocket client,
since the underlying API is blocking for the connection phase and we
need to schedule that off a web server thread.

Closes gh-23661
See gh-23665
2019-09-18 21:39:45 +02:00
Sebastien Deleuze 1dfe304da4 Improve parity between Java and Kotlin router DSL
This commit adds following functions to the Kotlin DSL:
add, filter, before, after and onError.

Closes gh-23524
2019-09-17 12:42:48 +02:00
Sebastien Deleuze 5a0216d657 Improve parity between Java and Kotlin router DSL
This commit adds variants with pattern + predicate to
Kotlin router DSLs, and vararg where necessary.

Closes gh-23524
2019-09-16 22:14:55 +02:00
Sam Brannen e7b2c93ede Delete dead code 2019-09-16 13:56:01 +02:00
Phillip Webb d945ae9191 Add blank line between java and javax imports
See gh-23539

Co-authored-by: Sam Brannen <sbrannen@pivotal.io>
2019-09-16 13:41:59 +02:00
Rossen Stoyanchev b587003d8d Merge branch '5.1.x' 2019-09-12 21:52:41 +01:00
Rossen Stoyanchev f259fda8eb Fix checkstyle violations 2019-09-12 21:46:42 +01:00
Rossen Stoyanchev 7194261961 Merge branch '5.1.x' 2019-09-12 21:17:00 +01:00
Rossen Stoyanchev 6eb0e9e44b Unwrap decorated request or response
Closes: gh-23598
2019-09-12 13:42:12 +01:00
Sebastien Deleuze 5bb8c47b14 Rename fromObject to fromValue in BodyInserters
Closes gh-23587
2019-09-09 00:08:55 +02:00
Sam Brannen 5d5f9aceca Avoid accidental usage of JUnit 4 assumptions
This commit also avoids starting a server if an assumption fails.
2019-09-06 16:03:36 +02:00
Sam Brannen ef50777535 Polishing 2019-09-05 13:45:38 +02:00
Sam Brannen d9e3b8b9a5 Introduce default constructor in TomcatHttpServer 2019-09-05 13:45:38 +02:00
Sebastien Deleuze 40a55b412d Rename BodyBuilder#bodyAndAwait to bodyValueAndAwait 2019-09-05 13:34:11 +02:00
Phillip Webb deba2ed1b3 Add blank line between java and javax imports
See gh-23539
2019-09-04 22:05:46 -07:00
Sam Brannen 803643559a Merge branch '5.1.x' 2019-09-04 16:24:44 +02:00
Sam Brannen d036b5a283 Do not treat void and Void as simple types in BeanUtils
Prior to this commit, the isSimpleProperty() and isSimpleValueType()
methods in BeanUtils treated void and Void as simple types; however,
doing so does not make sense in this context, since void implies the
lack of a property or value.

This commit addresses this by explicitly excluding void and Void in the
logic in isSimpleValueType().

This commit also simplifies the implementation of
ViewResolutionResultHandler.supports(HandlerResult) to take advantage
of this change.

Closes gh-23573
2019-09-04 15:48:40 +02:00
Juergen Hoeller 48934cba1b Polishing 2019-09-04 12:19:08 +02:00
Sebastien Deleuze 9b33b0ad58 Rename CoroutinesUtils#invokeHandlerMethod to invokeSuspendingFunction 2019-09-03 23:41:53 +02:00
Sam Brannen 1c5b949df0 Fix ViewResolutionResultHandlerTests
See gh-23572
2019-09-03 16:56:50 +02:00