Commit Graph

816 Commits

Author SHA1 Message Date
Arjen Poutsma f15bd88211 Fix checkstyle 2018-12-07 15:06:56 +01:00
Arjen Poutsma 3258ac1ec4 Expose request in WebClientResponseException
This commit exposes the request that lead to it in
WebClientResponseException, as a HttpRequest object.

Issue: SPR-17087
2018-12-07 11:08:02 +01:00
Juergen Hoeller 6a012147c4 Consistent support for last-modified argument as Instant/ZonedDateTime
Issue: SPR-17571
2018-12-06 15:53:47 +01:00
Rossen Stoyanchev 7a5f8e03bc Refine check for multiple subscribers
Commit #c187cb2 introduced proactive rejection of multiple subscribers
in ReactorClientHttpResponse, instead of hanging indefinitely as per
https://github.com/reactor/reactor-netty/issues/503.

However FluxReceive also rejects subsequent subscribers if the response
is consumed fully, as opposed to being canceled, e.g. as with
bodyToMono(Void.class). In that case, a subsequent subscriber causes
two competing error signals to be sent, and one gets dropped and
logged by reactor-core.

This fix ensures that a rejection is raised in
ReactorClientHttpResponse only after a cancel() was detected.

Issue: SPR-17564
2018-12-04 21:27:37 -05:00
Juergen Hoeller 77ab88b144 Polishing 2018-11-23 13:56:02 +01:00
Juergen Hoeller ae8f680d2e Polishing 2018-11-22 18:21:56 +01:00
Juergen Hoeller bf272b0b21 Nullability fine-tuning based on IntelliJ IDEA 2018.3 inspection
Issue: SPR-15540
2018-11-22 16:12:38 +01:00
Juergen Hoeller b1b28d4641 ToStringVisitor consistently returns platform-independent line breaks
Issue: SPR-17322
2018-11-22 16:11:59 +01:00
Johnny Lim 17b2b8af86 Remove an unnecessary local variable 2018-11-22 13:56:22 +01:00
Rossen Stoyanchev 548126ddd8 Consistently pass param info to ServerWebInputException
Issue: SPR-17232
2018-11-21 14:41:42 -05:00
Arjen Poutsma 88cb126511 Add RequestPredicate Visitor to WebFlux.fn
This commit introduces RequestPredicates.Visitor, an implementation of
the visitor pattern for RequestPredicates.

Issue: SPR-17322
2018-11-20 14:05:17 +01:00
Rossen Stoyanchev abf9ce8a34 Improve handling of empty response with Mono<T>
Issue: SPR-17560
2018-11-19 16:48:38 -05:00
Juergen Hoeller ce5c65c0b0 Upgrade to JAXB 2.3.1, Groovy 2.5.4, Jetty 9.4.14, Tomcat 9.0.13
Includes JAX-WS 2.3.1, Awaitility 3.1.3, OkHttp 3.12, Woodstox 5.2.
2018-11-19 12:41:26 +01:00
Hanope bfb49c7249 Fix typos
See gh-2019
2018-11-19 08:41:21 +01:00
HeemangHan 729ce4108d Correct typos (#2018) 2018-11-17 16:31:01 +01:00
Rossen Stoyanchev c89e6c616a Improve logging of request mapping information
Issue: SPR-17450
2018-11-16 17:30:18 -05:00
Rossen Stoyanchev 9f857c1f16 Replace constant exceptions with inlined ones
Issue: SRP-17475
2018-11-13 14:49:23 -05:00
Juergen Hoeller 40148c0560 Consistent use of ResolvableType.toClass() for assignability checks
Issue: SPR-17086
2018-11-12 20:29:37 +01:00
Juergen Hoeller 3a66927bd2 Polishing 2018-11-12 16:43:43 +01:00
Juergen Hoeller 818c2aa3b9 ServerRequest.attribute(name) defensively accesses concurrent map
Issue: SPR-17486
2018-11-12 16:22:42 +01:00
Juergen Hoeller d96a7b4bfc ClientRequest.attribute(name) defensively handles null value
Issue: SPR-17486
2018-11-12 11:52:21 +01:00
Rossen Stoyanchev a5339d71ea WebClient handles no Content-Type with data correctly
Issue: SPR-17482
2018-11-09 16:16:03 -05:00
Rossen Stoyanchev f5da737bd4 Polish 2018-11-08 23:13:48 -05:00
Rossen Stoyanchev c187cb2fa1 Ensure client response is drained with onStatus hook
Issue: SPR-17473
2018-11-08 22:41:22 -05:00
Rossen Stoyanchev 133b8b0b5a Polish 2018-11-02 16:19:53 -04:00
Rossen Stoyanchev 48654c6483 Polish 2018-11-01 14:21:00 -04:00
Rossen Stoyanchev 9da9bb9652 Fix since tag 2018-10-31 10:56:17 -04:00
Rossen Stoyanchev 3f42e16172 Increase sharing among InvocableHandlerMethod variants
In particular between reactive and non-reactive web variants, but
also preparing for a messaing reactive variant.
2018-10-30 17:15:09 -04:00
Rossen Stoyanchev 7c36549e3a Consistent InvocableHandlerMethod implementations
This commit makes the 3 existing InvocableHandlerMethod types more
consistent and comparable with each other.

1. Use of consistent method names and method order.

2. Consistent error formatting.

3. Explicit for loops for resolving argument values in webflux variant
because that makes it more readable, creates less garabage, and it's
the only way to bring consistency since the other two variants cannot
throw exceptions inside Optional lambdas (vs webflux variant which can
wrap it in a Mono).

4. Use package private HandlerMethodArgumentComposite in webflux
variant in order to pick up the resolver argument caching that the
other two variants have.

5. Polish tests.

6. Add missing tests for messaging variant.
2018-10-30 16:36:01 -04:00
Brian Clozel fc957e95bb Configure ResourceUrlProvider in WebFlux
Prior to this commit, no `ResourceUrlProvider` was configured
in WebFlux (no bean was contributed by the WebFlux infrastructure).
Also, several `ResourceTransformer` instances that extend the
`ResourceTransformerSupport` base class need a `ResourceUrlProvider`
to resolve absolute URLs when rewriting resource URLs. At this point,
no `ResourceUrlProvider` was configured and they could only resolve
relative URLs.

This commit contributes a new `ResourceUrlProvider` to the WebFlux
configuration; this bean can be reused by the WebFlux infrastructure and
application code.

This also automatically configure this shared `ResourceUrlProvider`
instance on the resource chain where needed.

Issue: SPR-17433
2018-10-26 13:56:00 +02:00
Juergen Hoeller 3fee8cb625 Polishing 2018-10-26 11:43:46 +02:00
Vikash Tiwari 8df3fd3f1d Remove unnecessary null check 2018-10-26 10:17:04 +02:00
Brian Clozel 2146e13787 Fix absolute paths when transforming resources
Prior to this commit, `ResourceTransformerSupport.toAbsolutePath`
would call `StringUtils.applyRelativePath` in all cases. But this
implementation is prepending the given path even if the relative path
starts with `"/"`.

This commit skips the entire operation if the given path is absolute,
i.e. it starts with `"/"`.

Issue: SPR-17432
2018-10-25 16:42:47 +02:00
Rossen Stoyanchev 42b7c5a79b Upgrade to Californium snapshots
Towards Californium SR2 to confirm fix for SPR-17306.
2018-10-23 15:52:05 -04:00
Brian Clozel 28cf7b728f Relax handler supports checks in RequestMappingHandlerAdapter
Issue: SPR-17420
2018-10-22 20:31:41 +02:00
Rossen Stoyanchev 862dd23975 Server adapters release buffers on error/cancel
Review and update Servlet and Undertow adapters to release any data
buffers they be holding on to at the time of error or cancellation.

Also remove onDiscard hooks from Reactor and Undertow request body.
For Reactor we expect it to be handled. For Undertow there isn't
any Reactor Core upstream for the callback to be useful.

Issue: SPR-17410
2018-10-19 21:45:14 -04:00
Arjen Poutsma d303c8a20f Store PathPattern instead of String in attributes
This commit changes the attributes stored under
RouterFunctions.MATCHING_PATTERN_ATTRIBUTE and
HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE from a String to a
PathPattern, similar to what annotated controllers set.

Issue: SPR-17395
2018-10-18 14:48:45 +02:00
Juergen Hoeller 93bb78ec23 Avoid private bean classes in integration tests (for CGLIB on JDK 11)
Issue: SPR-16391
2018-10-15 12:26:38 +02:00
Juergen Hoeller 608fd766cb Upgrade to Checkstyle 8.13, Groovy 2.5.3, Aalto XML 1.1.1 2018-10-15 00:01:45 +02:00
Arjen Poutsma 8de5c05af0 Set BEST_MATCHING_HANDLER_ATTRIBUTE in WebFlux.fn
SPR-17367
2018-10-11 13:44:06 +02:00
Brian Clozel ce7278aaf4 Optimize HTTP headers management
Several benchmarks underlined a few hotspots for CPU and GC pressure in
the Spring Framework codebase:

1. `org.springframework.util.MimeType.<init>(String, String, Map)`
2. `org.springframework.util.LinkedCaseInsensitiveMap.convertKey(String)`

Both are linked with HTTP request headers parsing and response headers
writin during the exchange processing phase.

1) is linked to repeated calls to `HttpHeaders.getContentType`
within a single request handling. The media type parsing operation
is expensive and the result doesn't change between calls, since
the request headers are immutable at that point.

This commit improves this by caching the parsed `MediaType` for the
`"Content-Type"` request header in the `ReadOnlyHttpHeaders` class.
This change is available for both Spring MVC and Spring WebFlux.

2) is linked to insertions/lookups in the `LinkedCaseInsensitiveMap`,
which is the data structure behind `HttpHeaders`.
Those operations are creating a lot of garbage (including a lot of
`String` created by `toLowerCase`). We could choose a more efficient
data structure for storing HTTP headers data.

As a first step, this commit is focusing on Spring WebFlux and
introduces `MultiValueMap` implementations mapped by native HTTP headers
for the following servers: Tomcat, Jetty, Netty and Undertow.
Such implementations avoid unnecessary copying of the headers
and leverages as much as possible optimized operations provided by the
native implementations.

This change has a few consequences:

* `HttpHeaders` can now wrap a `MultiValueMap` directly
* The default constructor of `HttpHeaders` is still backed by a
`LinkedCaseInsensitiveMap`
* The HTTP request headers for the websocket HTTP handshake now need to
be cloned, because native headers are likely to be pooled/recycled by
the server implementation, hence gone when the initial HTTP exchange is
done

Issue: SPR-17250
2018-10-11 12:11:47 +02:00
Juergen Hoeller 053820c4ff Polishing 2018-10-09 23:14:49 +02:00
Juergen Hoeller 2b986af310 BasicAuthenticationInterceptor with HttpHeaders.setBasicAuth alignment
Issue: SPR-17326
2018-10-09 23:13:46 +02:00
dmrachkovskyi 983bce125f Defer obtaining argument resolver default value
Issue: SPR-17338
2018-10-05 11:39:19 -04:00
Arjen Poutsma ff7ccf0d4e Only clear request attribute when different
With this commit, we now make sure that the attributes are not cleared
if they are same as the nested request.

Issue: SPR-17304
2018-10-04 16:50:11 +02:00
Arjen Poutsma 9975646ffb Add more RequestPredicate tests for attributes
This commit adds test for delegating request predicates that verify
whether the request attributes are properly restored when a delegate
fails.
2018-10-04 15:18:08 +02:00
Arjen Poutsma 38e5c01c3c Move negating RequestPredicate to RequestPredicates 2018-10-04 15:15:36 +02:00
Sebastien Deleuze 3ff5731429 Leverage ObjectProvider instead of autowired containers
In order to be able to leverage WebFlux configuration in a functional
way, WebHttpHandlerBuilder and RouterFunctionMapping should leverage
new ObjectProvider capabilities to get a sorted list of beans by type
instead of using autowired containers.

Issue: SPR-17327
2018-10-03 14:14:47 +02:00
Rossen Stoyanchev 1320fed7fe Use WebsocketOutbound#sendClose
Switch to using the sendClose method available since Reactor Netty 0.8
vs explicitly sending a CloseWebSocketFrame.

Related to SPR-17306, but does not address the root cause.
2018-10-02 09:37:32 -04:00
Rossen Stoyanchev 7481d73456 WebFlux HandshakeInfo exposes the remoteAddress
Issue: SPR-17192
2018-09-19 16:53:57 -04:00
Rossen Stoyanchev 288a9ecd18 Exposes maxFramePayloadLength for Reactor Netty
Issue: SPR-16228
2018-09-19 16:28:57 -04:00
Brian Clozel d0ada5653f Polish
See: SPR-17054
2018-09-18 11:20:33 +02:00
Arjen Poutsma 88ab911cf1 Provide matched pattern information in WebFlux fn
This commit stores the first matching path pattern in the attribute
`RouterFunctions.MATCHING_PATTERN_ATTRIBUTE`.

Issue: SPR-17098
2018-09-17 14:50:05 +02:00
Arjen Poutsma a680880a9b Restore attributes for failed AND/OR request predicates
This commit restores the attributes when either of the predicates in
an AND/OR conjunction is false.

Issue: SPR-17210
2018-09-17 10:34:52 +02:00
Rossen Stoyanchev db8e9eafb2 Add LogFormatUtils
1. Helper method to eliminate duplication in formatting (de-)serialized
   values for logging introduced with prior commit #e62298.

2. Helper method for TRACE vs DEBUG logging with different details.

Issue: SPR-17254
2018-09-14 18:06:46 -04:00
Juergen Hoeller 66c66baa8f Upgrade to Rhino 1.7.10
Includes reordering of web dependency declarations.
2018-09-14 14:03:53 +02:00
Juergen Hoeller cbc0fad961 Upgrade to Kotlin 1.2.70
Includes Hibernate ORM 5.1.16 and Hibernate Validator 6.0.13.
2018-09-13 18:23:42 +02:00
Sebastien Deleuze 48c660fa41 Add support for empty router in RouterFunctionDsl
Issue: SPR-17247
2018-09-05 16:53:59 +02:00
Sebastien Deleuze f8a0e3d084 Support RenderingResponse in RouterFunctionDsl
Issue: SPR-17244
2018-09-05 16:46:12 +02:00
Brian Clozel 482115f3ce Revert "Make DispacherServlet attributes protected"
This reverts commit 253ffd719d.
2018-08-23 16:52:16 +02:00
Brian Clozel 253ffd719d Make DispacherServlet attributes protected
Since the `initStrategies` method is there to be extended, the related
attributes should be `protected` as well.
2018-08-23 15:09:12 +02:00
Sam Brannen a8fbac8472 Polish JavaDoc
Issue: SPR-17174
2018-08-18 18:15:05 +02:00
Juergen Hoeller 6bcb454a0d Polishing 2018-08-16 19:31:10 +02:00
Juergen Hoeller 84300b796c Fix recent javadoc errors
Issue: SPR-17174
2018-08-16 18:51:31 +02:00
Brian Clozel f2506ca7a1 Revert "Infer HTTP 404 from empty Optional/Publisher types"
This reverts commit 7e91733502.
2018-08-15 15:15:35 +02:00
Brian Clozel 7e91733502 Infer HTTP 404 from empty Optional/Publisher types
This commit handles "empty" cases for `ResponseEntity` controller
handler return types when wrapped with a `java.util.Optional` in Spring
MVC or a single `Publisher` like `Mono`.

Given the following example for Spring MVC:

```
@GetMapping("/user")
public Optional<ResponseEntity<User>> fetchUser() {
	Optional<User> user = //...
	return user.map(ResponseEntity::ok);
}
```

If the resulting `Optional` is empty, Spring MVC will infer a
`ResponseEntity` with an empty body and a 404 HTTP response status.

The same reasoning is applied to Spring WebFlux with Publisher types:

```
@GetMapping("/user")
public Mono<ResponseEntity<User>> fetchUser() {
	Mono<User> user = //...
	return user.map(ResponseEntity::ok);
}
```

This feature is only valid for `HttpEntity` return types and does not
apply to `@ResponseBody` controller handlers.

Issue: SPR-13281
2018-08-15 11:59:16 +02:00
Juergen Hoeller de38af6843 Upgrade to JUnit Jupiter 5.3 RC1 (and Jetty 9.4.12 RC1)
Includes Groovy 2.5.2, Undertow 2.0.12, Hibernate Validator 6.0.12.

Issue: SPR-17129
2018-08-14 20:33:30 +02:00
Sam Brannen 8126ffbc8c Fix broken links in JavaDoc
Issue: SPR-17174
2018-08-13 12:22:52 +02:00
Sam Brannen cfb1ed1009 Clean up warnings and delete dead code 2018-08-12 15:55:11 +02:00
Rossen Stoyanchev aef39e8954 Remove test class added by mistake 2018-08-10 16:57:46 +03:00
Rossen Stoyanchev 61c52d64c5 Polish ConcurrentWebSocketSessionDecoratorTests 2018-08-10 16:15:21 +03:00
Sebastien Deleuze 6b6384a09e Improve WebFlux Protobuf support
- Update javadoc for decoding default instances
 - Refactor and simplify tests
 - Add missing tests
 - Refactor decoding with flatMapIterable instead of
   concatMap and avoid recursive call

Issue: SPR-15776
2018-08-09 15:47:45 +02:00
Juergen Hoeller 58e9706991 Polishing 2018-08-09 02:26:36 +02:00
Juergen Hoeller 247ec572b2 Consistent hasAnnotation check for findMergedAnnotation lookup
Issue: SPR-16933
2018-08-08 23:54:56 +02:00
Rossen Stoyanchev a0dfdfcac3 Hierarchy under WebClientResponseException
Issue: SPR-17145
2018-08-08 15:34:08 +03:00
Sebastien Deleuze 7e9b7102b7 Support custom CorsConfigurationSource in AbstractHandlerMapping
This commit allows to specify a custom CorsConfigurationSource
in AbstractHandlerMapping (both Servlet and Reactive variants).

AbstractHandlerMapping#getCorsConfigurations method is now
deprecated.

Issue: SPR-17067
2018-08-08 10:08:55 +02:00
Juergen Hoeller 34ddb88851 ConcurrentModel.addAttribute(String, Object) ignores null value
Issue: SPR-17141
2018-08-07 20:35:34 +02:00
Rossen Stoyanchev 4a18488f30 Update deprecated basic auth client filters.
1. Update ExchangeFilterFunctions to delegate internally to
HttpHeaders.setBasicAuth(user, password).

2. Remove deprecation from
ExchangeFilterFunctions.basicAuthentication(String user, String password)
It is still useful as a filter to insert the header.

3. Update deprecation notes.

Issue: SPR-17099
2018-08-07 10:10:27 +03:00
Juergen Hoeller 943b394992 Polishing 2018-08-06 18:34:00 +02:00
Sebastien Deleuze 2054fa2191 Upgrade to Jetty reactive HTTP client 1.0.1
Issue: SPR-17124
2018-08-06 12:01:29 +02:00
Juergen Hoeller 821ab62492 Upgrade to RxJava 2.2 and Kotlin 1.2.60
Includes latest dependency updates (Mockito 2.21, Log4J 2.11.1, Hibernate ORM 5.3.4, Protobuf 3.6.1, JRuby 9.2, HtmlUnit 2.32, Selenium 3.14) for Spring Framework 5.1.

Issue: SPR-16388
Issue: SPR-16239
2018-08-03 23:18:10 +02:00
Rossen Stoyanchev a8a1fc6de5 Earlier processing of forwarded headers
Forwarded headers are now processed before ServerWebExchange is created
through ForwardedHeaderTransformer which has the same logic as the
ForwardedHeaderFilter but works on the request only.

ForwardedHeaderFilter is deprecated as of 5.1 but if registered it is
removed from the list of filters and ForwardedHeaderTransformer is used
instead.

Issue: SPR-17072
2018-08-03 15:16:09 +03:00
Rossen Stoyanchev aec98268fe maxResponseBody client filter
Issue: SPR-16989
2018-08-02 21:19:22 +03:00
Juergen Hoeller 217aa38cbb Polishing 2018-08-02 18:00:42 +02:00
Juergen Hoeller 2474c48749 Polishing 2018-08-02 16:55:53 +02:00
stsypanov b5c691bdac SPR-17074 Replace pointless wrapping with Arrays.asList with iteration over array 2018-08-02 12:07:00 +02:00
Juergen Hoeller 589b7048ec Avoid synthesizable annotation creation for @Bean/@Scope processing
Includes consistent (non-)use of AnnotationUtils/AnnotatedElementUtils.

Issue: SPR-16933
2018-08-01 11:43:28 +02:00
Сергей Цыпанов f8340838b3 Use lambda expressions for lazy instantiation (#1911)
Issue: SPR-17074
2018-07-31 13:03:18 +02:00
Juergen Hoeller 4a147d26fc Initialize pre-filled HashMaps with large enough capacity
Empty Maps are preferably initialized without capacity (not initializing them at all or lazily initializing with default capacity when needed).

Issue: SPR-17105
2018-07-30 22:07:31 +02:00
Rossen Stoyanchev 91d17cf628 Add notes on future deprecation of the RestTemplate
Issue: SPR-16993
2018-07-27 08:41:20 -04:00
Rossen Stoyanchev f5ff1dc3f9 Comment on difference in matrix variable test
Based on discussion under
https://github.com/spring-projects/spring-framework/pull/1901
2018-07-27 08:40:36 -04:00
Juergen Hoeller 2b2bf27933 Polishing 2018-07-25 15:26:52 +02:00
Juergen Hoeller 3881a4aded Polishing 2018-07-25 14:16:02 +02:00
Juergen Hoeller fd8e4abe5d Introduce ResolvableType.toClass() shortcut
Issue: SPR-17086
2018-07-25 14:15:19 +02:00
Sebastien Deleuze d3b244a81b Optimize class detection by sharing the ClassLoader
Issue: SPR-17083
2018-07-25 11:09:42 +02:00
Rossen Stoyanchev 32faf09a80 Add check for mixing @EnableWebMvc and @EnableWebFlux
Issue: SPR-16609
2018-07-24 20:47:26 -04:00
Rossen Stoyanchev 0be8c20fca Consistent logging of selected media types 2018-07-24 20:47:26 -04:00
sdeleuze 36a07aa897 Support Protobuf serialization in WebFlux
This commit introduces Protobuf support in WebFlux via dedicated
codecs.

Flux<Message> are serialized/deserialized using delimited Protobuf
messages with the size of each message specified before the message
itself. In that case, a "delimited=true" parameter is added to the
content type.

Mono<Message> are expected to use regular Protobuf message
format (without the size prepended before the message).

Related HttpMessageReader/Writer are automatically registered when the
"com.google.protobuf:protobuf-java" library is detected in the classpath,
and can be customized easily if needed via CodecConfigurer, for example
to specify protocol extensions via the ExtensionRegistry based
constructors.

Both "application/x-protobuf" and "application/octet-stream" mime types
are supported.

Issue: SPR-15776
2018-07-25 01:17:06 +02:00
Brian Clozel 195f3f07e7 ResponseEntityResultHandler overwrites headers
Prior to this commit, controller handlers (regular and exception
handlers as well) would not overwrite existing HTTP response headers on
the exchange. This would lead to situations where Content-Type values
set during the initial handling phase would not be overwritten when
handling an error later on.

This commit aligns the implementation of that result handler on the
Spring MVC one in that regard.

Issue: SPR-17082
2018-07-24 22:21:30 +02:00
Juergen Hoeller 11881ff211 Polishing 2018-07-24 18:45:52 +02:00