Commit Graph

4846 Commits

Author SHA1 Message Date
Arjen Poutsma e6f638132c Create case-insensitive copy in RestClientResponseException
Closes gh-31978
2024-01-09 12:11:02 +01:00
Stéphane Nicoll 1f2d29ee08 Polish 2024-01-08 17:12:33 +01:00
Sébastien Deleuze cffc8835c6 Mention parameter-names in Jackson2ObjectMapperBuilder documentation
Closes gh-31959
2024-01-08 14:59:02 +01:00
Sébastien Deleuze bd66763f26 Polishing
See gh-28546
2024-01-08 12:27:37 +01:00
rstoyanchev 8552e149b5 Improve method validation for container elements
This change moves container element properties from ParameterErrors
to base class ParameterValidationResult, and makes that support
independent of whether violations are nested within a container
element bean or through constraints on container elements, e.g.
`List<@NotBlank String>`.

Closes gh-31887
2024-01-05 16:32:14 +00:00
rstoyanchev e0d6b69195 Update contribution
Closes gh-30300
2024-01-04 14:53:13 +00:00
Yanming Zhou a3532bfccc ResponseStatusException reason as message code for ProblemDetail
See gh-30300
2023-04-06 17:18:27 +08:00
Sébastien Deleuze 318d460256 Add CORS support for Private Network Access
This commit adds CORS support for Private Network Access
by adding an Access-Control-Allow-Private-Network response
header when the preflight request is sent with an
Access-Control-Request-Private-Network header and that
Private Network Access has been enabled in the CORS
configuration.

See https://developer.chrome.com/blog/private-network-access-preflight/
for more details.

Closes gh-28546
2024-01-05 20:07:51 +01:00
Fabrice Bibonne a108e701bc Add Javadoc for use of regexp PathPattern
Closes gh-31886
2024-01-05 14:47:45 +01:00
Brian Clozel 1372265bd9 Undo workaround for SameSite support in WebFlux
This commit implements Cookie support in WebFlux without any workaround
as now all supported servers have the SameSite feature enabled.

Closes gh-31954
2024-01-05 14:44:32 +01:00
Stéphane Nicoll 549f6c1e80 Polish "Fix references to "application/*+xml" in Javadoc"
See gh-31951
2024-01-05 06:44:14 +01:00
pri88yank 16b4c25f7d Fix references to "application/*+xml" in Javadoc
See gh-31951
2024-01-05 06:44:02 +01:00
Stéphane Nicoll 2784f6008e Only log status in ServletRequestHandledEvent
This commit updates the description of RequestHandledEvent to avoid
providing a misleading status as the absence of a failure logs OK which
can be inaccurate.

Closes gh-27595
2024-01-04 11:47:59 +01:00
Sébastien Deleuze 207b9a14f4 Improve the documentation and discoverability of CoWebFilter
Closes gh-31877
2024-01-03 17:50:22 +01:00
Brian Clozel f846d9484c Add Javadoc to MockHttpServletResponse
This commit adds Javadoc to the `getContentLength` method of
`MockHttpServletResponse` to reflect that it gets its value from the
HTTP response header.

Closes gh-31833
2024-01-03 15:19:53 +01:00
Sam Brannen a3c11fc033 Clean up warnings in tests in Gradle build 2024-01-02 16:44:52 +01:00
Stéphane Nicoll e22d1efdc0 Update copyright year of changed files
See gh-31930
2024-01-01 11:00:56 +01:00
Johnny Lim ff8097d37c Polish
See gh-31930
2024-01-01 10:59:35 +01:00
Stéphane Nicoll 3c5d46166e Polish "Replace if with switch where feasible"
See gh-31916
2023-12-28 13:33:32 +01:00
Yanming Zhou cfa3aa001f Replace if with switch where feasible
See gh-31916
2023-12-28 13:29:50 +01:00
Stéphane Nicoll a6e87b40c7 Polish "Use diamond operator where feasible"
See gh-31916
2023-12-28 13:14:26 +01:00
Yanming Zhou 094479b55f Use diamond operator where feasible
See gh-31916
2023-12-28 13:08:08 +01:00
Stéphane Nicoll ed1bfb8177 Polish "Use text block where feasible"
See gh-31916
2023-12-28 13:01:44 +01:00
Yanming Zhou a35384fd57 Use text block where feasible
See gh-31916
2023-12-28 13:01:44 +01:00
Stéphane Nicoll 9d31537ae5 Polish "Use String.repeat() where feasible"
See gh-31916
2023-12-28 13:01:44 +01:00
Yanming Zhou dee1b726f9 Use String.repeat() where feasible
See gh-31916
2023-12-28 13:01:44 +01:00
Yanming Zhou 45080e3724 Remove unnecessary final modifier
final is useless for private and static methods

See gh-31916
2023-12-28 13:01:43 +01:00
Juergen Hoeller a338a16b29 Polishing 2023-12-27 23:23:38 +01:00
Brian Clozel 4afac17e58 Reject invalid forwarded requests in ForwardedHeaderFilter
Prior to this commit, the `ForwardedHeaderFilter` and the forwarded
header utils would throw `IllegalArgumentException` and
`IllegalStateException` when request headers are invalid and cannot be
parsed for Forwarded handling.

This commit aligns the behavior with the WebFlux counterpart by
rejecting such requests with HTTP 400 responses directly.

Fixes gh-31842
2023-12-22 17:27:06 +01:00
Juergen Hoeller 232225b2aa Polishing 2023-12-22 13:06:29 +01:00
Stéphane Nicoll cd8bc2f82a Remove useless empty inheritDoc Javadoc tag 2023-12-22 11:23:11 +01:00
rstoyanchev f0add920f5 Adjust container types to which methodValidation
After the updates to MethodValidationAdapter in commit d7ce13 related
to method validation on element containers, we also need to adjust
the checks in HandlerMethod when method validation applies.

See gh-31746
2023-12-21 17:50:40 +00:00
rstoyanchev 33c149077a Check constraints on container elements
We now check for constraint annotations on elements of a
container to decide whether to apply method validation.

Closes gh-31870
2023-12-21 17:35:19 +00:00
Sam Brannen 3476402a75 Polish switch statements 2023-12-21 17:30:56 +01:00
Juergen Hoeller b04803de99 Polishing 2023-12-21 17:20:29 +01:00
Sébastien Deleuze 85cb6cc5fb Support Kotlin extensions in web handlers
This commit restores support for Kotlin extensions in
web handlers, and adds support for invoking reflectively
suspending extension functions, as well as the other
features supported as of Spring Framework 6.1 like
value classes and default value for parameters.

Closes gh-31876
2023-12-21 12:16:33 +01:00
Brian Clozel 53b937976d Reject setups with multiple observation conventions
Prior to this commit, the `WebHttpHandlerBuilder` would only configure
a custom observation convention if there is a single convention in the
application context. It would other wise use the default.

This commit aligns with the previous Spring Boot behavior where multiple
conventions setups are rejected as invalid with
`NoUniqueBeanDefinitionException`.

Fixes gh-31864
2023-12-19 17:35:02 +01:00
Sébastien Deleuze 12f01f9b5f Add support for @RequestMapping on Kotlin property accessors
This commit refines InvocableHandlerMethod (both Servlet and
Reactive variants) in order to support annotated property
accessors as they translate into regular Java methods, instead
of throwing a NullPointerException.

Closes gh-31856
2023-12-19 12:29:55 +01:00
Sébastien Deleuze 917978cbc2 Refactor InvocableHandlerMethodKotlinTests
The variant in org.springframework.web.method.support in
order to allow testing with a various classes.

See gh-31856
2023-12-19 12:10:13 +01:00
rstoyanchev 3f5c3b1747 Fix checkstyle violation
See gh-31711
2023-12-18 15:32:18 +00:00
rstoyanchev bec7210b4b Improve check to skip bean validation in DataBinder
DataBinder should skip any jakarta.validation.Validator yielding
to method validation when that is expected. This change improves
the check to skip by unwrapping the validator from in a
SmartValidator before checking if it is for bean validation.

Closes gh-31711
2023-12-18 15:25:18 +00:00
rstoyanchev 0a94dce41d Improve HandlerMethod check when method validation applies
Method validation needs to be used for a container such as a List or
Map, but until now we were only checking for a List container.
Moreover, in gh-31530 we improved method validation to also cover
any Collection.

This change aligns with HandlerMethod check for when method validation
applies with the underlying ability of method validation.
2023-12-18 15:25:18 +00:00
Juergen Hoeller 045c5dc1b4 Detect Jetty 12 "max length exceeded" message in handleParseFailure
Closes gh-31850
2023-12-18 16:18:27 +01:00
Stéphane Nicoll d0574197ea Polish "Use String.repeat instead of explicit cycle"
See gh-31802
2023-12-18 14:10:16 +01:00
Adam Ostrožlík 63b2787da6 Use String.repeat instead of explicit cycle
See gh-31802
2023-12-18 13:54:03 +01:00
rstoyanchev ec0ec7a0d6 Avoid nested constructor binding if there are no request parameters
Closes gh-31821
2023-12-13 18:06:16 +00:00
Brian Clozel 0970b1dc7a Optimize ContentCachingRequestWrapper allocation
This commit builds on top of changes made in gh-29775 and gh-31737.
Before this change, we would allocate several byte arrays even in cases
of known request size. This could decrease performance when getting the
cached content as it requires merging several arrays and data is not
colocated in memory.

This change ensures that we create a `FastByteArrayOutputStream`
instance with the known request size so that the first allocated segment
can contain the entire content.
If the request size is not know, we will default back on the default
allocation size for the `FastByteArrayOutputStream`.

Closes gh-31834
2023-12-13 18:47:32 +01:00
rstoyanchev 125e2902be Polishing contribution
Closes gh-31778
2023-12-12 16:01:23 +00:00
HeartPattern 4d838c1092 Exclude Part from nested constructor binding in WebFlux
See gh-31778
2023-12-12 16:01:23 +00:00
Sam Brannen c0683cd30b Update copyright headers 2023-12-12 14:51:03 +01:00
Juergen Hoeller 7adc2f0779 Upgrade to Tomcat 10.1.16 and Jetty 12.0.4 2023-12-12 14:26:56 +01:00
Arjen Poutsma 134bb6e31f Document exception wrapping in RestClient status handlers
This commit documents the fact that any (Unchecked)IOExceptions or
HttpMessageNotReadableExceptions thrown from the error handler will be
wrapped in a RestClientException.

Closes gh-31783
2023-12-12 13:34:16 +01:00
Arjen Poutsma 57b8100a06 Copy headers map in RestClientResponseException to ensure serializability
This commit ensures that the HttpHeaders used are serializable by making
 a copy.

Closes gh-31787
2023-12-11 14:02:31 +01:00
Sébastien Deleuze d75a7c3818 Support multiple CoWebFilter changing the context
This commit ensures CoWebFilter merges the exchange
CoroutineContext with the filter one if needed.

Closes gh-31792
2023-12-11 11:35:19 +01:00
Sébastien Deleuze 91b9a75371 Box Kotlin value class parameters in web endpoint
In order to avoid "java.lang.IllegalArgumentException:
object is not an instance of declaring class" errors.

Closes gh-31698
2023-12-08 15:27:08 +01:00
Rossen Stoyanchev 2e07f9ab33 DefaultWebClient exposes full URI template as request attribute
Closes gh-30027
2023-12-07 12:16:22 +00:00
Sam Brannen 438c3818cc Replace System.getProperties().remove(x) with System.clearProperty(x)
This commit migrates to the not-so-new System.clearProperty() method
introduced in Java 1.5.
2023-12-06 17:11:46 +01:00
Sébastien Deleuze d410872e4f Polish CookieIntegrationTests 2023-12-06 15:01:09 +01:00
Sébastien Deleuze 8fe2c780df Support cookies with the same name with Reactor Netty
Ignore the related test with Undertow due to a bug in
their cookies handling.

Closes gh-28490
2023-12-06 15:01:09 +01:00
Arjen Poutsma 0e6c17f518 Process tokens after each feed in Jackson2Tokenizer
This commit ensures that we process after each fed buffer in
Jackson2Tokenizer, instead of after all fed buffers.

Closes gh-31747
2023-12-06 14:31:05 +01:00
Arjen Poutsma ef4ffa0005 Support empty part in DefaultPartHttpMessageReader
This commit fixes a bug in DefaultPartHttpMessageReader's
MultipartParser, due to which the last token in a part window was not
properly indicated.

Closes gh-30953
2023-12-06 12:21:37 +01:00
Yanming Zhou afcd03bddc Replace assertThat(x.isEmpty()).isTrue() with assertThat(x).isEmpty()
Search for   : assertThat\((.+).isEmpty\(\)\).isTrue\(\)
Replace with : assertThat($1).isEmpty()

Search for   : assertThat\((.+).isEmpty\(\)\).isFalse\(\)
Replace with : assertThat($1).isNotEmpty()

Closes gh-31758
2023-12-06 10:04:56 +01:00
Yanming Zhou 7b16ef90f1 Replace assertThat(x.equals(y)) with assertThat(x).isEqualTo(y)
Search for   : assertThat\((.+)\.equals\((\w+)\)\)\.isTrue\(\)
Replace with : assertThat($1).isEqualTo($2)

Search for   : assertThat\((.+)\.equals\((\w+)\)\)\.isFalse\(\)
Replace with : assertThat($1).isNotEqualTo($2)

Closes gh-31763
2023-12-06 09:50:15 +01:00
Yanming Zhou 59815cefce Replace assertThat(x.get(i)). with assertThat(x).element(i).
Search for   : assertThat\((.+)\.get\((\d+)\)\)\.
Replace with : assertThat($1).element($2).

Closes gh-31759
2023-12-06 09:43:59 +01:00
Sam Brannen c74d60b9fe Polishing 2023-12-05 16:14:13 +01:00
Sam Brannen db48813181 Polish contribution
See gh-31757
2023-12-05 16:14:13 +01:00
Yanming Zhou 6f11716b6f Use idiomatic AssertJ map assertions
See gh-31752
2023-12-05 10:01:38 +01:00
Sam Brannen 62b3d7a963 Update copyright headers 2023-12-04 16:47:25 +01:00
Yanming Zhou 490b5c77fc Use switch expression where feasible 2023-12-04 15:42:55 +01:00
Patrick Strawderman 7cdacf3083 Introduce toString(Charset) in FastByteArrayOutputStream
This commit introduces a toString() overload in
FastByteArrayOutputStream that accepts a Charset in order to mirror the
method that was introduced in ByteArrayOutputStream in JDK 10,
including a special case for when a single buffer is in use internally
to avoid the need to resize.

This commit also updates getContentAsString() in
ContentCachingRequestWrapper to use this new toString(Charset) method.

Closes gh-31737
2023-12-02 16:31:28 +01:00
Sam Brannen 47cdc7c5f0 Update copyright headers
See gh-31738
2023-12-02 15:32:46 +01:00
dogglezz decb22a93d Polish Javadoc
Closes gh-31738
2023-12-02 15:31:39 +01:00
Arjen Poutsma d204dd2dbe Use IntrospectingClientHttpResponse in RestClient
This commit ensures that the RestClient uses the
IntrospectingClientHttpResponse to verify whether the response has a
body, and return null if it does not.

See gh-12671
Closes gh-31719
2023-12-01 14:22:58 +01:00
Patrick Strawderman e452c2e89c Avoid byte array copy in getContentAsString
The getContentAsString method was originally added in d9b8826 to avoid
the extra copying inherent to calling ByteArrayOutputStream.toByteArray;
however, in f83c609 the class was updated to instead use
FastByteArrayOutputStream, and in the process the extra copy was brought
back when getContentAsString was changed to call toByteArray.

Switch to calling toByteArrayUnsafe, a method provided by
FastByteArrayOutputStream, which avoids the extra copy; since we
immediately pass the byte array to the String constructor, and it isn't
accessed anywhere else, the usage is safe.

See gh-31731
2023-12-01 10:47:38 +01:00
Sam Brannen 6ea9fdbf77 Polishing 2023-11-30 19:04:59 +01:00
rstoyanchev 8090a52f5c ForwardedHeaderFilter supports ERROR requestUri attribute
Closes gh-30828
2023-11-30 13:10:17 +00:00
rstoyanchev 19bca03aa2 Polishing in ForwardedHeaderFilter
See gh-30828
2023-11-30 13:10:17 +00:00
rstoyanchev 8ca82120e0 Add missing exception name to DisconnectedClientHelper
Closes gh-31717
2023-11-30 13:10:17 +00:00
rstoyanchev 9ade52dbe2 Exclude Part and MultipartFile from nested constructor binding
Closes gh-31669
2023-11-30 13:10:17 +00:00
Brian Clozel 35fcbae8c6 Fix reactive HTTP server Observation instrumentation
Prior to this commit, regressions were introduced with gh-31417:

1. the observation keyvalues would be inconsistent with the HTTP response
2. the observation scope would not cover all controller handlers, causing
  traceIds to be missing

The first issue is caused by the fact that in case of error signals, the
observation was stopped before the response was fully committed, which
means further processing could happen and update the response status.
This commit delays the stop event until the response is committed in
case of errors.

The second problem is caused by the change from a `contextWrite`
operator to using the `tap` operator with a `SignalListener`. The
observation was started in the `doOnSubscription` callback, which is too
late in some cases. If the WebFlux controller handler is synchronous
non-blocking, the execution of the handler is performed before the
subscription happens. This means that for those handlers, the
observation was not started, even if the current observation was
present in the reactor context. This commit changes the
`doOnSubscription` to `doFirst` to ensure that the observation is
started at the right time.

Fixes gh-31703
Fixes gh-31706
2023-11-29 14:39:56 +01:00
Sam Brannen 657b1c6455 Document need for -parameters flag in exception messages
Closes gh-31675
2023-11-25 14:53:56 +01:00
Stéphane Nicoll 487dbf8140 Polish "Polish RestClient Javadoc"
See gh-31659
2023-11-23 12:59:03 +01:00
johannesrost e95f8d2922 Polish RestClient Javadoc
See gh-31659
2023-11-23 12:38:16 +01:00
Brian Clozel d50b51e312 Fix ordering of releasing resources in JSON Encoder
Prior to this commit, the Jackson 2.x encoders, in case of encoding a
stream of data, would first release the `ByteArrayBuilder` and then the
`JsonGenerator`. This order is inconsistent with the single value
variant (see `o.s.h.codec.json.AbstractJackson2Encoder#encodeValue`) and
invalid since the `JsonGenerator` uses internally the
`ByteArrayBuilder`.

In case of a CSV Encoder, the codec can buffer data to write the column
names of the CSV file. Writing an empty Flux with this Encoder would not
fail but still log a NullPointerException ignored by the reactive
pipeline.

This commit fixes the order and avoid such issues at runtime.

Fixes gh-30493
2023-11-22 18:21:06 +01:00
Sébastien Deleuze 441e210533 Treat kotlin.Unit as void in web controllers
This commit fixes a regression introduced by gh-21139
via the usage of Kotlin reflection to invoke HTTP
handler methods. It ensures that kotlin.Unit is treated
as void by returning null.

It also polishes CoroutinesUtils to have a consistent
handling compared to the regular case, and adds related
tests to prevent future regressions.

Closes gh-31648
2023-11-22 13:45:03 +01:00
Arjen Poutsma e6ab8a6d61 Remove attributes from RestClient
This commit removes any references to attributes from RestClient, which
were left by mistake.

Closes gh-31625
2023-11-21 16:12:06 +01:00
Juergen Hoeller 99378fe947 Polishing 2023-11-16 11:22:09 +01:00
Brian Clozel c02f735056 Merge branch '6.0.x' 2023-11-16 09:04:09 +01:00
Brian Clozel c18784678d Reduce allocations in server conventions
This commit optimizes the default observation conventions to reduce
`KeyValues` allocations.
2023-11-16 09:00:24 +01:00
Stéphane Nicoll f15b8b95ad Merge branch '6.0.x' 2023-11-15 19:04:11 +01:00
Stéphane Nicoll 4464251754 Add missing runtime hints for ProblemDetail mixins
Closes gh-31606
2023-11-15 18:44:17 +01:00
Arjen Poutsma 8f21479234 Add body conversion capabilities in RestClient::exchange
This commit introduces a ConvertibleClientHttpResponse type that
extends ClientHttpResponse, and that can convert the body to a desired
type. Before this commit, it was not easy to use the configured HTTP
message converters in combination with RestClient::exchange.

Closes gh-31597
2023-11-14 11:18:59 +01:00
Stéphane Nicoll 7f615fd8af Fix reference in deprecation message of parseForwardedFor 2023-11-11 18:05:36 +01:00
Sébastien Deleuze 38724a1205 Fix RestClient generic type handling
For client side use case, the context class should be null,
consistently with what is done in HttpMessageConverterExtractor.

Closes gh-31574
2023-11-09 08:50:31 +01:00
rstoyanchev ba4d459f81 Merge branch '6.0.x' 2023-11-08 11:47:18 +00:00
rstoyanchev 5c012bbb0c Set maxAge correctly when expiring WebSession
Closes gh-31214
2023-11-08 11:44:36 +00:00
Stéphane Nicoll d34b3c1a71 Merge branch '6.0.x' 2023-11-08 08:04:27 +01:00
Johnny Lim cafb38ad1d Add Javadoc since to ProblemDetail.setProperties()
See gh-31571
2023-11-08 08:02:57 +01:00
Arjen Poutsma 5afb00d270 Merge branch '6.0.x' 2023-11-07 15:10:59 +01:00
Arjen Poutsma dc26d3b0ec Defer cleanup in DefaultServerWebExchange
This commit ensures that the multipartRead flag is read in a deferred
block, and is not evaluated too early.

Closes gh-31567
2023-11-07 15:00:20 +01:00