Commit Graph

4967 Commits

Author SHA1 Message Date
Arjen Poutsma 0241a02e66 Fix guard against multiple subscriptions
This commit changes the guard against multiple subscriptions, as the
previously used doOnSubscribe hook could not function as guard in
certain scenarios.

Closes gh-32727
2024-04-30 16:07:03 +02:00
Juergen Hoeller 09b476ac18 Polishing 2024-04-24 13:42:02 +02:00
Juergen Hoeller 580adfcbed Polishing 2024-04-23 16:07:09 +02:00
Stéphane Nicoll 95ac0eae4a Update copyright year of changed files
See gh-32696
2024-04-23 15:32:59 +02:00
Johnny Lim cc73ccefef Polish
See gh-32696
2024-04-23 15:31:48 +02:00
Juergen Hoeller d4ddbd537b Polishing 2024-04-23 13:16:33 +02:00
Brian Clozel 5aa576f5c6 Register status handler exceptions in observations
Prior to this commit, `RestClientException` thrown by status handlers
would not be registered as observation errors. This commit ensures that
such exceptions are first caught, registered in the observation and
rethrown as expected.

Closes gh-32575
2024-04-20 19:44:11 +02:00
Brian Clozel da4547a27e Extend observations to RestClient ResponseSpec
Prior to this commit, the `RestClient` observations would be stopped as
soon as the exchange function was called. This means that all errors
related to response decoding or mapping would not be recorded by the
obsevations.

This commit extends the observation recording to the `ResponseSpec` DSL
calls as well as custom exchange functions.

Fixes gh-32575
2024-04-18 21:26:18 +02:00
yhao3 7f27ba3902 Update links to HttpOnly documentation at OWASP in ResponseCookie
Closes gh-32663
2024-04-18 11:52:50 +02:00
Brian Clozel b3a45670f9 Do not set 0 Content-Length header in BufferingClientHttpRequestFactory
Prior to this commit, the `BufferingClientHttpRequestFactory`, through
the `AbstractBufferingClientHttpRequest`, would set a "Content-Length"
header value, even if the buffered body was empty.

This behavior is invalid since no request body would be set by the
client code in the first place.

This commit ensures that this header is only set if a request body has
been buffered and is about to be written to the request.

Fixes gh-32650
2024-04-17 22:44:36 +02:00
Simon Baslé 1e54916119 Ensure multipart data is deleted in WebFlux when connection terminates
Before this change temporary files would not consistently be deleted
when the connection which uploads the multipart files closes naturally.

This change uses the usingWhen Reactor operator to ensure that the
termination of the connection doesn't prevent individual file parts
from being deleted due to a cancellation signal.

Closes gh-31217
2024-04-15 14:20:48 +02:00
Brian Clozel 494ed4e852 Refine UriComponentsBuilder parsing
This commit refines the expressions for the scheme, user info, host and
port parts of the URL in UriComponentsBuilder to better conform to
RFC 3986.

Fixes gh-32616
2024-04-11 08:49:11 +02:00
Juergen Hoeller 39cd31613b Polishing 2024-04-10 18:06:32 +02:00
Brian Clozel 019ce4418c BufferingClientHttpRequestWrapper should not write empty body
Prior to this commit, `BufferingClientHttpRequestWrapper` would always
write to the actual client request body, even if the buffered content
was empty (empty byte array).
This would cause issues with specific client request factories,
especially the OkHttp variant, that would consider empty byte arrays as
non-empty body and would reject such cases for GET requests with an
"IllegalArgumentException: method GET must not have a request body".

This commit only writes to the request if the buffered content is not
empty.

Fixes gh-32612
2024-04-10 16:41:16 +02:00
rstoyanchev 8d05028c2e RequestParam resolver supports empty array suffix
Closes gh-32577
2024-04-09 18:24:57 +01:00
rstoyanchev 4a68c44a27 Update content-length when reconstructing body
Closes gh-32471
2024-04-09 18:24:57 +01:00
Juergen Hoeller 07472758ee Detect Undertow RequestTooBigException message in handleParseFailure
Closes gh-32549
2024-04-05 18:03:44 +02:00
Arjen Poutsma 47c9c7eb07 Update copyright
See gh-32528
2024-04-05 16:13:39 +02:00
Arjen Poutsma b24221754a ReactorNettyClientResponse should close response body
This commit ensures that the response body is drained and closed when
the response itself is closed, instead of disposing the connection, as
this will disable the connection pool.

Closes gh-32528
2024-04-05 15:38:18 +02:00
Sébastien Deleuze 7a666cfd86 Revert some null-safety changes
This commit reverts some null-safety changes which make sense
on main but are too impactful for 6.1.x for Kotlin developers
using -Xjsr305=strict.

See gh-32475
2024-04-05 14:59:39 +02:00
Sébastien Deleuze 048e4f0aa2 Invoke KCallablesJvm.setAccessible only when required
Closes-32536
2024-03-28 11:12:50 +01:00
T45K b28153e1d7 Fix handling of value class with private constructor
See gh-32536
2024-03-28 11:11:58 +01:00
Sébastien Deleuze 290a41d398 Refine null-safety in more modules
This commit refines the null-safety in all remaining modules
except spring-test.

See gh-32475
2024-03-26 15:39:18 +01:00
Sébastien Deleuze a63ebe7e9d Refine null-safety in spring-web and spring-websocket
See gh-32475
2024-03-25 11:02:44 +01:00
Johnny Lim dca5f1dcd8 Add Javadoc since to KotlinSerializationStringEncoder.setStreamingMediaTypes()
See gh-32517
2024-03-24 09:21:36 +01:00
Sébastien Deleuze 1e80694daf Fix a regression with Kotlin generic controllers
This commit reintroduces a more defensive parameter type check that
skips KClass casting for generic parameters.

Closes gh-32510
2024-03-21 17:55:57 +01:00
Sam Brannen ef02f0bad8 Wrap InvalidMimeTypeException in HttpMediaTypeNotAcceptableException
The fix for #31254 resulted in an InvalidMimeTypeException being thrown
by MimeTypeUtils.sortBySpecificity() instead of an
IllegalArgumentException. However, InvalidMimeTypeException extends
IllegalArgumentException. Consequently, the change from
IllegalArgumentException to InvalidMimeTypeException did not result in
the desired effect in HeaderContentNegotiationStrategy.

HeaderContentNegotiationStrategy.resolveMediaTypes() still allows the
InvalidMimeTypeException to propagate as-is without wrapping it in an
HttpMediaTypeNotAcceptableException.

To address this issue, this commit catches InvalidMediaTypeException
and InvalidMimeTypeException in HeaderContentNegotiationStrategy and
wraps the exception in an HttpMediaTypeNotAcceptableException.

See gh-31254
See gh-31769
Closes gh-32483
2024-03-19 15:51:27 +01:00
Sam Brannen 836a0b3a40 Polishing 2024-03-19 14:19:01 +01:00
Juergen Hoeller c531a8a705 Nullability refinements and related polishing
See gh-32475
2024-03-19 09:58:44 +01:00
Johnny Lim d50c94fca9 Add Javadoc since to AbstractClientHttpRequestFactoryWrapper.getDelegate()
See gh-32474
2024-03-18 14:08:59 +01:00
Juergen Hoeller eb8b7c4331 Remove superfluous @NonNull declarations 2024-03-16 14:22:17 +01:00
rstoyanchev 381f790329 Extract reusable checkSchemeAndPort method
Closes gh-32440
2024-03-14 08:45:38 +00:00
Juergen Hoeller 54a6d89da7 Additional unit tests for operations on empty UriTemplate
See gh-32432
2024-03-13 18:06:17 +01:00
Stéphane Nicoll a34ceb405c Polish "Allow UriTemplate to be built with an empty template"
See gh-32432
2024-03-13 17:21:46 +01:00
Kasper Bisgaard 1b25a1506a Allow UriTemplate to be built with an empty template
See gh-32432
2024-03-13 17:20:08 +01:00
Stéphane Nicoll 88b3844d9b Fix default value in ReactorNettyClientRequestFactory#setExchangeTimeout
Closes gh-32419
2024-03-12 08:13:42 +01:00
Sébastien Deleuze 80f3be6577 Replace getJvmErasure by getClassifier
Should be slightly faster.

See gh-32334
2024-03-11 13:37:41 +01:00
Sam Brannen b4e743614e Restore link to Jakarta Servlet issue tracker 2024-03-09 16:30:14 +01:00
Stéphane Nicoll 4983a802a7 Polish "Fix Javadoc"
See gh-32403
2024-03-09 16:02:01 +01:00
Maksim Sasnouski abdccffa39 Fix Javadoc
This commit fixes various Javadoc issues across the code base.

See gh-32403
2024-03-09 16:02:00 +01:00
Yanming Zhou 0e279fe666 Polishing
Closes gh-32397
2024-03-08 09:25:03 +01:00
Sébastien Deleuze c1d4b610ca Refine Kotlin inline class optimizations
Closes gh-32334
2024-03-07 11:11:20 +01:00
rstoyanchev 5f601ceb45 Mark response errors from @ExceptionHandler as handled
Also fix a couple of related issues:
- add AsyncRequestNotUsableException to the list of exceptions
that imply response issues.
- handle exceptions from @ExceptionHandler regardless of whether
thrown immediately or via Publisher.

Closes gh-32359
2024-03-06 18:17:13 +00:00
rstoyanchev ef0717935b Test wrapping of response for async request
The following adjustments are also made as a result:
- Use int to check if lock is held and unlock is needed, given that
for non-async requests we don't need to obtain a lock.
- Protect access methods getOutputStream and getWriter with the
same locking and state checks.

Closes gh-32340
2024-03-05 11:42:03 +00:00
rstoyanchev 822e2447a0 Polishing StandardServletAsyncWebRequestTests
See gh-32340
2024-03-05 11:42:03 +00:00
Juergen Hoeller e9110c0729 Polishing 2024-03-04 22:48:52 +01:00
Sébastien Deleuze 7493ce86b6 Fix ServletResponseHttpHeaders#get null handling
ServletResponseHttpHeaders#get should be annotated with `@Nullable` and
return null instead of a singleton list containing null when there is no
content type header.

Closes gh-32362
2024-03-04 14:43:09 +01:00
Sébastien Deleuze ce9dc19a3c Optimize content type parsing
This commit avoids calling HttpHeaders#getContentType multiple times in
ServletServerHttpResponse#writeHeaders.

Closes gh-32361
2024-03-04 14:43:09 +01:00
rstoyanchev 4b96cd28c0 Add locking in ServletResponse#flushBuffer
In addition to using the ServletOutputStream, it's also possible to call
ServletResponse#flushBuffer, so the ServletOutputStream wrapper logic needs
to apply there as well.

See gh-32340
2024-03-04 13:35:46 +00:00
Sébastien Deleuze 516a203703 Support nullable Kotlin value class arguments
This commit skips the value class parameter instantiation for nullable
types when a null argument is passed.

Closes gh-32353
2024-03-03 22:26:21 +01:00
rstoyanchev 877e0b1483 Improve concurrent handling of result in WebAsyncManager
1. Use state transitions
2. Increase synchronized scope in setConcurrentResultAndDispatch

See gh-32340
2024-03-03 20:44:52 +00:00
rstoyanchev 379ffac508 Add state and response wrapping to StandardServletAsyncWebRequest
The wrapped response prevents use after AsyncListener onError or completion
to ensure compliance with Servlet Spec 2.3.3.4.

The wrapped response is applied in RequestMappingHandlerAdapter.

The wrapped response raises AsyncRequestNotUsableException that is now
handled in DefaultHandlerExceptionResolver.

See gh-32340
2024-03-03 20:44:36 +00:00
Sébastien Deleuze 227e75dae4 Support nullable Kotlin value class arguments
This commit refines WebMVC and WebFlux argument resolution in order to
convert properly Kotlin value class arguments by using the type of the
value instead of the type of the value class.

Closes gh-32353
2024-03-01 16:38:26 +01:00
Sébastien Deleuze 85a781d517 Instantiate value class parameters with Kotlin reflection
In order to invoke the init block and to improve the maintainability.

Closes gh-32324
2024-03-01 11:50:19 +01:00
Arjen Poutsma 33705516ff Polishing external contribution
See gh-32318
2024-02-29 15:51:29 +01:00
Patrick Strawderman beb415dfa3 Optimize HttpHeaders.getAcceptLanguageAsLocales
The HttpHeaders.getAcceptLanguageAsLocales was incurring overhead from
using a Stream, as well as calling the fairly expensive
Locale.getDisplayName method.

Switch to using an ArrayList, and skipping over wildcard ranges to avoid
needing to check the display name.

Closes gh-32318
2024-02-29 15:36:55 +01:00
Juergen Hoeller 154ca54c9f Polishing 2024-02-28 21:40:08 +01:00
Juergen Hoeller f22a1eece4 Polishing 2024-02-28 19:14:37 +01:00
Sébastien Deleuze 45c21042f6 Optimize Kotlin inline class checks
This commit fixes a performance regression caused by gh-31698,
and more specifically by KClass#isValue invocations which are slow since
they load the whole module to find the class to get the descriptor.

After discussing with the Kotlin team, it has been decided that only
checking for the presence of `@JvmInline` annotation is enough for
Spring use case.

As a consequence, this commit introduces a new
KotlinDetector#isInlineClass method that performs such check, and
BeanUtils, CoroutinesUtils and WebMVC/WebFlux InvocableHandlerMethod
have been refined to leverage it.

Closes gh-32334
2024-02-28 17:18:57 +01:00
Sébastien Deleuze dc1ef23780 Refine *HttpMessageConverter#getContentLength null safety
Closes gh-32325
2024-02-27 15:51:52 +01:00
Sam Brannen cca440eb8e Do not cache Content-Type in ContentCachingResponseWrapper
Based on feedback from several members of the community, we have
decided to revert the caching of the Content-Type header that was
introduced in ContentCachingResponseWrapper in 375e0e6827.

This commit therefore completely removes Content-Type caching in
ContentCachingResponseWrapper and updates the existing tests
accordingly.

To provide guards against future regressions in this area, this commit
also introduces explicit tests for the 6 ways to set the content length
in ContentCachingResponseWrapper and modifies a test in
ShallowEtagHeaderFilterTests to ensure that a Content-Type header set
directly on ContentCachingResponseWrapper is propagated to the
underlying response even if content caching is disabled for the
ShallowEtagHeaderFilter.

See gh-32039
Closes gh-32317
2024-02-26 17:52:56 +01:00
Sam Brannen 497aa3c069 Polish ShallowEtagHeaderFilterTests 2024-02-26 17:44:48 +01:00
Sam Brannen be45481d70 Return unique set from ContentCachingResponseWrapper.getHeaderNames()
Prior to this commit, getHeaderNames() returned duplicates for the
Content-Type and Content-Length headers if they were set in the wrapped
response as well as in ContentCachingResponseWrapper.

This commit fixes that by returning a unique set from getHeaderNames().

In addition, this commit introduces a new test in
ContentCachingResponseWrapperTests to verify the expected behavior for
Content-Type and Content-Length headers that are set in the wrapped
response as well as in ContentCachingResponseWrapper.

See gh-32039
See gh-32317
2024-02-25 16:17:22 +01:00
Sam Brannen 5680d20637 Honor Content-[Type|Length] headers from wrapped response again
Commit 375e0e6827 introduced a regression in
ContentCachingResponseWrapper (CCRW). Specifically, CCRW no longer
honors Content-Type and Content-Length headers that have been set on
the wrapped response and returns null for those header values if they
have not been set directly on the CCRW.

This commit fixes this regression as follows.

- The Content-Type and Content-Length headers set in the wrapped
  response are honored in getContentType(), containsHeader(),
  getHeader(), and getHeaders() unless those headers have been set
  directly on the CCRW.

- In copyBodyToResponse(), the Content-Type in the wrapped response is
  only overridden if the Content-Type has been set directly on the CCRW.

See gh-32039
Closes gh-32317
2024-02-24 16:37:22 +01:00
Sam Brannen 8787381892 Polish ContentCachingResponseWrapper[Tests] 2024-02-24 16:37:14 +01:00
Juergen Hoeller 3cc64968b9 Consistent nullability for internal field access 2024-02-24 08:21:37 +01:00
Arjen Poutsma b4bec4ca61 Allow repeatable writes in Client Interceptors
See gh-31449
2024-02-14 10:05:26 +01:00
Juergen Hoeller b4153618a4 Consistent Lock field declaration (instead of ReentrantLock field type) 2024-02-13 11:07:20 +01:00
rstoyanchev 120ea0a51c Update user info pattern
Closes gh-32211
2024-02-13 07:09:46 +00:00
Stéphane Nicoll ee801d1b28 Update copyright year of changed file
See gh-32232
2024-02-12 10:29:16 +01:00
Olga MaciaszekSharma eebdff23e7 Fix supportsRequestAttributes for RestClientAdapter
Previously, RestClientAdapter claimed that it supports request
attributes when, in fact, it does not. This commit updates the
implementation accordingly.

See gh-32232
2024-02-12 10:27:32 +01:00
Juergen Hoeller 3ecbc4de13 Polishing 2024-02-06 17:57:47 +01:00
Juergen Hoeller 81c156eefb Replace public hasRestTemplateDefaults() method with hasBaseUri()
See gh-32180
2024-02-06 17:57:27 +01:00
Juergen Hoeller cfa47fa4fb Polishing 2024-02-06 16:46:16 +01:00
Juergen Hoeller 80949eb30f Store known attribute names in session (for distributed sessions)
Closes gh-30463
2024-02-06 16:46:11 +01:00
Arjen Poutsma c570f3b2da Fix off-by-one error in PartEvent part count
This commit fixes an off-by-one error in the
PartEventHttpMessageReader,  so that it no longer counts empty windows.

Closes gh-32122
2024-02-05 11:04:24 +01:00
Arjen Poutsma e15c150696 Only copy UriBuilderFactory when customized
This commit ensures that, when creating a RestClient.Builder from a
RestTemplate, the UriBuilderFactory is only copied if it has been
changed from the default values.
Before this commit, the UriBuilderFactory was effectively alway copied,
resulting in not being able to use a baseUrl.

This commit also introduces a small memory optimization in
DefaultUriBuilderFactory, so that default environment variables are
created lazily.

Closes gh-32180
2024-02-02 15:16:10 +01:00
Juergen Hoeller ae17b11b70 Preserve overridden toString result in HandlerMethod copy constructor
Closes gh-32184
2024-02-01 19:14:11 +01:00
Sam Brannen 521fbfdb85 Update copyright headers in contribution 2024-02-01 17:58:06 +01:00
Siddik ACIL 87377d6f3e Fix modelAttribitePredicate typos
This commit replaces occurrences of modelAttribitePredicate with modelAttributePredicate
in HandlerMethodValidationException and the associated validator.

Closes gh-32183
2024-02-01 17:56:07 +01:00
Juergen Hoeller 00577ed80a Polishing 2024-01-31 17:12:20 +01:00
Sam Brannen 067638ae6e Introduce ClassUtils.isVoidType() utility method 2024-01-30 16:27:34 +01:00
Stéphane Nicoll 298f308ce1 Upgrade copyright year of changed file
See gh-32157
2024-01-30 15:59:06 +01:00
jee14 6ffb74def3 Wrap ternary operator within parantheses
See gh-32157
2024-01-30 15:57:51 +01:00
Sam Brannen db535863dd Consistently use class literals for primitive types
To improve consistency and avoid confusion regarding primitive types
and their wrapper types, this commit ensures that we always use class
literals for primitive types.

For example, instead of using the `Void.TYPE` constant, we now
consistently use `void.class`.
2024-01-30 15:26:12 +01:00
Sam Brannen 9eae0ba50e Clean up warnings in build 2024-01-29 17:47:46 +01:00
Juergen Hoeller 005d5ef922 Polishing 2024-01-29 16:53:35 +01:00
Stéphane Nicoll 4b4778d569 Polish "Simplify use of Reactor's cast operator"
See gh-32141
2024-01-27 12:21:46 +01:00
Kai Zander d96a63944c Simplify use of Reactor's cast operator
This commit replaces filter(x -> x instanceof C).cast(C.class) with the
built-in ofType(C.class).

See gh-32141
2024-01-27 12:21:46 +01:00
Sébastien Deleuze 4f16297e45 Polishing
See gh-32074
2024-01-24 16:53:34 +01:00
Felipe 11898daed7 Add support for JSON streams to Kotlin Serialization
Closes gh-32074
2024-01-24 16:53:34 +01:00
Arjen Poutsma f2e267b494 Guard against multiple body subscriptions
Before this commit, the JDK and Jetty connectors do not have any
safeguards against multiple body subscriptions. Such as check has now
been added.

Closes gh-32100
2024-01-24 14:05:20 +01:00
Juergen Hoeller 199a675692 Declare current observation context as available since 6.0.15
See gh-31609
See gh-31646
2024-01-24 12:40:00 +01:00
Juergen Hoeller 2f921dd13d Declare allowPrivateNetwork as available since 5.3.32
See gh-28546
See gh-31974
2024-01-24 12:37:19 +01:00
Juergen Hoeller b92877990d Consistent nullability for concurrent result 2024-01-24 11:43:36 +01:00
Juergen Hoeller d7778c0212 Polishing 2024-01-23 18:31:31 +01:00
rstoyanchev 9230a7db16 WebAsyncManager handles disconnected client errors
See gh-32042
2024-01-22 17:17:18 +00:00
Sam Brannen 45a1f98bd6 Polishing 2024-01-23 11:36:24 +01:00
Juergen Hoeller 5faace0eb3 Predetermine validation groups on initialization
Closes gh-32068
2024-01-23 11:15:12 +01:00
Sam Brannen 3b2f6e74a6 Make assertions based on Annotation#toString() lenient
The behavior for the toString() implementation for annotations changed
in JDK 19, per my request to the JDK team (see link below).

Specifically, since JDK 19, the toString() implementation for annotation
proxies created by the JDK started using canonical names instead of
binary names for types.

See https://bugs.openjdk.org/browse/JDK-8281462
2024-01-23 10:41:40 +01:00