Commit Graph

2916 Commits

Author SHA1 Message Date
Brian Clozel 5838bf5888 Merge branch '6.1.x' 2024-09-13 09:33:10 +02:00
Brian Clozel 6a20987933 Add missing URI template variables in RedirectViews
Prior to this commit, the URL handler mapping would expose the matching
pattern, the path within mapping and matching URI variables as request
attributes. This was the case when the mapping would use the
`AntPathMatcher` as matching infrastructure, but not when using the
`PathPattern` variant. In this case, the map of URI variables would be
`null`. This could throw `IllegalArgumentException` when `RedirectView`
instances were relying on the presence of specific variables.

This commit ensures that URI variables are also extracted when the
`PathPatternParser` is used.

Fixes gh-33422
2024-09-13 09:28:45 +02:00
rstoyanchev 398e5528a1 Merge branch '6.1.x' 2024-09-12 08:40:58 +01:00
rstoyanchev d86bf8b205 Align RouterFunctions resource handling
Closes: gh-33434
2024-09-12 08:33:37 +01:00
Juergen Hoeller e9e5fee149 Consistently resolve exceptions for resources and handler functions
Closes gh-33381
2024-09-11 15:51:01 +02:00
Brian Clozel 2b9b581024 Add streaming support to MVC functional endpoints
Prior to this commit, MVC function endpoints would allow Server Sent
Event responses through `ServerResponse.sse()`. While this covers a
common use case for streaming responses, other technologies would
benefit from a "low-level", unopinionated streaming support.

This commit introduces a new `BodyBuilder.stream()` methods that enables
such use cases. Developers are in charge of setting the relevant HTTP
response headers beforehand, and then can write to the response as raw
`String`, `byte[]` or using complex objects and the configured message
converters for serialization.

Because each streaming protocol has different message separator
semantics, it is also the developers' responsibility to flush buffered
content to the network once a message has been fully written.

Closes gh-32710
2024-09-10 15:41:21 +02:00
rstoyanchev 88ff5e1dcc Remove unused imports 2024-09-10 13:36:16 +01:00
rstoyanchev ebef599146 Fix checkstyle violations 2024-09-10 13:05:57 +01:00
rstoyanchev 19700d07b1 Quote ETag if not quoted in HttpHeaders#setETag
This aligns HttpHeaders with other places like ServletWebRequest and
DefaultWebExchange where an ETag is accepted as input.

It also allows us to remove quoting from places that delegate to
HttpHeaders#setETag since it now does that internally.

Closes gh-33412
2024-09-10 09:17:56 +01:00
rstoyanchev 1b26122e64 Polishing and minor refactoring
Update checks whether quoting is needed to be more complete
than what we've used so far, making sure the there is both
opening and closing quotes independent of each other.

See gh-33412
2024-09-10 08:56:01 +01:00
hyunmin0317 80b264ba82 Refactor eTag formatting into utility method
See gh-33412
2024-09-10 08:55:39 +01:00
Brian Clozel 761fb8f6c9 Allow multiple listeners on ResponseBodyEmitter
Prior to this commit, `ResponseBodyEmitter` woud accept a single
`Runnable` callback on each of its `onTimeout`, `onError` or
`onCompletion` methods. This would limit the developers' ability to
register multiple sets of callbacks: one for managing the publication of
streaming values, another one for managing other concerns like
keep-alive signals to maintain the connection.

This commit now allows multiple calls to `onTimeout`, `onError` and
`onCompletion` and will register all callbacks accordingly.

Closes gh-33356
2024-09-06 15:30:18 +02:00
Sam Brannen 717b972f88 Polish contribution
See gh-33452
2024-09-03 18:08:23 +02:00
Yanming Zhou 019c0b1d4e
Expand acronyms FQN and FQCN
Closes gh-33452
2024-09-03 17:30:27 +02:00
Juergen Hoeller 69d5587f53 Merge branch '6.1.x'
# Conflicts:
#	spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
2024-08-31 12:04:29 +02:00
Juergen Hoeller 1f6ab1a0c9 Polishing 2024-08-31 12:00:41 +02:00
Juergen Hoeller ce5869eeb0 Consistent test execution with Locale.UK 2024-08-31 12:00:34 +02:00
rstoyanchev 7aa25e083a Merge branch '6.1.x' 2024-08-28 18:59:47 +03:00
rstoyanchev 186deb777f Update deprecation notices on rawStatusCode
Mark for removal where not marked, and set to 7.0
consistently as the target for removal.

See gh-33440
2024-08-28 18:49:49 +03:00
Sam Brannen d749d2949d Use new features from JUnit Jupiter 5.11
This commit primarily migrates to the new argumentSet() feature but also
applies additional polishing to our use of parameterized tests.

See gh-33395
2024-08-16 13:48:19 +02:00
Simon Baslé bf5e218b35 Add support for headers in `@HttpExchange`
On the client side, supports `name=value` pairs. Placeholders in values
are resolved by the `embeddedValueResolver`.
On the server side, additionally supports `name` and `!name` syntax.

Closes gh-33309
2024-08-09 18:02:16 +02:00
rstoyanchev b61eee7fb0 Support cross-parameter validation
Closes gh-33271
2024-08-09 18:53:30 +03:00
rstoyanchev 0d64c90a79 Move status/header handling into FragmentsRendering
Based on feedback from htmx-spring-boot. It's more generally useful
to process those from within DefaultFragmentsRendering rather than
in ModelAndViewMethodReturnValueHandler. That way a custom
return value handler can create a FragmentsRendering as well and
get the same result.

See gh-33194
2024-08-09 18:01:15 +03:00
rstoyanchev 8e2b27e5d8 WebFlux support for SSE with multiline fragments
See gh-33194
2024-08-08 16:25:03 +03:00
rstoyanchev 622c1b9e8c WebMvc support for SSE Fragment stream
Closes gh-33194
2024-08-05 14:38:23 +03:00
rstoyanchev 184bb7c23c Polishing in ResponseBodyEmitterReturnValueHandler
See gh-33194
2024-08-05 14:38:23 +03:00
Stéphane Nicoll 3aec39973c Polish 2024-08-02 09:16:15 +02:00
rstoyanchev dbc69284c8 ResponseEntityExceptionHandler handles AsyncRequestNotUsableException
Closes gh-33225
2024-07-30 11:33:47 +03:00
rstoyanchev 5ac7e74bf2 Replace test FilterRegistration with the one in testFixtures
See gh-33252
2024-07-30 11:33:47 +03:00
Brian Clozel b888f362e5 Document ControllerAdviceBean as internal usage
This commit documents `ControllerAdviceBean` as internal usage, as it is
not meant for application to manually create controller advice bean
instances.

This also refactors the existing partial implementation of the support
for creating controller advice beans "programmatically".

Closes gh-32776
2024-07-26 17:52:20 +02:00
rstoyanchev aa6b47bfce Polishing in FragmentsRendering
See gh-33194
2024-07-24 15:34:13 +01:00
Stéphane Nicoll d5abc071f1 Polish "Add missing Javadoc since in AbstractUrlHandlerMapping"
See gh-33247
2024-07-21 09:30:06 +02:00
Johnny Lim edc356d5a0 Add missing Javadoc since in AbstractUrlHandlerMapping
See gh-33247
2024-07-21 09:29:53 +02:00
Stéphane Nicoll e4edd3246a Restore Freemarker support now it supports Jakarta
Closes gh-30186
2024-07-18 17:55:52 +02:00
rstoyanchev bd31e8dacc Provide access to underlying ConstraintViolation
Closes gh-33025
2024-07-12 17:35:35 +01:00
Simon Baslé fbe781b172 Merge branch '6.1.x' 2024-07-12 12:52:40 +02:00
Simon Baslé 152914a752 Fix multipart async servlet request temporary files deletion
This change tracks the multipart nature of the async request
within the `DispatcherServlet`, in the `WebAsyncManager`.

This allows for the second ASYNC dispatch to recognize the
multipart aspect and clean up the associated resources.

Closes gh-33161
2024-07-12 12:50:59 +02:00
rstoyanchev 65296c6aad Add status/headers to WebMVC FragmentsRendering
See gh-33162
2024-07-10 16:40:40 +01:00
rstoyanchev 14c1faa5ee Updates to WebMVC fragment rendering API
See gh-33162
2024-07-10 16:40:40 +01:00
Juergen Hoeller c6347025d6 Merge branch '6.1.x'
# Conflicts:
#	spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java
2024-07-08 19:54:07 +02:00
Juergen Hoeller 7227c30917 Allow tests to pass on Windows JVM (non-UTF-8 default encoding)
See gh-33071
2024-07-08 19:42:28 +02:00
rstoyanchev ef6a3768ee Support multi-view rendering
See gh-33162
2024-07-08 12:47:10 +01:00
rstoyanchev 545228d693 Remove unused tiles config files 2024-07-08 12:47:10 +01:00
Sam Brannen 932ce04541 Stop referring to old Spring versions in Javadoc 2024-07-01 17:50:52 +02:00
Sébastien Deleuze 4555384528 Introduce SmartHttpMessageConverter
SmartHttpMessageConverter is similar to GenericHttpMessageConverter,
but more consistent with WebFlux Encoder and Decoder contracts, with
the following differences:
 - A ResolvableType parameter is used instead of the Type one
 - The MethodParameter can be retrieved via the ResolvableType source
 - No contextClass parameter
 - `@Nullable Map<String, Object> hints` additional parameter for write
   and read methods

This commit also refines RestTemplate#canReadResponse in order to use
the most specific converter contract when possible.

Closes gh-33118
2024-07-01 15:05:57 +02:00
Sam Brannen b64edb2d2a Update Content-Type based on encoding in MVC FreeMarkerView
Closes gh-33119
2024-06-29 17:12:48 +02:00
Sam Brannen ce53443cf0 Polishing 2024-06-29 17:12:47 +02:00
Sam Brannen 8b95697c8d Set output_encoding in FreeMarkerView implementations
According to the official FreeMarker documentation, Spring's
FreeMarkerView implementations should be configuring the
output_encoding for template rendering.

To address that, this commit modifies the FreeMarkerView
implementations in Web MVC and WebFlux to explicitly set the
output_encoding for template rendering.

See https://freemarker.apache.org/docs/pgui_misc_charset.html#autoid_53
See gh-33071
Closes gh-33106
2024-06-27 10:07:47 +02:00
Sam Brannen 95887c81b9 Polish naming for Charset setters in FreeMarker support
See gh-33102
2024-06-26 17:51:11 +02:00
Sam Brannen 73c0783df1 Allow encoding to be set with a Charset in FreeMarker support
Closes gh-33102
2024-06-26 16:18:09 +02:00
rstoyanchev 4e13a69948 Fix spring-websocket test failure after 6c2f60
See gh-32813
2024-06-26 09:31:08 +01:00
Sam Brannen 7183a19dbe Merge branch '6.1.x' 2024-06-25 16:58:45 +02:00
Sam Brannen d133ab60ee Improve documentation regarding encoding in FreeMarker support
This commit also introduces integration tests to test the status quo
regarding encoding.

Closes gh-33071
2024-06-25 16:56:48 +02:00
rstoyanchev 6c2f602369 Propagate context to send for SSE Flux
Closes gh-32813
2024-06-25 15:39:43 +01:00
rstoyanchev c1250b1898 Replace use of deprecated ContextSnapshot methods
See gh-32813
2024-06-25 15:39:43 +01:00
Sam Brannen 5f765fc8ce Polishing 2024-06-23 13:22:08 +02:00
Sam Brannen e6b77d301d Merge branch '6.1.x' 2024-06-22 16:52:42 +02:00
Sam Brannen 000b563e83 Use consistent formatting for view name in AbstractView 2024-06-22 16:51:37 +02:00
Sam Brannen eeb9959cb9 Polishing 2024-06-20 17:13:48 +02:00
Arjen Poutsma e62255512a Encode based on response character encoding
Before this commit, characters were always encoded with the default
encoding (i.e. ISO-8859-1). Now, the character encoding of the response
is used.

Closes gh-files
2024-06-19 14:26:38 +02:00
Brian Clozel 52af43d6d2 Handle ResponseStatusException thrown by MVC functional endpoints
Prior to this commit, exceptions thrown by MVC functional handlers would
not be considered by `ExceptionHandlerExceptionResolver`. This means
that common exceptions would not be handled consistently between
annotated and functional handlers. This is true, for example, for all
`ProblemDetails`-related exception handling.

While MVC functional and annotation models are separate concepts,
WebFlux has a different error handling model that processes all
exceptions in a central place.

This commit ensures that `ExceptionHandlerExceptionResolver` considers
exceptions thrown by handlers of type `HandlerFunction<?>` and processes
them accordingly.

Closes gh-32689
2024-06-06 14:21:17 +02:00
Sam Brannen 17e4c241c3 Avoid use of deprecated AssertJ APIs 2024-06-05 14:50:30 +02:00
Sam Brannen 43a60a7e3f Polishing 2024-06-05 14:50:01 +02:00
rstoyanchev f4f89aa2a4 Add headers to data binding values
Closes gh-32676
2024-06-05 11:30:32 +01:00
rstoyanchev 398aae2b9a Polishing in data binding tests
See gh-32676
2024-06-05 11:30:32 +01:00
Juergen Hoeller 34eccbe8e6 Remove final declaration from getMessageSource() and getLocale() methods
Includes checking the Servlet 3.0+ ServletRequest.getServletContext() method in the request-only constructors, being able to fall back to the root WebApplicationContext.

See gh-32926
2024-06-03 15:27:33 +02:00
Andre Blanke a582e48dd0 Use getMessageSource internally in RequestContext 2024-06-03 15:22:44 +02:00
Arjen Poutsma 903493e9a9 Various MultiValueMap improvements
This commit makes several improvements to MultiValueMap:
- asSingleValueMap offers a single-value view (as opposed to the
  existing toSingleValueMap, which offers a copy)
- fromSingleValue is a static method that adapts a Map<?,?> to the
  MultiValueMap interface
- fromMultiValue is a static method that adapts a Map<?,List<?>> to the
  MultiValueMap interface

Closes gh-32832
2024-05-24 11:44:55 +02:00
Stéphane Nicoll 975e2f4218 Revert "Avoid deprecation warnings for WebJarsResourceResolver"
This reverts commit 61db499ae2.
2024-05-23 16:21:42 +02:00
Sam Brannen 61db499ae2 Avoid deprecation warnings for WebJarsResourceResolver 2024-05-22 15:57:41 +02:00
Brian Clozel 4d4b343815 Support Content Negotiation with @ExceptionHandler
Prior to this commit, `@ExceptionHandler` annotated controller methods
could be mapped using the exception type declaration as an annotation
attribute, or as a method parameter.
While such methods support a wide variety of method arguments and return
types, it was not possible to declare the same exception type on
different methods (in the same controller/controller advice).

This commit adds a new `produces` attribute on `@ExceptionHandler`; with
that, applications can vary the HTTP response depending on the exception
type and the requested content-type by the client:

```
@ExceptionHandler(produces = "application/json")
public ResponseEntity<ErrorMessage> handleJson(IllegalArgumentException exc) {
	return ResponseEntity.badRequest().body(new ErrorMessage(exc.getMessage(), 42));
}

@ExceptionHandler(produces = "text/html")
public String handle(IllegalArgumentException exc, Model model) {
	model.addAttribute("error", new ErrorMessage(exc.getMessage(), 42));
	return "errorView";
}
```

This commit implements support in both Spring MVC and Spring WebFlux.

Closes gh-31936
2024-05-20 17:22:30 +02:00
Brian Clozel cd56b47302 Merge branch '6.1.x' 2024-05-13 21:19:21 +02:00
Brian Clozel c6b6ccdc89 Close ResponseBodyEmitter in case of write errors
Prior to this commit, the `ReactiveTypeHandler` would handle `Flux`-like
return types from controller methods and adapt them to SSE streams using
the `SseEmitter`/`ResponseBodyEmitter` APIs. In case an `IOException` is
thrown while writing to the HTTP response stream, the
`ReactiveTypeHandler` would rely on the Servlet container to call
`AsyncListener#onError` - this would be the signal for Spring MVC to
complete the async exchange. To prevent racing issues between this
signal and the actual handling of the exception, changes like  gh-20173
were applied. Since then, robust checks were added with gh-32340 in
`StandardServletAsyncWebRequest.LifecycleHttpServletResponse`.

With Jetty 12, `AsyncListener#onError` would not be called as the error
would happen while writing in blocking mode to the response (so, not
using the Servlet WriteListener contract). But still, such `IOException`
would still result in the closing of the HTTP connection. As of Jetty
12.0.4, this is no longer the case and the party managing the async
lifecycle is in charge of completing the exchange, as it should. This
means that the current behavior leaks HTTP connections for these cases
and causes memory issues.

This commit ensures that such exceptions happening during response
writes are caught and result in the completion of the `SSEEmitter` and
the closing of the exchange. Even if other Servlet containers still
propagate the error `AsyncListener#onError`, competing signals are still
managed with gh-32340.

Closes gh-32629
2024-05-13 20:30:13 +02:00
rstoyanchev 10e3d3b434 Merge branch '6.1.x' 2024-05-13 11:41:22 +01:00
rstoyanchev d03ea0bf19 Update docs on HandlerInterceptor
Closes gh-32729
2024-05-13 11:40:32 +01:00
Brian Clozel 5cb4985234 Merge branch '6.1.x' 2024-05-13 10:44:09 +02:00
Brian Clozel 89ce63f1f3 Replace RFC7807 by RFC9457 in documentation
This commit updates all references to RFC7807 by RFC9457 since the
former is now obsolete.

Closes gh-32806
2024-05-13 10:42:35 +02:00
Juergen Hoeller b2d43f54e0 Merge branch '6.1.x' 2024-05-10 12:29:49 +02:00
Juergen Hoeller bf08e0c1b4 Polishing 2024-05-10 12:27:29 +02:00
Yanming Zhou a02861f7db Insist on using `CollectionUtils.isEmpty()` and `StringUtils.hasLength()`
search `(\w+) != null && !(\1).isEmpty\(\)`
2024-05-09 09:25:09 +02:00
Sébastien Deleuze 12272d6e41 Remove unneeded `@SuppressWarnings("NullAway")`
Closes gh-32542
2024-05-06 18:28:54 +02:00
Arjen Poutsma 8f3b7484e2 Add testing support for WebMvc.fn
This commit introduces testing support for WebMvc.fn in the form of a
RouterFunctionMockMvcBuilder and RouterFunctionMockMvcSpec.

Closes gh-30477
2024-05-02 15:20:56 +02:00
Arjen Poutsma d5664ba01a Ensure old attributes are not removed by accident
This commit ensures that a copy is made of old attributes before
replacing it with new attributes. Because new attributes can be
composed of old, clearing the old would also remove entries from the
 new.

See gh-32245
2024-05-02 10:51:38 +02:00
Stéphane Nicoll ad0c488767 Polish "Allow AbstractUrlHandlerMapping to add/remote handlers"
See gh-32064
2024-04-30 13:48:34 +02:00
ameinema 109d985f89 Allow AbstractUrlHandlerMapping to add/remote handlers
See gh-32064
2024-04-30 12:58:29 +02:00
Juergen Hoeller 0402ea13c0 Merge branch '6.1.x' 2024-04-24 13:42:43 +02:00
Juergen Hoeller 09b476ac18 Polishing 2024-04-24 13:42:02 +02:00
rstoyanchev 75a5409c97 Add PreFlightRequestHandler for Spring MVC
This is equivalent of the same contract for WebFlux. It is implemented
by HandlerMappingIntrospector, and may be called directly by Spring
Security to handle a pre-flight request without delegate to the rest
of the filter chain.

HandlerMappingIntrospector also has the boolean method
allHandlerMappingsUsePathPatternParser that checks whether all handler
mappings are configured to use parsed PathPattern's.

See gh-31823
2024-04-23 19:00:10 +01:00
Stéphane Nicoll a77895bd90 Merge branch '6.1.x' 2024-04-23 15:34:49 +02:00
Johnny Lim cc73ccefef Polish
See gh-32696
2024-04-23 15:31:48 +02:00
Stéphane Nicoll ed188f82d8 Merge branch '6.1.x' 2024-04-23 15:25:20 +02:00
Stéphane Nicoll 4d34444a69 Consistent annotation lookup in MvcUriComponentsBuilder
Previously, a UriComponents build based on a method would require the
given method to be the annotated one as method parameter resolution only
applied locally. This was a problem when a controller was specified on
a method whose mapping is defined in a parent.

This commit harmonies the lookup using AnnotatedMethod who provides
support for a synthesized method parameter that takes annotations from
parent parameter into account.

Closes gh-32553
2024-04-23 15:21:27 +02:00
Sam Brannen 1455a9fe22 Polishing 2024-04-08 16:37:47 +02:00
Stéphane Nicoll 5253af1a04 Merge branch '6.1.x' 2024-04-04 14:43:38 +02:00
Stéphane Nicoll d955549037 Clarify scope of exception
See gh-29491
2024-04-04 14:42:41 +02:00
Sébastien Deleuze 67edcde0a2 Introduce support for webjars-locator-lite
This commit introduces support for org.webjars:webjars-locator-lite
via a new LiteWebJarsResourceResolver in Spring MVC and WebFlux, and
deprecates WebJarsResourceResolver which is performing a classpath
scanning that slows down application startup.

Closes gh-27619
2024-04-02 10:16:51 +02:00
Sam Brannen d360def92e Polishing 2024-03-30 16:06:06 +01:00
Sébastien Deleuze 8b51b36729 Perform NullAway build-time checks in more modules
This commit enables null-safety build-time checks in
all remaining modules except spring-test.

See gh-32475
2024-03-26 15:53:01 +01:00
Sébastien Deleuze 2fea3d7921 Merge branch '6.1.x' 2024-03-26 15:41:46 +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