Commit Graph

1961 Commits

Author SHA1 Message Date
rstoyanchev 7a79da589a Add default web handling of method validation errors
Closes gh-30644
2023-07-03 12:08:11 +01:00
rstoyanchev a481c7649f Refactor to prepare for method validation handling
To handle method validation errors in ResponseEntityExceptionHandler,
MethodValidationException and associated types should not depend on
Bean Validation. To that effect:

1. MethodValidationResult and ParameterValidationResult no longer make
the underlying ConstraintViolation set available, and instead expose
only the adapted validation errors (MessageSourceResolvable, Errors),
analogous to what SpringValidatorAdapter does. And likewise
MethodValidationException no longer extends ConstraintViolationException.

2. MethodValidationPostProcessor has a new property
adaptConstraintViolations to decide whether to simply raise
ConstraintViolationException, or otherwise to adapt the ConstraintViolations
and raise MethodValidationException instead, with the former is the default
for compatibility.

3. As a result, the MethodValidator contract can now expose methods that
return MethodValidationResult, which provided more flexibility for handling,
and it allows MethodValidationAdapter to implement MethodValidator directly.

4. Update Javadoc in method validation classes to reflect this shift, and
use terminology consistent with Spring validation in classes without an
explicit dependency on Bean Validation.

See gh-30644
2023-07-03 12:08:11 +01:00
rstoyanchev 91eb2be44c Remove no longer supported protected methods
Closes gh-26721
2023-06-27 16:34:52 +01:00
rstoyanchev 11a416156b Use ResolvableType to create WebDataBinder
This provides more flexibility to pass a targetType even if
a MethodParameter is not available.

See gh-26721
2023-06-26 13:11:05 +01:00
rstoyanchev d37d6688d8 WebFlux constructs model attribute via DataBinder
See gh-26721
2023-06-23 11:15:00 +01:00
rstoyanchev 801f01e23f Polishing in ModelAttributeMethodArgumentResolver
See gh-26721
2023-06-22 20:59:05 +01:00
rstoyanchev 40bf923d7d Polishing in MultipartFileArgumentResolver
Closes gh-30728
2023-06-27 10:51:42 +01:00
Olga Maciaszek-Sharma e69a1d22f9 Add MultipartFile support to HTTP interface client
See gh-30728
2023-06-27 09:55:24 +01:00
Sam Brannen 854715d9a7 Update copyright headers 2023-06-25 15:39:16 +02:00
Sébastien Deleuze 35667e81ea Merge branch '6.0.x' 2023-06-23 14:20:13 +02:00
Sébastien Deleuze f06cf21341 Support Kotlin parameter default values in handler methods
This commit adds support for Kotlin parameter default values
in handler methods. It allows to write:
@RequestParam value: String = "default"
as an alternative to:
@RequestParam(defaultValue = "default") value: String

Both Spring MVC and WebFlux are supported, including on
suspending functions.

Closes gh-21139
2023-06-22 16:08:48 +02:00
Sam Brannen b8a713fde3 Merge branch '6.0.x' 2023-06-22 15:12:25 +02:00
Johnny Lim 271f2dc665 Polish
This commit polishes a bit.

Closes gh-30691
2023-06-22 15:06:05 +02:00
Sébastien Deleuze 82ec28b369 Add a CoExchangeFilterFunction for WebClient
This commit introduces a Kotlin-specific implementation
of the ExchangeFilterFunction interface that allows for
using coroutines, similar to what CoWebFilter does on
server-side.

Closes gh-30650
2023-06-20 20:54:38 +02:00
Sam Brannen 2dd34cf967 Clean up warnings in tests 2023-06-15 16:26:34 +02:00
Juergen Hoeller f00a8cb3a3 Remove ServerWebExchange dependency in ServerRequestObservationContext
Avoiding cycle between http.server and web.server packages.

See gh-30013
2023-06-14 21:57:27 +02:00
Juergen Hoeller 220995b830 Move HandlerMethodValidator to web.method.annotation package
Avoiding cycle between web.method.support and web.method.annotation packages.

See gh-29825
2023-06-14 21:52:55 +02:00
rstoyanchev 61eaa9333b Polishing in ErrorResponse
See gh-30566
2023-06-14 16:30:15 +01:00
rstoyanchev 9c7b5cb3f5 Add ProblemDetail "type" message code
See gh-30566
2023-06-14 16:30:15 +01:00
Juergen Hoeller 93345de687 Consistent Locale exposure for Bean Validation message assertions
See gh-29825
See gh-30198
2023-06-14 10:39:19 +02:00
rstoyanchev 85d81024a4 Add MethodParameter[] input to MethodValidationAdapter
This allows re-use of existing MethodParameter instances from controller
methods with cached metadata, and also ensures additional capabilities
such as looking up parameter annotations on interfaces.

See gh-29825
2023-06-13 17:40:57 +01:00
rstoyanchev 6b50b7b72a Initialize propertyName in TypeMismatchException
See gh-26219
2023-06-13 11:29:35 +01:00
rstoyanchev ccf68878c7 Merge branch '6.0.x' 2023-06-12 16:12:03 +01:00
rstoyanchev bbab4faf7a Method level only, empty RequestMapping matches "" and "/"
Closes gh-30293
2023-06-12 16:11:42 +01:00
Rossen Stoyanchev 6b89cf94a3 Add method validation to WebFlux
See gh-29825
2023-06-12 11:37:55 +01:00
Arjen Poutsma ad5bf2fac8 Merge branch '6.0.x' 2023-06-08 16:40:44 +02:00
Arjen Poutsma ce5189a0a0 Default ServerWebExchange::cleanupMultipart implementation
This commit provided a default implementation for ServerWebExchange::cleanupMultipart.

See gh-30590
2023-06-08 16:31:53 +02:00
Arjen Poutsma f4ef057e9e Merge branch '6.0.x' 2023-06-08 14:42:24 +02:00
Arjen Poutsma c1fe57135e Clean multipart up only when data is read
This commit ensures that any storage used for multipart handling only
gets cleaned up if multipart data is actually retrieved via
ServerWebExchange::getMultipartData.

Closes gh-30590
2023-06-08 14:23:47 +02:00
Sam Brannen 714d380ec0 Merge branch '6.0.x' 2023-06-07 12:01:54 +02:00
Sam Brannen f2ae106c32 Update deprecation Javadoc regarding "for removal in 6.2"
See gh-30608
2023-06-07 12:00:27 +02:00
Sébastien Deleuze 66a1be2d86 Enable KotlinScriptTemplateTests with Java 19
No support yet for Java 21.

Closes gh-29249
2023-06-06 15:49:04 +02:00
Juergen Hoeller 8c6287ef7b Expose parameter/field name for non-JavaBeans type conversion
Supports name-bound PropertyEditor registrations on data classes.
Includes consistent support for field-aware method parameters.

Closes gh-28284
2023-06-02 20:42:05 +02:00
rstoyanchev b3f5d20ad8 Merge branch '6.0.x' 2023-05-30 17:18:01 +01:00
rstoyanchev 454a85978f Allow fallback on subclass of ProblemDetail
Closes gh-30533
2023-05-30 17:17:31 +01:00
Sam Brannen 01abd521e2 Merge branch '6.0.x' 2023-05-25 13:48:15 +02:00
Sam Brannen cfb3a45479 Improve Javadoc for ExchangeFilterFunction
See gh-30543
2023-05-25 13:47:37 +02:00
galingerv 7d7d7bcced Fix typos in Javadoc for ExchangeFilterFunction
Closes gh-30543
2023-05-25 13:40:18 +02:00
Sam Brannen f91fae5dfb Avoid deprecation warnings for imports 2023-05-25 13:30:54 +02:00
Brian Clozel 96a429a561 Move reactive server instrumentation out of WebFilter
Prior to this commit, the Observation instrumentation for Reactive
server applications was implemented with a `WebFilter`. This allowed to
record observations and set up a tracing context for the controller
handlers.

The limitation of this approach is that all processing happening at a
lower level is not aware of any observation. Here, the
`HttpWebHandlerAdapter` handles several interesting aspects:

* logging of HTTP requests and responses at the TRACE level
* logging of client disconnect errors
* handling of unresolved errors

With the current instrumentation, these logging statements will miss the
tracing context information. As a result, this commit deprecates the
`ServerHttpObservationFilter` in favor of a more direct instrumentation
of the `HttpWebHandlerAdapter`. This enables a more precise
instrumentattion and allows to set up the current observation earlier in
the reactor context: log statements will now contain the relevant
information.

Fixes gh-30013
2023-05-22 11:03:02 +02:00
Brian Clozel a91effcd86 Ignore some FreeMarker tests for JDK21
This reverts commit 07a5d8c91 and instead disables the relevant
FreeMarker tests for JDK21+ runs.
2023-05-11 18:00:23 +02:00
Brian Clozel 07a5d8c91c Fix FreeMarker tests for JDK21 build
Prior to this commit, some FreeMarker tests would fail when involving
property lookup in a template file, where this bean property is linked
with a method implemented as a default method on an interface.

While I did not manage to reproduce this behavior in an independent test
case, this is most likely related to a change in JDK 21:
https://bugs.openjdk.org/browse/JDK-8071693

This commit changes the template expression to using the default method
directly.
2023-05-11 17:10:26 +02:00
Juergen Hoeller c1014f5989 Relax relative path existence assertion for parsed URIs
See gh-29481
See gh-28522
2023-05-01 00:01:49 +02:00
Juergen Hoeller 9342317291 Avoid use of java.net.URL constructors (for JDK 20 compatibility)
Explicit path computation also leads to consistent relative path semantics for resource URLs.

Closes gh-29481
Closes gh-28522
2023-04-30 23:03:39 +02:00
Brian Clozel b408cee29f Merge branch '6.0.x' 2023-04-25 10:26:40 +02:00
James Yuzawa 5dacf50b9b Optimize MultiValueMap iteration operations
* use forEach and putIfAbsent to copy headers in DefaultClientRequestBuilder
* use forEach in ReactorClientHttpRequest and ReactorNetty2ClientHttpRequest
* circumvent ReadOnlyHttpHeaders.entrySet()
* ensure the fast path to LinkedCaseInsensitiveMap for forEach and putIfAbsent exists

Closes gh-29972
2023-04-25 09:57:26 +02:00
Sam Brannen 7df2e2a8d2 Remove APIs deprecated for removal in 6.1
This is the first commit that removes deprecated APIs.

Subsequent commits will remove additional deprecated APIs.

See gh-29449
2023-04-19 17:23:49 +02:00
Sam Brannen d446de62a4 Update copyright headers 2023-04-19 15:55:11 +02:00
rstoyanchev bd029b9218 Ensure RestClientResponseException is serializable
Closes gh-30224
2023-04-12 15:38:27 +01:00
Brian Clozel 01f97887ea Improve WebClient observations handling of CANCEL signal
Prior to this commit, `WebClient` observations would be recorded as
aborted (with tags "outcome":"UNKNOWN", "status":"CLIENT_ERROR")
for use cases like this:

```
Flux<String> result = client.get()
    .uri("/path")
    .retrieve()
    .bodyToFlux(String.class)
    .take(1);
```

This is due to operators like `take` or `next` that consume *some*
`onNext` signals and then cancels the subscription before completion.
This means the subscriber is only partially interested in the response
and we should not count this as a client error.

This commit ensures that observations are only recorded as aborted if
the response was not published at the time the CANCEL signal was
received.

The code snippet above will now publish observations with
"outcome":"SUCCESS" and "status":"200" tags, for example.

Closes gh-30070
2023-04-07 16:37:09 +02:00
Sam Brannen cef597bedd Update copyright headers 2023-04-07 14:24:22 +02:00
Krzysztof Krasoń 1734deca1e
Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and
readable ones. Using the dedicated assertion instead of a generic one
will produce more meaningful error messages. 

For instance, consider collection size:
```
// expected: 5 but was: 2
assertThat(collection.size()).equals(5);
// Expected size: 5 but was: 2 in: [1, 2]
assertThat(collection).hasSize(5);
```

Closes gh-30104
2023-04-04 17:34:07 +02:00
Vatsa 6c8ebc7f7e Add non-null assertions in DefaultServerResponseBuilder
This commit adds various non-null assertions to
DefaultServerResponseBuilder, in both Spring MVC and WebFlux.

Closes gh-30157
2023-04-04 12:36:46 +02:00
Sam Brannen 69c8f8e9c7 Update copyright headers 2023-04-03 16:45:49 +02:00
Brian Clozel 1efa162cf0 WebClient defaultStatusHandler do not apply to exchangeTo*
This commit documents the fact that default status handlers configured
on the `WebClient` are not applied to `exchangeTo*` methods as those
variants give full access to the client response.

Applying them here would restrict the ability to adapt the behavior
depending on the HTTP response status.

Closes gh-30059
2023-03-31 11:19:40 +02:00
Harry Yang a8b7a5e037 Refine initRequestBuilder in DefaultWebClient
Closes gh-30254
2023-03-31 10:53:51 +02:00
Brian Clozel d451d6adcc Ensure that client responses are observed when filters fail
Prior to this commit, an error thrown by a `ExchangeFilterFunction`
configured on a `WebClient` instance would be recorded as such by the
client observation, but the response details would be missing from the
observation.
All filter functions and the exchange function (performing the HTTP
call) would be merged into a single `ExchangeFunction`; this instance
was instrumented and osberved. As a result, the instrumentation would
only get the error signal returned by the filter function and would not
see the HTTP response even if it was received. This means that the
recorded observation would not have the relevant information for the
HTTP status.

This commit ensures that between the configured `ExchangeFilterFunction`
and the `ExchangeFunction`, an instrumentation `ExchangeFilterFunction`
is inserted. This allows to set the client response to the observation
context, even if a later error signal is thrown by a filter function.

Note that with this change, an error signal sent by a filter function
will be still recorded in the observation.

See gh-30059
2023-03-30 20:04:48 +02:00
Sébastien Deleuze d126b99c91 Refine generic type management in AbstractMessageWriterResultHandler
This commit updates AbstractMessageWriterResultHandler#writeBody in
order to use the declared bodyParameter instead of
ResolvableType.forInstance(body) when the former has unresolvable
generics.

Closes gh-30214
2023-03-30 18:07:01 +02:00
Brian Clozel 66cdf43b56 Polish
Closes gh-30223
2023-03-29 10:55:48 +02:00
James Yuzawa 2ba206f8ba Order metric labels in ObservationConventions
See gh-30223
2023-03-29 10:55:34 +02:00
Sam Brannen 0ca02ce677 Disable affected tests on Java 18+/19+
See gh-30185
2023-03-24 16:05:40 +01:00
Sam Brannen ce9a72f95c Update copyright headers 2023-03-23 16:56:20 +01:00
James Yuzawa 800b13492b
Optimize some iterations in BodyExtractor and BodyInserter
This commit turns some stream-based iterations back into simpler
enhanced for loops.

For simple use cases like these, where the stream API is merely used to
map/filter + collect to a List, a for loop is more efficient.
This is especially true for small collections like the ones we deal
with in BodyInserters/BodyExtractors here (in the order of 50ns/op vs
5ns/op). These cases are also simple enough that they don't lose in
readability after the conversion.

Closes gh-30136
2023-03-22 11:04:54 +01:00
Sam Brannen df4e7d1929 Polishing 2023-03-15 15:08:47 +01:00
Brian Clozel 2a5eab4b89 Ignore quality factor when filtering out "*/*"
Prior to this commit, the `RequestedContentTypeResolverBuilder` would
create a `RequestedContentTypeResolver` that internally delegates to a
list of resolvers. Each resolver would either return the list of
requested media types, or a singleton list with the "*/*" media type; in
this case this signals that the resolver cannot find a specific media
type requested and that we should continue with the next resolver in the
list.

Media Types returned by resolvers can contain parameters, such as the
quality factor. If the HTTP client requests "*/*;q=0.8", the
`HeaderContentTypeResolver` will return this as a singleton list. While
this has been resolved from the request, such a media type should not be
selected over other media types that could be returned by other
resolvers.

This commit changes the `RequestedContentTypeResolverBuilder` so that it
does not select "*/*;q=0.8" as the requested media type, but instead
continues delegating to other resolvers in the list. This means we need
to remove the quality factor before comparing it to the "*/*" for
equality check.

Fixes gh-29915
2023-03-15 10:16:27 +01:00
rstoyanchev c3ce847871 Polishing contribution
Closes gh-30092
2023-03-14 11:10:02 +00:00
James Yuzawa cd8955fa72 Remove extra copy in WebClient headers/cookies
See gh-30092
2023-03-14 10:49:53 +00:00
Sam Brannen e17f5c50a8 Update copyright headers 2023-03-13 21:53:40 +01:00
Sam Brannen 00be19c647 Consistently declare Object::equals argument as @Nullable 2023-03-13 21:43:21 +01:00
Sam Brannen a6dab10309 Update code regarding null-safety semantics
See gh-30083
2023-03-13 21:19:46 +01:00
Sam Brannen b617e16d8d Polishing 2023-03-13 21:16:02 +01:00
Sam Brannen 9cf7b0e230 Polishing 2023-03-12 18:38:50 +01:00
Sam Brannen 99e54fec3a Ensure all packages declare package-info.java with null-safety annotations
This commit picks up where the two previous commits left off.

Specifically, this commit:

- Removes the "severity=warning" configuration to ensure that violations
  actually fail the build.
- Fixes regular expressions for suppressions by matching forward
  slashes using `[\\/]` instead of `\/`.
- Moves the configuration for newly introduced checks to locations in
  checkstyle.xml that align with the existing organization of that file.
- Renames the IDs for RegexpSinglelineJava checks from
  javaDocPackageNonNullApiAnnotation/javaDocPackageNonNullFieldsAnnotation
  to packageLevelNonNullApiAnnotation/packageLevelNonNullFieldsAnnotation,
  respectively, since these checks are not related to Javadoc.
- Simplifies the null-safety annotation checks to match against
  imported annotation types, which enforces consistency across
  package-info.java files for the annotation declarations.
- Simplifies the RegEx for JavadocPackage suppressions to only exclude
  packages not under src/main/java (vs src/main) and those in the
  framework-docs module.
- Consistently suppresses all checks for the `asm`, `cglib`, `objenesis`,
  and `javapoet` packages in spring-core.
- Adds explicit suppressions for null-safety annotations for the `lang`
  package in spring-core.
- Adds explicit suppressions for null-safety annotations for the
  `org.aopalliance` package in spring-aop.
- Revises the RegEx for null-safety annotation suppressions to only
  exclude package-info.java files not under src/main/java and
  additionally to exclude package-info.java files in the framework-docs
  module as well as those in the spring-context-indexer,
  spring-instrument, and spring-jcl modules.
- Adds all missing package-info.java files.
- Adds null-safety annotations to package-info.java files where
  appropriate.

Closes gh-30069
2023-03-10 17:33:52 +01:00
Arjen Poutsma e88ec06a36 Disable flaky unit test for undertow 2023-03-09 10:03:07 +01:00
Vatsa d8fbd35467 Add non-null assertions in DefaultServerRequestBuilder
This commit adds various non-null assertions to
DefaultServerRequestBuilder, in both Spring MVC and WebFlux.

Closes gh-30046
2023-03-08 12:50:02 +01:00
Sam Brannen 9b811a01f6 Polishing 2023-03-07 15:20:10 +01:00
Sam Brannen 2b23d1693d Remove unused service package 2023-03-07 15:20:10 +01:00
Sébastien Deleuze 9f2f93129b Move HttpServiceProxyFactoryExtensions.kt to spring-web module
HttpServiceProxyFactoryExtensions.kt has been mistakenly created
in spring-webflux module instead of spring-web, breaking JPMS for
WebFlux users.

This commit moves this file and related tests to the spring-web
module.

Closes gh-30042
2023-02-27 14:48:28 +01:00
Sam Brannen 2d56505ea9 Polishing 2023-02-20 16:49:27 +01:00
Sam Brannen 2e1374b459 Update copyright headers 2023-02-19 13:41:36 +01:00
Arjen Poutsma 88e6544d9d Fix regression in WebFlux support for WebDAV methods
This commit ensures that WebFlux's RequestMethodsRequestCondition
supports HTTP methods that are not in the RequestMethod enum.

- RequestMethod::resolve is introduced, to convert from a HttpMethod
(name) to enum values.
- RequestMethod::asHttpMethod is introduced, to convert from enum value
to HttpMethod.
- HttpMethod::valueOf replaced Map-based lookup to a switch statement
- Enabled tests that check for WebDAV methods

See gh-27697
Closes gh-29981
2023-02-17 12:46:26 +01:00
Johnny Lim ce3be72e7f Polish 2023-02-15 22:22:58 +09:00
Juergen Hoeller 979118c1eb Polishing 2023-02-15 10:13:16 +01:00
Juergen Hoeller f87a87e29d Consistent ordering of Resource methods
See gh-24651
2023-02-15 10:13:03 +01:00
Arjen Poutsma 12d4dc1bae Polishing external contribution
This commit makes several changes to PR #24651.

- Add byte[] getContentAsByteArray() on Resource.
- Remove getContentAsString() from Resource, as it relied on the default
charset which is not reliable.
- Add getContentAsString() to EncodedResource, as a charset is provided
through the constructor.

See gh-24651
2023-02-14 14:56:34 +01:00
Arjen Poutsma 3e2f58cdd2 Offer restricted access to DataBuffer's ByteBuffer
This commit introduces DataBuffer::readableByteBuffers and
DataBuffer::writableByteBuffers, allowing restricted access to the
ByteBuffer used internally by DataBuffer implementations.

Closes gh-29943
2023-02-13 15:28:29 +01:00
Boris Fox 72926c29f9 Temporarily set LocaleContextHolder to provide validation message interpolator with locale context (fixes SPR-17231). 2023-02-13 11:45:45 +00:00
Sébastien Deleuze a2a676241c Introduce HttpServiceProxyFactory#createClient Kotlin extension
Closes gh-29942
2023-02-07 15:50:30 +01:00
Sébastien Deleuze 9f061f1eec Refine KotlinWebClientHttpServiceProxyTests
See gh-29527
2023-02-07 11:07:30 +01:00
Donghyeon Kim 1d4bf58e8d Support Coroutines in HttpServiceProxyFactory
See gh-29527
2023-02-07 11:07:29 +01:00
rstoyanchev ce85fdc5c7 Always use application/problem+json with ProblemDetail
See gh-gh-29588
2023-02-07 08:57:24 +00:00
rstoyanchev 9c6fd3ed06 Consistently list supported media types
Add constructors to HttpMediaTypeNotSupportedException and
UnsupportedMediaTypeStatusException for a parse error that also accept
the list of supported media types to include in the response headers.

Closes gh-28062
2023-01-30 17:46:08 +00:00
rstoyanchev 17f1eadb6f Polishing contribution
Closes gh-29610
2023-01-30 17:46:08 +00:00
divcon 09991f2492 Polishing in ResponseEntityResultHandler
See gh-files
2023-01-30 17:46:08 +00:00
Johnny Lim 0b446a94c5 Add Javadoc since for CLIENT_NAME enums
See gh-29839
Closes gh-29893
2023-01-30 10:10:31 +01:00
Brian Clozel 5dfa61eb0b Restrict "uri" KeyValue for client observations
Prior to this commit, the "uri" KeyValue for low cardinality metadata
would contain the entire uri template given to the HTTP client when
creating the request. This was a breaking change for existing metrics
dashboards, as previous support was removing the protocol, host and port
parts of the URI.
Indeed, this information is available in the "client.name" and
"http.uri" KayValue.

This commit parses and removes the protocol+host+port information from
the uri template for the "uri" KeyValue.

Fixes gh-29885
2023-01-30 10:09:45 +01:00
Brian Clozel b267547fb4 Contribute "uri" KeyValue for "/" client requests
Prior to this commit, client HTTP requests performed by `WebClient`
could miss the "uri" KeyValue for simple "/" requests.
This can happen when the baseUri is configured for the client with a
host and a root base path like "https://example.org/"; given the nature
of the `WebClient` API, in these cases, one can perform requests like
this:

```
WebClient client = WebClient.builder()
    .observationRegistry(registry)
    .baseUrl("https://example.org/")
    .build();

String response = client.get().retrieve().bodyToMono(String.class).block();
```

Such a call would contribute a `"none"` value for the `"uri"` KeyValue.

While only templates should be allowed for this keyvalue, we can assume
that requests to `"/"` should be recorded anyway and won't cause
cardinality explosion.

Fixes gh-29879
2023-01-30 10:09:41 +01:00
Sam Brannen 75046bbea0 Update copyright headers 2023-01-28 20:42:21 +01:00
Brian Clozel 7da6e93597 Set WebClient Observation as current in reactor context
Prior to this commit, the `DefaultWebClient` would be instrumented for
client observations and would start/stop a `"http.client.requests"`
observation. This would not set this new observation as the current one
in the Reactor context under `ObservationThreadLocalAccessor.KEY`.
This means that potential child observations would not detect it as
their parent; this can happen if the Reactor Netty `HttpClient`
observation is enabled.

This commit ensures that the reactor context is properly populated for
upstream operators.

Fixes gh-29891
2023-01-27 14:42:08 +01:00
Brian Clozel 767f59a3ae Make client.name low cardinality keyvalue for client observations
Prior to this commit, the `"client.name"` key value for the
`"http.client.requests"` client HTTP observations would be considered as
high cardinality, as the URI host is technically unbounded.
In practice, the number of hosts used by a client in a given application
can be considered as low cardinality. This commit moves this keyvalue to
low cardinality so that it's present for both metrics and traces.

Closes gh-29839
2023-01-25 20:51:15 +01:00
Brian Clozel d37ef61b30 Resolve static resources without wildcard pattern
Prior to this commit, the reactive `ResourceWebHandler` would only look
at the path within the current mapping when resolving static resources
to be served. This means that when registering a handler at
`"/resources/**"` with a `"classpath:/static/"` location, the handler
would process a `"GET /resources/file.txt"` as the `"/static/file.txt"`
classpath location.

When a developer registers a fixed pattern like `"/resources/file.txt"`
with the same location, the path within the handler mapping is empty as
there is no dynamic part in the given pattern. While the typical use
case for this feature is to register multiple resources at once with a
pattern, we should support a single registration like this.

This commit ensures that if the matching `PathPattern` for the current
request does not have a pattern syntax (i.e. no regexp, no wildcard), we
can use it to match the resource directly. Otherwise, we can use the
path within the handler mapping to resolve the resource as before.

Closes gh-29739
2023-01-20 17:15:52 +01:00
Sébastien Deleuze 8f94c4e933 Remove WebClientIntegrationTests#exchangeWithRelativeUrl outdated test
This test can fail when a web server runs on port 80 and
is not relevant anymore due to the removal of related feature
via 6e936a4081.

Closes gh-28902
2023-01-20 13:59:39 +01:00
Sébastien Deleuze fb0aa5abb3 Fix WebClientIntegrationTests flaky Jetty tests
Ensure the port used by the client in malformedResponseChunksOnBodilessEntity
and malformedResponseChunksOnEntityWithBody has correctly been set.

Closes gh-29862
2023-01-20 11:38:22 +01:00
Sam Brannen 1ace42f245 Enable JRubyScriptTemplateTests 2023-01-19 16:20:03 +01:00
Sam Brannen 0502d18e3d Update copyright headers 2023-01-19 16:20:03 +01:00
Sam Brannen c4c786596f Migrate to Mockito.mock(T...) where feasible 2023-01-19 16:20:02 +01:00
Arjen Poutsma 9ebd1e8d64 Fix IllegalStateException in empty ProducesRequestCondition
When comparing empty ProducesRequestCondition, compareTo would throw an
IllegalStateException if the Accept header was invalid. This commit
fixes that behavior.

Closes gh-29794
2023-01-18 10:38:09 +01:00
Sam Brannen 64de6de725 Update copyright headers 2023-01-17 15:49:26 +01:00
Sam Brannen c3e8ff9ce7 Do not use Mockito to mock ReactiveAdapterRegistry 2023-01-17 15:44:57 +01:00
Sam Brannen ad5c636aff Upgrade to Mockito 5.0 2023-01-17 14:31:11 +01:00
rstoyanchev 312db36849 Combined, empty RequestMapping matches both "" and "/"
Closes gh-29625
2023-01-13 14:58:11 +00:00
Sam Brannen a4956dfe26 Update copyright headers 2023-01-11 13:52:20 +01:00
Sam Brannen 0415975dd1 Polish contribution and related code 2023-01-11 13:52:20 +01:00
Krzysztof Krason afb8a0d1b1 Use new Java features (switch expressions, text blocks, new JDK methods)
Closes gh-29747
2023-01-11 13:51:28 +01:00
Sam Brannen c7bdfbea4f Add missing Javadoc
See gh-29574
2022-12-13 13:46:31 +01:00
Sam Brannen 7fe78b745f Polish Javadoc 2022-12-13 13:44:03 +01:00
Arjen Poutsma c79ae0c842 Align multipart codecs on client and server
This commit ensures that the same multipart codecs are registered on
both client and server. Previously, only the client enabled only sending
 multipart, and the server only receiving.

Closes gh-29630
2022-12-13 10:13:46 +01:00
Sam Brannen 46fc28fd1a Clean up Javadoc and source code regarding " ." typos 2022-12-12 16:31:14 +01:00
Johnny Lim f8a1dac593
Use consistent visibility for ResponseEntityExceptionHandler.getMessageSource()
See gh-29574
Closes gh-29676
2022-12-12 16:15:52 +01:00
Sam Brannen 67644a28b6 Use URI#create instead of URI constructor where feasible in spring-webflux 2022-12-09 13:26:30 -05:00
rstoyanchev 39d4d2041a Polishing contribution
Closes gh-29634
2022-12-09 10:24:42 +00:00
koo.taejin 5ac97b16a8 Optimize object creation PartialMatchHelper
See gh-29634
2022-12-09 10:19:54 +00:00
Sam Brannen 69f47e7700 Polishing
- primarily automated "clean up" using Eclipse IDE
2022-12-09 00:56:00 -05:00
Sam Brannen 348cc01284 Rename MultipartWebClientIntegrationTests classes to avoid duplicate names 2022-12-06 12:50:36 -05:00
Sam Brannen 9f7a510f90 Polishing 2022-12-06 12:29:03 -05:00
divcon f64397d822 Apply "instanceof pattern matching" in spring-webflux
Closes gh-29635
2022-12-06 10:03:26 -05:00
Sam Brannen de07ad47f1 Polishing, suppression of deprecation warnings, copyright headers, etc. 2022-12-05 14:16:22 -05:00
rstoyanchev db53b618c1 Simplify form data handling in HttpRequestValues
Closes gh-29615
2022-12-05 15:37:48 +00:00
rstoyanchev 913163884a Improve invalid Content-Type handling in WebFlux
Closes gh-29565
2022-12-05 15:37:48 +00:00
rstoyanchev a09f93768a Fix URI override for HttpExchange
Closes gh-29624
2022-12-02 17:02:05 +00:00
Sam Brannen ad60164911 Update copyright headers for source code changed since August 2022
The changes in this commit were performed using the newly introduced
update_copyright_headers.sh script.
2022-11-29 19:38:42 +01:00
Sam Brannen 1bb723b9e0 Rename to AbstractReactiveWebSocketIntegrationTests to avoid duplicate class names 2022-11-28 17:43:39 +01:00
Sam Brannen db02c96c55 Avoid deprecation warnings in tests 2022-11-28 17:40:46 +01:00
rstoyanchev 6c8fb6c204 Add MessageSource getters
See gh-29574
2022-11-28 10:59:57 +00:00
Juergen Hoeller 21d3a7529c Consistent documentation references to Jakarta WebSocket (2.1)
Closes gh-29581
2022-11-25 17:07:30 +01:00
Juergen Hoeller 9c7b471634 Deprecate JettyWebSocketClient in favor of StandardWebSocketClient
JettyWebSocketClient only supported on Jetty 11, to be phased out.

Closes gh-29576
2022-11-25 17:06:15 +01:00
Juergen Hoeller 459e8a1ea5 Deprecate LocalVariableTableParameterNameDiscoverer completely
LocalVariableTableParameterNameDiscoverer is not registered by default anymore now.
Java sources should be compiled with `-parameters` instead (available since Java 8).
Also retaining standard Java parameter names for all of Spring's Kotlin sources now.

Closes gh-29531
2022-11-22 19:26:15 +01:00
Sam Brannen 7fcd1de8e3 Use AssertJ's isEmpty() instead of hasSize(0)
Achieved via global search-and-replace.
2022-11-22 17:11:50 +01:00
Sam Brannen d5b0b2b1a1 User AssertJ's hasSize() for arrays
Achieved via global search-and-replace.
2022-11-22 17:03:45 +01:00
Sam Brannen 36f7597f25 Use AssertJ's hasSize() for collections and maps
Achieved via a global search-and-replace.
2022-11-22 16:50:10 +01:00
Stephane Nicoll 09a58a55bf Polish 2022-11-15 20:10:03 +01:00
Sam Brannen 2aa78889d2 Use consistent wording in precondition error messages 2022-11-15 12:31:01 +01:00
Sam Brannen 07ba13c9ca Remove superfluous method override 2022-11-14 17:11:58 +01:00
Brian Clozel 1ad7cc3702 Reorganize server observability packages
Prior to this commit, the server observability support would create a
cycle in Java packages.

This commit refactors the current arrangement to solve this by:

* "flattening" the reactive HTTP instrumentation; this removes the
  dependency to the `ServerWebExchange` and `PathPattern` types
* moving the `observation` package under
  `org.springframework.http.server` and
  `org.springframework.http.server.reactive`

See gh-29477
2022-11-14 12:59:45 +01:00
Sébastien Deleuze 7a9bd3fed9 Merge branch '5.3.x' 2022-11-13 19:08:28 +01:00
Sébastien Deleuze b766a49a4d Support suspending functions returning Unit in WebFlux
Closes gh-27629
2022-11-13 19:05:29 +01:00
rstoyanchev e0b405869f Merge branch '5.3.x' 2022-11-11 15:16:26 +00:00
rstoyanchev 0348a7bf2e Improve API for RFC 7807 in functional endpoints
Closes gh-29462
2022-11-11 13:34:35 +00:00
rstoyanchev f9d8367379 Exclude URL query from checkpoint in DefaultWebClient
Closes gh-29148
2022-11-11 13:29:36 +00:00
rstoyanchev 8ade083a05 Filter out null WebSocketSession attributes
Closes gh-29315
2022-11-11 11:20:18 +00:00
rstoyanchev fb22044c10 Polishing
See gh-22991
2022-11-09 11:34:32 +00:00
rstoyanchev 307247b6a3 Use DispatchExceptionHandler in HandlerResult
Commit #2878ad added the DispatchExceptionHandler contract for
mapping an error before a handler is selected to a HandlerResult.
The same is also convenient for use in HandlerResult itself which
currently uses a java.util.Function essentially for the same.

See gh-22991
2022-11-08 18:31:35 +00:00
rstoyanchev 2878ade980 WebFlux support for handling of early exceptions
This change enables a WebFlux HandlerAdapter to handle not only the
success scenario when a handler is selected, but also any potential
error signal that may occur instead. This makes it possible to
extend ControllerAdvice support to exceptions from handler mapping
such as a 404, 406, 415, and/or even earlier exceptions from the
WebFilter chain.

Closes gh-22991
2022-11-08 15:13:18 +00:00
Sam Brannen d0b162a76c Polishing 2022-11-08 14:16:00 +01:00
Sam Brannen 95f3337bb5 Revise contribution
This commit reverts changes to AbstractCacheManager since iterating
over the caches in a for-loop and a stream is duplicated effort.

This commit reverts changes to DefaultRenderingResponseBuilder,
RouterFunctions, and OriginHandshakeInterceptor since order matters for
those use cases: they were originally based on the semantics of
LinkedHashSet or LinkedHashMap; whereas, Set.copyOf() and Map.copyOf()
do not provide any guarantees regarding ordering.

This commit also applies analogous changes to "sibling" implementations
across Servlet mocks as well as Web MVC and WebFlux.

See gh-29321
2022-11-08 14:14:29 +01:00
divcon ba136dcf40 Replace use of Collections.unmodifiable*() methods where appropriate
Closes gh-29321
2022-11-08 13:51:31 +01:00
Sam Brannen 3438c47744 Polishing 2022-11-08 11:48:13 +01:00
rstoyanchev aeb35663d4 Remove deprecated methods in HttpServiceProxyFactory 2022-11-07 16:57:17 +00:00
Juergen Hoeller a2ac764f9c Reuse StandardWebSocketUpgradeStrategy as a base class for Tomcat etc
Includes non-reflective instantiation of well-known strategy classes.

See gh-29436
2022-11-07 17:35:31 +01:00
Johnny Lim 710cf1f486 Use ObservationThreadLocalAccessor.KEY where possible
Closes gh-29439
2022-11-07 15:39:28 +01:00
Juergen Hoeller 19cf503534 Align with Servlet 6.0 and introduce support for Jakarta WebSocket 2.1
Includes corresponding build upgrade to Tomcat 10.1.1 and Undertow 2.3.0
(while retaining runtime compatibility with Tomcat 10.0 and Undertow 2.2)

Closes gh-29435
Closes gh-29436
2022-11-06 16:08:30 +01:00
Andy Wilkinson 95395b53d5 Make WebSocket upgrade strategies compatible with Tomcat 10.1 2022-11-06 00:30:35 +01:00
Sam Brannen 82823517fa Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java
#	spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java
#	spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java
#	spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java
#	spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
#	spring-web/src/main/java/org/springframework/http/HttpRange.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java
2022-11-05 14:50:18 +01:00
Sam Brannen 5f02323b9c Avoid String allocations with Assert.isTrue() 2022-11-05 14:40:45 +01:00
Sam Brannen d849f9816a Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java
2022-11-04 16:29:54 +01:00
Sam Brannen a281d8c3fd Polishing 2022-11-04 16:24:59 +01:00
Brian Clozel 6022065ad3 Rename web observation documentation
Prior to this commit, several variants of observation documentation
would share the same name; for example HTTP client observations for both
blocking and reactive clients would have the same name.

While it is required that they have the same metric name for dashboards,
the observation documentation names should be different so that they can
be documented without confusing developers.

This commit renames the observation documentation names to avoid that.

Closes gh-29431
2022-11-04 15:38:32 +01:00
Brian Clozel db79d1d2b9 Set matching pattern in reactive server observation context
This commit fixes the observation instrumentation for the reactive HTTP
server by setting the best matching pattern determined by the web
framework into the `ServerRequestObservationContext`.

This information is required by the observation convention for creating
the expected `KeyValue` for the matching pattern. Prior to this commit,
the information was missing and resulted in an UNKNOWN key value.

Fixes gh-29422
2022-11-02 19:02:31 +01:00
Brian Clozel 3c049a2bd0 Polish
See gh-29388
2022-11-02 16:26:01 +01:00
Marcin Grzejszczak c03ccb2e6c Propagate context in reactive HTTP server and client
Prior to this commit, the ServerHttpObservationFilter would not add
the current observation as a key in the Reactor context, preventing
from being used or propagated during the HTTP exchange handling.

Also, the client instrumentation in `DefaultWebClient` would start
the observation once the request is fully formed and immutable,
preventing the context from being propagated through HTTP request
headers.

This commit fixes both uses cases now by:

* adding the current observation as a key in the reactor context
  on the server side
* using the `ClientRequest.Builder` as a Carrier on the client side

Closes gh-29388
2022-11-02 16:25:50 +01:00
Arjen Poutsma 2042cb68a5 Merge two DispatcherHandlerIntegrationTests 2022-11-02 14:48:58 +01:00
Arjen Poutsma 9e306151c7 Use case-insensitive check for request conditions
This commit ensures that the ConsumesRequestCondition and
ProducesRequestCondition use a case insensitive check when comparing
parameters.

Closes gh-29416
2022-11-02 14:29:50 +01:00
Sébastien Deleuze aa2d7dba5b Merge branch '5.3.x' 2022-11-02 11:16:35 +01:00
Christoph Dreis 58bb6e7181 Reduce allocations caused by producible media types
Closes gh-29412
2022-11-02 11:15:26 +01:00
rstoyanchev 5ef3aab3fe Warn about ResponseEntity-ProblemDetail status mismatch
Closes gh-29378
2022-11-01 14:10:39 +00:00
rstoyanchev 921eeadff4 Minor refactoring after recent commits
See gh-29384
2022-11-01 13:56:40 +00:00
rstoyanchev e71057dca9 Support i8n of ProblemDetail "title" field
Closes gh-29407
2022-11-01 12:42:34 +00:00
rstoyanchev 506fbe5243 Improve mapping any Exception to ErrorResponse
Add protected, convenience method in ResponseEntityExceptionHandler
to create a ProblemDetail for any exception, along with a
MessageSource lookup for the "detail" field.

Closes gh-29384
2022-11-01 12:42:34 +00:00
Sébastien Deleuze 6dd3fb1411 Merge branch '5.3.x' 2022-10-21 09:38:03 +02:00
Mikk Raudvere 12cc8a9f07 Fix typos
Closes gh-29364
2022-10-21 09:35:38 +02:00
rstoyanchev bd59c7a691 Polishing contribution
Closes gh-29310
2022-10-19 13:22:38 +01:00
Violeta Georgieva 997d1b3d7e Enable leak detection in Netty 5 tests
See gh-29310
2022-10-19 12:07:40 +01:00
Sébastien Deleuze aa776e40f9 Ensure classpath checks can be evaluated at build-time
Closes gh-29352
2022-10-19 10:49:11 +02:00
Johnny Lim 5dca43ebd6 Use KeyValue.NONE_VALUE where possible
See https://github.com/micrometer-metrics/micrometer/issues/3458

Closes gh-29342
2022-10-19 09:32:57 +02:00
Johnny Lim 7df8b59a7f Polish "Reorganize HTTP Observation types"
See gh-29334
2022-10-18 09:11:07 +09:00
Brian Clozel 001b2636d6 Reorganize HTTP Observation types
Closes gh-29334
2022-10-17 21:54:53 +02:00
rstoyanchev 5cb3af708c Add Builder to HttpServiceProxyFactory
HttpServiceProxyFactory now support programmatic initialization through
a builder, while bean-style initialization is deprecated.

See gh-29296
2022-10-17 12:23:58 +01:00
Sébastien Deleuze 581fa1419f Merge branch '5.3.x' 2022-10-16 20:32:52 +02:00
Sébastien Deleuze 1439c5bb8f Document how to use WebJars without webjars-locator-core dependency
Closes gh-29322
2022-10-16 20:28:57 +02:00
Arjen Poutsma ce03980fb4 Mark HttpRequest::getMethodValue and ClientHttpResponse::getRawStatusCode for removal 2022-10-12 16:29:14 +02:00
Brian Clozel 455a736a01 Switch to Micrometer 1.10.0-SNAPSHOT
See gh-29241
2022-10-06 14:08:07 +02:00
Iain Henderson b8243e6f84 Support CBOR and Protobuf with Kotlin Serialization
This commit introduces support for CBOR and Protobuf using Kotlin
serialization. Support comes in the form of Encoder/Decoder as well
as HttpMessageConverters. Seperate abstract base classes supply support
for binary and string (de)serialization.

The exising JSON codecs and message converters have been migrated to
use the new base classes.

Closes gh-27628
2022-10-06 13:51:50 +02:00
rstoyanchev a4210854fb MessageSource support for Spring MVC and WebFlux exceptions
See gh-28814
2022-10-05 14:02:42 +01:00
Brian Clozel 681cf0dae7 Provide full request URL for "http.url" keyvalue
Prior to this commit, the Observation filter for Servlet applications
would only use the request pathInfo as an "http.url" high cardinality
keyvalue. This commit ensures that we're using the full request URL as a
value there.

This also polishes gh-29254.

Fixes gh-29257
See gh-29254
2022-10-05 11:40:28 +02:00
Brian Clozel 7dd6afc263 Temporarily disable kotlin scripts tests with Java 19
See gh-29249
2022-10-05 10:04:24 +02:00
Brian Clozel 486a1b6024 Change keyvalue name to http.url in server observations
This commit changes the new high cardinality key value from
"uri.expanded" to "http.url" in order to align with the OTel
specification, since there is no need for backwards compatibility on
this new metadata.

Closes gh-29254
2022-10-05 09:55:42 +02:00
Sam Brannen 1224be84ba Remove incorrect [@]since tags 2022-10-04 16:24:13 +02:00
Sam Brannen e284405e9a Delete unused code 2022-10-04 16:19:53 +02:00
Brian Clozel 5613922fba Polish test
This test should not rely on a particular content-type as none is
defined on the producing end, not on the requesting end.
2022-10-04 10:09:07 +02:00
rstoyanchev 4d5b0c91a3 Polishing contribution
Closes gh-29247
2022-10-03 18:20:52 +01:00