Commit Graph

507 Commits

Author SHA1 Message Date
Brian Clozel a06da0019f Remove PathPatternParser from PatternsRequestCondition
Since `PathPattern.combine` now returns another `PathPattern` instance
(it was previously returning a String instance), we can now safely
remove the parser instance included in `PatternsRequestCondition`.

Issue: SPR-15663
2017-07-18 11:40:30 +02:00
Rossen Stoyanchev b0422d02dc Resource transformers use AsynchronousFileChannel
Issue: SPR-15773
2017-07-18 03:58:21 +02:00
Rossen Stoyanchev 70252a7335 Add tests for SPR-15777 2017-07-17 08:35:58 +02:00
Rossen Stoyanchev 47b63150d1 Refactor DefaultWebSession
Use copy constructor to refresh a session with lastAccessTime and a
save function referencing the current exchange. As a result both fields
are now final and ConfigurableWebSession is no longer needed.
2017-07-14 22:55:56 +02:00
Rossen Stoyanchev 9d04c0424d Allow empty body with no content type in BodyExtractors
Issue: SPR-15758
2017-07-14 14:38:42 +02:00
Rossen Stoyanchev d2c6ea5b1b Polish 2017-07-14 13:23:11 +02:00
Arjen Poutsma 805b7159b0 Add ParameterizedTypeReference variants to bodyTo[Mono|Flux], toEntity[List]
This commit introduces overloaded variants of `bodytoMono`,
`bodyToFlux`, `toEntity`, and `toEntityList` that take a
`ParameterizedTypeReference`. It also adds similar methods to
`WebClient.ResponseSpec`.

Issue: SPR-15725
2017-07-14 13:09:44 +02:00
Sebastien Deleuze f46520e6e8 Add Jackson Smile support to WebFlux
This binary format more efficient than JSON should be useful for server
to server communication, for example in micro-services use cases.

Issue: SPR-15424
2017-07-13 17:57:07 +02:00
Rossen Stoyanchev ed5cc27f7b Support empty body without content type in WebFlux
Issue: SPR-15758
2017-07-13 11:11:34 +02:00
Arjen Poutsma d6c102d1b8 Add apply method to WebClient.Builder
This commit introduces an apply method to `WebClient.Builder`, allowing
users to make multiple changes to the builder in one consumer.

Issue: SPR-15743
2017-07-12 14:53:06 +02:00
Rossen Stoyanchev 9ac71afbda Fix one failing test and @Ignore another
The failures look like older failures possibly exposed by recent
changes in Reactor.

The one in ViewResolutionResultHandler is very old test error.
The one in Jackson2JsonDecoderTests is more recent but went unreported.
2017-07-12 13:16:51 +02:00
Rossen Stoyanchev befacf4a35 ParameterContentNegotiationStrategy uses MediaTypeFactory
Issue: SPR-15649
2017-07-11 17:54:16 +02:00
Arjen Poutsma c9a3b863c4 Move toEntity(List) from WebClient.ResponseSpec to ClientResponse
This commit moves `toEntity(Class<T>)` and `toEntityList(Class<T>)`
from WebClient.ResponseSpec to ClientResponse. The main reason for doing
so is that the newly introduced `onStatus` method (see
2f9bd6e075) does not apply to these two
methods, and the result would be confusing. Also, `ClientResponse` and
`ResponseEntity` represent the same data: status code, headers, and a
body.

Issue: SPR-15724
2017-07-11 17:40:16 +02:00
Arjen Poutsma 51e02c2911 Add status-based error filter
This commit introduces an ExchangeFilterFunction that throws an
exception given a HTTP status predicate.

Issue: SPR-15724
2017-07-11 16:36:47 +02:00
Arjen Poutsma 2f9bd6e075 Add local error handling in WebClient.retrieve
This commit introduces a way to customize the WebClientExceptions, as
thrown by WebClient.ResponseSpec.bodyTo[Mono|Flux]. The first
customization will override the defaults, additional customizations are
simply tried in order.

Issue: SPR-15724
2017-07-11 16:36:40 +02:00
Arjen Poutsma 2ea693bd83 Add ClientRequest.attribute(String)
This commit adds the attribute(String) convenience method to the
ClientRequest class. It also adapts the Basic Authentication filter to
use it.
2017-07-11 15:41:33 +02:00
Arjen Poutsma e11bb17aa6 Change ServerRequest.attribute(String) to return Object
This commit changes `ServerRequest.attribute(String)`` to return
`Optional<Object>` instead of `Optional<T>`, where `T` was infered
from a type parameter.
2017-07-11 15:41:33 +02:00
Rossen Stoyanchev 0e370e0703 Separate out URL path parsing in PathContainer
PathContainer now has separate parsePath and parseUrlPath methods each
creating PathSegment and UrlPathSegment respectively.
2017-07-11 10:56:19 +02:00
Rossen Stoyanchev 2f17c5f3b6 From static to instance-based PathContainer#subPath 2017-07-11 06:05:36 +02:00
Rossen Stoyanchev 9f7d57f933 Encapsulate choice of URI encoding within RequestPath
Currently the URI path is always treated as UTF-8 so we can eliminate
the encoding parameter from RequestPath#parse.
2017-07-11 06:05:36 +02:00
Rossen Stoyanchev fac35ebec2 Remove PathPatternRegistry 2017-07-10 11:37:18 +02:00
Rossen Stoyanchev 9640cedeae Removing remaining use of PathPattern with String path 2017-07-07 19:20:36 +02:00
Arjen Poutsma 3232cb6260 Avoid required uri when using WebClient w/ base url
This commit makes the `uri` step of the WebClient optional, so that
users who have specified a base URL during WebClient config do not need
to provide an empty one (i.e. `url("")`).

The basic idea of this fix is that the HTTP method methods in WebClient
(`get`, `post`, etc.) should be able to "bypass" the uri stage, and skip
straight to defining headers, or even doing an exchange or retrieve
(i.e. call methods on `RequestHeaderSpec` or `RequestBodySpec`).

I have accomplished this by adding two new composed interfaces:
`RequestHeadersUriSpec` and `RequestBodyUriSpec`.
`RequestHeadersUriSpec` extends from the existing `UriSpec` and
`RequestHeaderSpec`, while `RequestBodyUriSpec` extends from `UriSpec`
and `RequestBodySpec`. These types are returned from the HTTP methods
(`get`, `post` etc). The `uri` methods on these types return a plain
`RequestHeaderSpec` and `RequestBodySpec` (i.e. types without the `uri`
methods), so that you can call `uri` once only.

Issue: SPR-15695
2017-07-07 17:07:15 +02:00
Rossen Stoyanchev 4e95378fc6 Remove unused imports 2017-07-06 15:28:32 +02:00
Rossen Stoyanchev 5f9f323b12 Add logging to randomly failing websocket test 2017-07-06 15:07:41 +02:00
Rossen Stoyanchev acd6b9df06 Fix failing test
Explicitly pass the client-side JSR-356 WebSocketContainer to the
TomcatWebSocketClient to prevent the ContainerProvider from finding
the one from undertow-websockets-jsr through the ServiceLoader API.
2017-07-06 14:32:46 +02:00
Arjen Poutsma b0ab84657b Disable "failOnServerError" in ReactorClientHttpRequest
This commit disables the "failOnServerError" feature on the
`HttpClientRequest`, as wrapped by ReactorClientHttpRequest. 5xx errors
are supposed to be dealt with in the WebClient, not in the lower-level
components.

Issue: SPR-15739
2017-07-06 13:37:21 +02:00
Arjen Poutsma 0065bc5ee5 Support null query param values in ServerRequest.queryParam(String)
Issue: SPR-15740
2017-07-06 12:10:55 +02:00
Arjen Poutsma 74b4c02881 Add ClientRequest attributes
This commit introduces client-side request attributes, similar to those
found on the server-side. The attributes can be used, for instance, for
passing on request-specific information to a globally registered
ExchangeFilterFunction.

The client request builder, as well as WebClient.RequestHeadersSpec and
WebTestClient.RequestHeaderSpec, add methods for adding a single
attribute, as well as manipulating the entire attributes map.

The client request itself adds a accessor for the (immutable) attributes
map.

This commit also introduces a new variant of the basic authentication
filter in ExchangeFilterFunctions. This variant takes the username and
password from well-known attributes.

Issue: SPR-15691
2017-07-05 14:52:38 +02:00
Juergen Hoeller a6d616d844 Exception handler methods may receive original as well as cause
Issue: SPR-15701
2017-07-05 13:39:30 +02:00
Brian Clozel 9c93521512 Leverage PathPatternParser in CORS configuration source
Previously `UrlBasedCorsConfigurationSource` was relying on
`PathMatcher` implementations for matching incoming request lookup paths
with the configured path patterns for CORS configuration.

This commit replaces the use of `PathMatcher` with a `PathPatternParser`
that parses the string patterns into `PathPattenr` instances and allows
for faster matching against lookup paths.

Issue: SPR-15688
2017-07-04 16:01:18 +02:00
Violeta Georgieva fd1859c34c Adapt to the changes in Reactor Netty ClientOptions
ClientOptions/HttpClientOptions are now created via Builder
2017-07-04 15:26:29 +02:00
Rossen Stoyanchev f7478446b7 Improve Object return type support in WebFlux
Issue: SPR-15731
2017-07-04 08:19:50 -04:00
Arjen Poutsma f8589d9eca Return MultiValueMap from ServerRequest.queryParams instead of List
This commit changes ServerRequest.queryParams from returning a
List<String> given a String name, to returning a
MultiValueMap<String, String>, which gives more flexibility.
2017-07-03 16:23:33 +02:00
Arjen Poutsma 2ccbc55ffd Use PathContainer in web.reactive.function.server
This commit uses the newly introduced `PathContainer` and `RequestPath`
support in the functional web framework. It exposes the path container
as property in `ServerRequest`, and uses that in the path-based
`RequestPredicates`.
2017-07-03 13:36:30 +02:00
Rossen Stoyanchev 9528c3532d Fix typo 2017-07-01 21:07:08 -04:00
Rossen Stoyanchev 15cf9c1d78 Switch to ContainerPath variants in HandlerMapping's 2017-07-01 20:05:17 -04:00
Rossen Stoyanchev 145eab9c2f Remove PathMatchResultComparator
Follow-up change to the previous commit.
2017-07-01 17:27:54 -04:00
Rossen Stoyanchev a5e54788cc Remove PathPatternComparator
Direct comparison of a pattern (as a String) to the path does not make
much sense now that we deal with URL encoding through PathContainer
which exposes (safely) decoded path segments.

Removing the PathPatternComparator also means we can keep patterns
pre-sorted instead of sorting them all the time. That probably offsets
any benefits from comparing to the lookup path for direct matches and
patterns are still sorted according to specificity.
2017-06-30 18:19:35 -04:00
Rossen Stoyanchev 8581afa621 WebFlux compiles after PathPattern/Container changes 2017-06-30 18:19:35 -04:00
Arjen Poutsma 930f0f1760 Add ServerRequest.cookies()
This commit introduces a cookies() method on ServerRequest, returning a
MultiValueMap<String, HttpCookie>.

Issue: SPR-15715
2017-06-30 16:31:37 +02:00
Juergen Hoeller cc74a2891a @Nullable all the way: null-safety at field level
This commits extends nullability declarations to the field level, formalizing the interaction between methods and their underlying fields and therefore avoiding any nullability mismatch.

Issue: SPR-15720
2017-06-30 01:54:16 +02:00
Rossen Stoyanchev 8f4eb23540 Remove use of Optional in SyncHandlerMethodArgumentResolver
... and a couple more protected methods in WebFlux

Issue: SPR-15718
2017-06-29 17:19:48 -04:00
Rossen Stoyanchev 7de6cfa1df Refactor WebSession#getAttribute options
Issue: SPR-15718
2017-06-29 15:23:36 -04:00
Rossen Stoyanchev 9253facf02 Refactor ServerWebExchange#getAttribute options
Issue: SPR-15718
2017-06-29 14:55:30 -04:00
Stephane Maldini cd643704ad Update to reactor core 3.1.0.B-S with context update for monoSendOperator
Explicit typing for older jvm compilation in BodyExtractor
2017-06-29 10:47:28 -07:00
Rossen Stoyanchev 67330dfc23 Expose mapped handler as an exchange attribute
Issue: SPR-15564
2017-06-29 13:18:39 -04:00
Rossen Stoyanchev 667437e300 Polish 2017-06-27 18:48:45 -04:00
Sebastien Deleuze d728d597f2 Add missing license headers in Kotlin files 2017-06-27 14:39:26 +02:00
Juergen Hoeller 98642c7e29 Consistent ScriptTemplateView locale resolution via request
Issue: SPR-15064
2017-06-26 23:28:49 +02:00
Rossen Stoyanchev cea1a0f1ca Polish 2017-06-26 15:51:17 -04:00
Violeta Georgieva 9cb74b1399 Enable suspend/resume on reactive TomcatWebSocketSession 2017-06-26 15:39:02 -04:00
Juergen Hoeller 098ff6f0f8 Compatibility with JDK 9 release candidate build (175)
Includes upgrade to Objenesis 2.6, Gradle 3.5.1, RxJava 2.1.1, JSON Binding API 1.0 final.

Issue: SPR-15686
Issue: SPR-15600
2017-06-26 18:58:59 +02:00
Brian Clozel 8ac29c8ce7 Add cloneBuilder method on WebClient.Builder
This commit adds a new `cloneBuilder()` method on `WebClient.Builder`;
we can now reuse the customizations of an existing builder without
sharing its state across several `WebClient` building code paths.

Issue: SPR-15690
2017-06-23 16:16:23 -04:00
Rossen Stoyanchev c37c59f578 Consumer methods for WebHttpHandlerBuilder
Replace the more limited List-based methods to add filtes and exception
handlers with Consumer<List<?>> variants.
2017-06-23 07:12:10 -04:00
Sebastien Deleuze 5c1d8c7c59 Leverage ZonedDateTime in HttpHeaders
This commit introduces 2 new public methods in HttpHeaders in order
to leverage Java 8 ZonedDateTime in addition to the existing long
(with GMT time zone implied) variants:
 - ZonedDateTime getFirstZonedDateTime(String headerName)
 - void setZonedDateTime(String headerName, ZonedDateTime date)

This commit also leverages Java 8 thread-safe DateTimeFormatter for
HttpHeader implementation instead of SimpleDateFormat. As a consequence
of the usage of DateTimeFormatter.RFC_1123_DATE_TIME, HTTP date header
serialization could change slightly for single digit days from for
example "Thu, 01 Jan 1970 00:00:00 GMT" to
"Thu, 1 Jan 1970 00:00:00 GMT".

Issue: SPR-15661
2017-06-23 00:15:51 +02:00
Arjen Poutsma 4f39edc905 Fix initialization issue with headers in DefaultWebClient
This commit fixes a lazy initialization issue in
`headers(Consumer<HttpHeaders>)`.

Issue: SPR-15657
2017-06-21 15:48:48 +02:00
Sebastien Deleuze 59e90943e4 Rename CorsProcessor#processRequest to process 2017-06-21 10:50:09 +02:00
Juergen Hoeller 03133630cb Missing @Nullable annotations in WebFlux, in particular around locale resolution
Issue: SPR-15036
Issue: SPR-15540
2017-06-20 18:08:42 +02:00
Juergen Hoeller c244f33f84 Polishing 2017-06-20 16:50:02 +02:00
Arjen Poutsma 3b1d46b3ba Polishing 2017-06-20 16:34:09 +02:00
Arjen Poutsma 50fc8f4e32 Support Void response body type in WebClient
This commit adds support for Void response body types in the WebClient,
both when using `exchange` with a response.bodyToMono(Void.class), as
well as using `retrieve` with `toEntity(Void.class)`.

Issue: SPR-15679
2017-06-20 16:30:37 +02:00
Arjen Poutsma 4a0597d612 Replace WebClient.filter with Builder.filter
This commit replaces the WebClient.filter method with
WebClient.Builder.filter. The reason for this change is that filters
added via WebClient.filter would be applied in the opposite order of
their declaration, due to the compositional nature of the method,
combined with the immutable nature of the WebClient.
WebClient.Builder.filter does keep the order of the filters, as
registered.

Furthermore, this commit introduces a WebClient.mutate() method,
returning a WebClient.Builder. This method allow to add/remove filters
and other defaults from a given WebClient.

Issue: SPR-15657

Add WebClient.Builder.addFilter

Add Consumer-based headers and cookies methods to builders.

Add WebClient.mutate
2017-06-20 14:25:52 +02:00
Brian Clozel 52148a10b7 Consistently use CodecConfigurer for configuration
This commit changes the `ExchangeStrategies` and `HandlerStrategies`
interfaces to consistently use the `CodecConfigurer` (and
sub-interfaces) for configuring codecs on the server and on the client.

Issue: SPR-15682
2017-06-19 18:42:37 +02:00
Sebastien Deleuze d5f9ad03a7 Support ScriptEngine#eval(String, Bindings) in ScriptTemplateView
Supporting ScriptEngine#eval(String, Bindings) when no render function
is specified allows to support use cases where script templates are
simply evaluating a script expression with an even more simplified
configuration.

This improvement also makes it possible to use script engines that
do not implement Invocable.

Issue: SPR-15115
2017-06-16 10:38:59 +02:00
Sebastien Deleuze 04d5a2951c Remove KClass based Kotlin extensions
Issue: SPR-15660
2017-06-13 18:43:59 +02:00
Arjen Poutsma 7018804e84 ServerRequest.path() should return raw path
After this commit, ServerRequest.path() returns the raw, unencoded path,
as that is expected by the PathPatternParser.
2017-06-13 15:23:46 +02:00
Sebastien Deleuze e0e6736bc5 Introduce LocaleContextResolver in WebFlux
This commit introduces LocaleContextResolver interface, which is used
at ServerWebExchange level to resolve Locale, TimeZone and other i18n
related informations.

It follows Spring MVC locale resolution patterns with a few differences:
 - Only LocaleContextResolver is supported since LocaleResolver is less
   flexible
 - Support is implemented in the org.springframework.web.server.i18n
   package of spring-web module rather than in spring-webflux in order
   to be able to leverage it at ServerWebExchange level

2 implementations are provided:
 - FixedLocaleContextResolver
 - AcceptHeaderLocaleContextResolver

It can be configured with both functional or annotation-based APIs.

Issue: SPR-15036
2017-06-13 15:10:18 +02:00
Stephane Nicoll 58242f2249 Polish 2017-06-13 10:13:14 +02:00
Brian Clozel 233c15b80e Add PathPatternRegistry for handler mapping matching
Previously `HandlerMapping` implementation were heavily relying on
`String` path patterns, `PathMatcher` implementations and dedicated maps
for matching incoming request URL to an actual request handler.

This commit adds the `PathPatternRegistry` that holds `PathPattern`
instances and the associated request handler — matching results are then
shared as `PathMatchResult` instances. `AbstractUrlHandlerMapping` will
use this registry directly, but other components dealing with request
matching (like `PatternsRequestCondition`) will directly use ordered
`PathPattern` collections since ordering is important there.

This opens the door for faster request matching and simplifies the
design of this part.

Issue: SPR-15608
2017-06-12 18:53:05 +02:00
Juergen Hoeller 3ae84d6dd8 Consistent support for Charset/StandardCharsets in UriUtils etc
Issue: SPR-15613
2017-06-12 15:51:45 +02:00
Juergen Hoeller 14161d1dbf Protected applyLifecycleMethods in UrlBasedViewResolver
Issue: SPR-15219
2017-06-12 15:48:59 +02:00
Stephane Nicoll 451b419624 Polish "Use Map#forEach instead of Map#entrySet#forEach"
Closes gh-1449
2017-06-12 14:37:33 +02:00
diguage 2efa06237a Use Map#forEach instead of Map#entrySet#forEach
See gh-1449
2017-06-12 14:37:33 +02:00
Arjen Poutsma 424bc75fb1 Remove headers(HttpHeaders)
This commit removes the headers(HttpHeaders) method on ClientRequest and
ServerResponse, in favor of headers(Consumer<HttpHeaders>), which is
more flexible.
2017-06-12 14:14:40 +02:00
diguage c1d44d9a34 Use the diamond syntax
Closes gh-1450
2017-06-12 09:19:06 +02:00
Rossen Stoyanchev 38a12ed4ba Expose RequestPath in ServerHttpRequest
The new structured getPath() method replaces the existing
getContextPath() + getPathWithinApplication().

Issue: SPR-15648
2017-06-11 21:59:24 -04:00
Rossen Stoyanchev 01a92517bd Refactor RequestedContentTypeResolverBuilder
The revised builder emphasizes creating a list of resolvers either
built-in or custom with each top-level builder method resulting in
adding a resolver.

By default only the Header resolver is configured.

The path extension resolver is removed altogether to discourage its use
but is trivial to create manually with the helpf of
UriUtils#extractFileExtension + MediaTypeFactory.

Issue: SPR-15639
2017-06-09 16:15:38 -04:00
Rossen Stoyanchev b0e8e7f536 Refactor MappingContentTypeResolver implementations
After the removal of suffix pattern matches, there is no longer a need
to expose the list of registered file extensions.

Also polish, refactor, and simplify the abstract base class
AbstractMappingContentTypeResolver and its sub-classes.

Issue: SPR-15639
2017-06-09 16:15:38 -04:00
Rossen Stoyanchev cb604738cf ResourceWebHandler uses MediaTypeFactory directly
There is no need for ResourceWebHandler to go through the
PathExtensionContentTypeResolver when MediaTypeFactory makes it easy to
perform such lookups for a given Resource.

This does not support any extensions explicitly registered through a
WebFluxConfigurer but it would be easy enough to pass those into
ResourceWebHandler as a simple Map<String, MediaType>, should the need
arise.

Issue: SPR-15639
2017-06-09 16:15:38 -04:00
Rossen Stoyanchev b65bfdb979 Remove HttpRequestPathHelper
The use of the undecoded URL path by default and the removal of suffix
pattern matching effectively means HttpRequestPathHelper is no longer
needed.

Issue: SPR-15640, SPR-15639
2017-06-09 16:15:38 -04:00
Rossen Stoyanchev 95196e1aee Use undecoded pathWithinApplication in WebFlux
Introduce pathWithinApplication() in ServerHttpRequest and use it for
request mapping purposes instead of LookupPath.

In turn this means that for request mapping purposes:
1) the path is not decoded
2) suffix pattern matching is not supported

Issue: SPR-15640
2017-06-09 16:15:38 -04:00
Arjen Poutsma 5e954dcba0 Use ParameterizedTypeReference in public-facing WebFlux APIs
This commit changes the use of `ResolvableType` to
`ParameterizedTypeReference` in all public-facing WebFlux APIs. This
change removes the necessity for providing the parameterized type
information twice: once for creating the `ResolvableType`, and once for
specifying a `BodyExtractor`.

Issue: SPR-15636
2017-06-09 13:29:15 +02:00
Sebastien Deleuze b6c09fa76a Disambiguate BodyExtractors/Inserters Kotlin function names 2017-06-09 01:51:28 +03:00
Sebastien Deleuze 86580b2358 Polishing 2017-06-09 01:49:56 +03:00
Sebastien Deleuze 8579ae66fc Add comprehensive tests of Kotlin extensions
This commit also removes extensions hidden by Java API (varargs).
2017-06-09 01:01:16 +03:00
Juergen Hoeller fd53d2a51a Consistent use of @Nullable in spring-test
This commit also removes nullability from two common spots: ResolvableType.getType() and TargetSource.getTarget(), both of which are never effectively null with any regular implementation. For such scenarios, a non-null empty type/target is the cleaner contract.

Issue: SPR-15540
2017-06-08 22:52:59 +02:00
Arjen Poutsma bf66f45283 Support overriding, removing headers in ClientRequest
This commit adds two Consumer based methods to ClientRequest that allow
for direct manipulation of the underlying headers or cookies map. As
such, these methods can be used to override or remove existing entries.

Issue: SPR-15635
2017-06-08 14:00:39 +02:00
Arjen Poutsma 510436bae9 Copy header values instead of header lists in DefaultClientRequestBuilder
This commit changes the `headers(HttpHeaders)` method in
DefaultClientRequestBuilder so that it copies the individual header
values instead of using the `List<String>` value directly. The reason
for this change is that the list of values can be immutable, and adding
additional values after that could result in
UnsupportedOperationExceptions.
2017-06-07 17:55:51 +02:00
Juergen Hoeller f813712f5b Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments.

Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit.

Issue: SPR-15540
2017-06-07 14:19:15 +02:00
Rossen Stoyanchev 4244df740b Consolidate matrix vars parsing in HttpRequestPathHelper
Restore matrix variable parsing code not resorting to the use of
WebUtils which brings Servlet API dependencies with it.

Instead the parsing logic is now exposed through HttpRequestPathHelper
which already contained the decoding logic and also the knowledge of
whether to decode the parsed variables or not.

Issue: SPR-15397
2017-06-02 15:52:44 -04:00
Rossen Stoyanchev d2685dfe67 Add static factory/accessor methods to LookupPath
Issue: SPR-15397
2017-06-02 15:15:42 -04:00
Rossen Stoyanchev a7020e419a Polish use of LookupPath 2017-06-02 14:46:34 -04:00
Brian Clozel cf1bc81199 Introduce LookupPath in WebFlux request routing
This commit adds the `LookupPath` class that contains the full
request path relative to the web context; the application can
get from it various information, including the file extension
and path parameters (if any).

Since that operation is done multiple times for each request, this
object is stored as an attribute at the `ServerWebExchange` level.

Issue: SPR-15397
2017-06-01 18:31:04 +02:00
Brian Clozel 0557404715 Throw exception for illegal PathMatch configurations
With the new `ParsingPathMatcher` implementation, new patterns are now
allowed, such as `"/foo/{*bar}". The `"{*bar}"` segment will capture
everything until the end of the given path. Adding other elements after
that segment is illegal and will throw exceptions.

One can configure on a `PathMatchConfigurer` various options like
`useTrailingSlashMatch` and `useSuffixPatternMatch`; those options, when
enabled, will try to append suffixes like `".*"` and `"/"` to existing
path patterns. In case of a "capture the rest" pattern segment, those
options won't be honored.

This is why this commit ensures that an exception is thrown at the start
of the application if an illegal configuration is applied to the
`PathMatchConfigurer`.

Issue: SPR-15303, SPR-15558
2017-06-01 18:30:18 +02:00
Arjen Poutsma 8ea54270e1 Allow for null query parameter values in ServerRequest
With this commit, ServerRequest allows for `null` values in query
parameters, treating them as empty values instead.

Issue: SPR-15609
2017-06-01 18:00:54 +02:00
Sebastien Deleuze 1f28825f9d Add more @Nullable parameters based on null usage
Issue: SPR-15540
2017-05-31 21:42:23 +02:00
Sebastien Deleuze c3e6afb879 Improve null-safety to fix some Spring Boot warnings
Issue: SPR-15540
2017-05-31 17:14:49 +02:00
Sebastien Deleuze b47d713e14 Add missing @Nullable annotations on parameters
Issue: SPR-15540
2017-05-31 16:56:08 +02:00
Rossen Stoyanchev 5dcfd84d3b MockServerHttpRequest and Response set cookie headers
Issue: SPR-15522
2017-05-30 11:00:15 -04:00
Rossen Stoyanchev 67bcef22e4 Polish MockServerHttpRequest|Response 2017-05-30 11:00:15 -04:00
Arjen Poutsma 42d1ba080d Copy MockServerRequest to spring-test
This commit copies the MockServerRequest to the spring-test module, in
the mock.web.reactive.function.server package.

Issue: SPR-15530
2017-05-29 10:16:55 +02:00
Rossen Stoyanchev 1383ad5f91 Reasonable defaults for MultipartHttpMessageWriter
MultipartHttpMessageWriter is now configured to handle JSON and XML
out of the box.
2017-05-27 20:41:07 -04:00
Rossen Stoyanchev 1328c8f46e Simplify CodecConfigurer related type names
Essentially drop "Configurer" suffix from nested interfaces.
2017-05-27 20:41:07 -04:00
Sebastien Deleuze 87598f48e4 Introduce null-safety of Spring Framework API
This commit introduces 2 new @Nullable and @NonNullApi
annotations that leverage JSR 305 (dormant but available via
Findbugs jsr305 dependency and already used by libraries
like OkHttp) meta-annotations to specify explicitly
null-safety of Spring Framework parameters and return values.

In order to avoid adding too much annotations, the
default is set at package level with @NonNullApi and
@Nullable annotations are added when needed at parameter or
return value level. These annotations are intended to be used
on Spring Framework itself but also by other Spring projects.

@Nullable annotations have been introduced based on Javadoc
and search of patterns like "return null;". It is expected that
nullability of Spring Framework API will be polished with
complementary commits.

In practice, this will make the whole Spring Framework API
null-safe for Kotlin projects (when KT-10942 will be fixed)
since Kotlin will be able to leverage these annotations to
know if a parameter or a return value is nullable or not. But
this is also useful for Java developers as well since IntelliJ
IDEA, for example, also understands these annotations to
generate warnings when unsafe nullable usages are detected.

Issue: SPR-15540
2017-05-27 08:57:01 +02:00
Rossen Stoyanchev 2d37c966b2 Support for decoding @RequestPart content
Issue: SPR-15515
2017-05-26 18:03:01 -04:00
Rossen Stoyanchev 718162b8c4 Fix issue with "redirect:" when a media type is present
Issue: SPR-15291
2017-05-24 16:31:05 -04:00
Rossen Stoyanchev 9b53b86d24 Check Reactor presence after Undertow for WebSocket
Issue: SPR-15539
2017-05-24 15:05:59 -04:00
Arjen Poutsma a5b94f3a77 Use HttpRequest.getMethodValue
This commit uses the newly introduced HttpRequest.getMethodValue in
the webflux module.

Issue: SPR-15545
2017-05-24 17:19:43 +02:00
Arjen Poutsma 31d1e26c95 Use List<T> instead of Supplier<Stream<T>>
This commit changes all methods that return `Supplier<Stream<T>` to
return `List<T>` instead. This includes the HandlerStrategies, but also
BodyInserter.Context, BodyExtractor.Context, and ServerResponse.Context.

The reason for this change is that most of the strategies have some sort
of order, where more specific message readers - for instance - come
before generic ones. Such an ordering can only be enforced through a
List.

Issue: SPR-15578
2017-05-24 13:48:03 +02:00
Arjen Poutsma 01e3561db9 Support RouterFunction in @EnableWebFlux
This commit removes the RouterFunctions.toHandlerMapping method, in
favor of native support for RouterFunctions in @EnableWebFlux
configuration classes.

In order to accomplish this, the HandlerStrategies components has been
repurposed to only be used for the "bare-bones" HttpHandler, while the
(newly introduced) RouterFunctionMapping uses the strategies as exposed
through WebFluxConfigurationSupport.

Furthermore, this commit also introduces support for testing
RouterFunctions without resorting to an application context.

Issue: SPR-15536
2017-05-24 11:42:15 +02:00
Rossen Stoyanchev 3f32f72bfc Polish
SPR-15576
2017-05-23 21:57:34 -04:00
Juergen Hoeller 0183576215 Polishing 2017-05-23 22:05:22 +02:00
Juergen Hoeller db69a082d9 Avoid java.util.Optional signatures for simple field access
Issue: SPR-15576
2017-05-23 22:05:15 +02:00
Juergen Hoeller 67881a5726 Polish PathPattern parser (including package change to web.util.pattern)
Issue: SPR-15531
2017-05-17 17:40:25 +02:00
Arjen Poutsma ba39697f2e Expose Principal in ServerRequest
This commit exposes the Principal in ServerRequest.

Issue: SPR-15552
2017-05-16 14:50:57 +02:00
Arjen Poutsma f4cf55cb2b Add support for WebFilter and WebExceptionHandler
This commit adds support for configuring `WebFilter` and
`WebExceptionHandler` instances in HandlerStrategies. It also drops the
"native" support for `ResponseStatusException`s, in favor of the
`ResponseStatusExceptionHandler`, which is registered by default.

Issue: SPR-15518
2017-05-11 11:45:00 +02:00
Arjen Poutsma ad9cf99420 ResourceHandlerFunction returns EntityResponse
The ResourceHandlerFunction now returns an `EntityResponse<Resource>`
(instead of a `ServerResponse`), so that filters can inspect/change the
returned Resource.
2017-05-11 11:45:00 +02:00
Arjen Poutsma 8db4b2f7ed Remove synchronized block around PathPatternParser
Removed the synchronized block around PathPatternParser, since it is
now thread-safe.
2017-05-11 09:55:20 +02:00
Arjen Poutsma f0f3df5cc0 Use PathPattern in PathResourceLookupFunction 2017-05-10 10:12:55 +02:00
Arjen Poutsma 64c0ec3d5e Add test for combining @Controller with RouterFunctions
This commit adds a test for combining RouterFunctions with a
@Controller.

Issue: SPR-15521
2017-05-09 16:38:30 +02:00
Juergen Hoeller 5497416c2d Polishing 2017-05-08 09:10:36 +02:00
Kazuki Shimizu df793392fd Fix javadoc of AbstractHandlerMapping#setPathMatcher 2017-05-08 05:52:15 +09:00
Juergen Hoeller 25aef4d3cc ResponseStatusException reason is optional (with lazily constructed message)
Issue: SPR-15524
2017-05-06 12:53:03 +02:00
Juergen Hoeller 39f8bd663e Polishing 2017-05-05 23:19:08 +02:00
Rossen Stoyanchev 83e0e1604a Refine encoding/decoding exception handling
Starting with removing a package cycle on the use of
ResponseStatusException in the codec package, this commit generally
refines codec exception handling.

The new [Encoding|Decoding]Exception mirror the existing
HttpMessageNot[Readable|Writable]Exception and are used similarly
especially to differentiate betwen 400 and 500 errors when parsing
server request body content.

The commit also aligns some of the exception handling of JSON and XML
on the WebFlux side with that on the Spring MVC side.

Issue: SPR-15516
2017-05-05 14:29:43 -04:00
Juergen Hoeller ba501791c9 Consistent use of WebFlux terminology over Web Reactive 2017-05-05 14:21:01 +02:00
Juergen Hoeller 429d6ac67d Defensive handling of test timeouts with RxNetty and Reactor 2017-05-05 14:19:50 +02:00
Rossen Stoyanchev ac1db169a4 Drop "get" prefix from Part accessor methods 2017-05-04 10:13:16 -04:00
Arjen Poutsma 4525c6a537 Add support for Flux<Part> in BodyExtractors
This commit adds a `toParts` method in `BodyExtractors`, returning a
BodyExtractor<Part>.
2017-05-04 12:39:51 +02:00
Rossen Stoyanchev 6f3051c677 Support for @RequestPart with reactive type wrapper
Issue: SPR-14546
2017-05-03 23:03:47 -04:00
Rossen Stoyanchev fc7bededd0 Support data binding for multipart requests in WebFlux
Issue: SPR-14546
2017-05-03 22:36:04 -04:00
Rossen Stoyanchev b5089ac092 Support @RequestBody Flux<Part> in WebFlux
This commit turns the Synchronoss NIO Multipart HttpMessageReader into
a reader of Flux<Part> and creates a separate reader that aggregates
the parts into a MultiValueMap<String, Part>.

Issue: SPR-14546
2017-05-03 18:46:41 -04:00
Rossen Stoyanchev 4db1eb1e4e Polish 2017-05-02 17:59:22 -04:00
Rossen Stoyanchev 2ccf78743a Move 500 error handling to HttpWebHandlerAdapter
Issue: SPR-15506
2017-05-02 16:44:37 -04:00
Rossen Stoyanchev 1881727b37 Remove ServerWebExchange#getRequestParams
Issue: SPR-15508
2017-05-02 16:09:55 -04:00
Juergen Hoeller 7f19e57d9d Polishing 2017-05-02 21:38:09 +02:00
Rossen Stoyanchev 2390748fd7 WebFlux multpart support polish + minor refactoring 2017-05-01 18:00:08 -04:00
Arjen Poutsma ea85431ac5 Add error filter to WebClient integration test
This commit adds a `WebClient` integration test that shows how to use
`ExchangeFilterFunction`s for error handling purposes.

Issue: SPR-15403
2017-05-01 13:36:35 +02:00
Rossen Stoyanchev c7338c70dc Support async wrappers for Principal and WebSession
Issue: SPR-15494
2017-04-28 16:03:41 -04:00
Sebastien Deleuze f2caaa9195 Add @Request(Param/Part) support for multipart requests
Issue: SPR-14546
2017-04-28 17:02:46 +02:00
Sebastien Deleuze 8e272bc5b0 Expose ServerCodecConfigurer as a bean
With this commit, ServerCodecConfigurer is now exposed as a bean in
order to be provided to DefaultServerWebExchange via
WebHttpHandlerBuilder and HttpWebHandlerAdapter. This allows
DefaultServerWebExchange to get configured codecs for reading form or
multipart requests.

Issue: SPR-14546
2017-04-28 16:42:23 +02:00
Sebastien Deleuze a712c19661 Add multipart support to WebFlux functional API
Issue: SPR-14546
2017-04-28 16:42:23 +02:00
Stephane Nicoll 1b9e12f52f Polish "Use Java 8 forEach method on Map"
Closes gh-1404
2017-04-28 11:07:08 +02:00
Jon Borenstein 13dc0cd828 Use Java 8 forEach method on Map 2017-04-28 11:07:08 +02:00
Juergen Hoeller c668d9a473 Polishing 2017-04-26 18:20:19 +02:00
Arjen Poutsma 4a8c99c9ce Consistent handling of 4xx/5xx status codes in WebClient
This commit changes the handling of 4xx/5xx status codes in the
WebClient to the following simple rule: if there is no way for the user
to get the response status code, then a WebClientException is returned.
If there is a way to get to the status code, then we do not return an
exception.

Issue: SPR-15486
2017-04-26 17:50:59 +02:00
Arjen Poutsma 0e7d6fc4d1 Rename WebClient.ResponseSpec.bodyToEntity[List] to toEntity[List]
This commit renames `WebClient.ResponseSpec.bodyToEntity` to `toEntity`
and similarly renames `WebClient.ResponseSpec.bodyToEntityList` to
`toEntityList`. In both cases, the `body` prefix was dropped because the
return value contains more than the body.

Issue: SPR-15486
2017-04-26 17:50:59 +02:00
Arjen Poutsma b9dbac7b2c Rename ServerResponse.BodyBuilder.body to syncBody
This commit renames the `body(Object)` on ServerResponse to
`syncBody(Object)`. The reason for this is that the original method
name clashed with the `body(Publisher)` method in the Kotlin extension.

The new name nicely reflects the synchronous nature of the method,
 making it less appealing than the `Publisher`-based `body` method.

Issue: SPR-15467
2017-04-25 11:33:47 +02:00
Rossen Stoyanchev cc102c2fcd Properly handle Flux<?> and Flux<Object> in WebFlux
Issue: SPR-15464
2017-04-20 09:19:38 -04:00
Arjen Poutsma d1e0990293 Polishing 2017-04-19 16:49:06 +02:00
Arjen Poutsma 30f61e0c07 Add body(Object) method to ServerResponse.BodyBuilder
This method introduces a new body(Object) to ServerResponse, a shortcut
to body(BodyInserters.fromObject(Object)).

Note that in the implementation of the method, an `instanceof` check is
performed to make sure that the passed argument is not a `Publisher`,
as users should call `body(Publisher, Class)` for sending a reactive
type.

This Publisher-check is also done in the `WebClient`, for the same
reasons.

Issue: SPR-15461
2017-04-19 16:40:23 +02:00
Arjen Poutsma b897f96e0f Use PathRemainingMatchInfo in RequestPredicates
This commit uses the newly introduced PathRemainingMatchInfo
(316a680577) in path-based
RequestPredicates.

Issue: SPR-15419
2017-04-19 10:39:51 +02:00
Rossen Stoyanchev 887e5e50a9 Polish model attribute name checks 2017-04-18 23:10:47 -04:00
Rossen Stoyanchev d78d82c516 Use Conventions for reactive model attribute names
Issue: SPR-14915
2017-04-18 23:00:43 -04:00
Andy Clement 316a680577 Modify getPathRemaining to return remaining path and bound variables
Without this change it was necessary to call getPathRemaining and
then chop up the path and make a call to matchAndExtract to get the
bound variables for the path part that matched. With this change
this is all done in the call to getPathRemaining which returns
an object holding the remaining path and the bound variables.

Issue: SPR-15419
2017-04-18 16:17:44 -07:00
Brian Clozel 88f8df4dce Update Mono.then(Supplier) deprecated calls
Reactor Core has now deprecated the `Mono.then(Supplier)`.
This is now replaced with `Mono.then(Mono.defer(Supplier))`.
2017-04-18 21:11:19 +02:00
Rossen Stoyanchev 3efb76c852 Jackson encoder skips String.class
Jackson2Encoder explicitly disables String from the supported types
consistent with the same change on the decoder side:

0662dbf044

Issue: SPR-15443
2017-04-14 17:21:26 -04:00
Brian Clozel a8d785b87f Move RxNetty support to test scope
The RxNetty runtime support is not meant to be officially supported and
should be restricted to testing purposes only.

Issue: SPR-15444
2017-04-14 19:18:42 +02:00
Sebastien Deleuze 005e85b0f5 Update to latest Reactor 3.1 API changes
Issue: SPR-15318
2017-04-14 13:18:20 +02:00
Sebastien Deleuze e3fae2716e Rename Mono#otherwise[Empty] to switch[onError/IfEmpty]
Issue: SPR-15318
2017-04-13 15:36:34 +02:00
Arjen Poutsma dc279d839b Use refactored CodecConfigurer
This commit changes the `HandlerStrategies` and `ExchangeStrategies`
builders to use the `CodecConfigurer` for configuring Decoder|Encoder
and HttpMessage[Reader|Writer]. Other classes that use `CodecConfigurer`
have also been changed to reflect the refactoring to interfaces.

This commit also removes the ExchangeStrategies methods that take an
application context, as it was too naive approach to simply look up
every message reader and writer in the context.

Issue: SPR-15415, SPR-15435
2017-04-13 11:02:29 +02:00
Sebastien Deleuze 4d9144132e Upgrade to Reactor Core 3.1
Issue: SPR-15318
2017-04-11 18:13:04 +02:00
Rossen Stoyanchev 49ac6d54f7 Apply default content type change to WebFlux
Issue: SPR-15367
2017-04-11 11:54:40 -04:00
Rossen Stoyanchev 3393c10d79 Refactor HttpHeaders "Accept-Language" with Locale 2017-04-11 07:19:07 -04:00
Sebastien Deleuze 23e35c0e1a Handle Jackson InvalidDefinitionException with 5xx status in WebFlux
Issue: SPR-14925
2017-04-11 12:39:09 +02:00
Arjen Poutsma ac27dbea4b Use ServerCodecConfigurer in HandlerStrategies
This commit changes the `HandlerStrategies` builder to use
`ServerCodecConfigurer` for configuring Decoder|Encoder and
HttpMessage[Reader|Writer]. Note that the configurer is not exposed
directly, but wrapped so that `HandlerStrategies` can keep on returning
`this` for a proper builder pattern.

This commit also removes the HandlerStrategies methods that take an
application context, as it was too naive approach to simply look up
every message reader and writer in the context.

Issue: SPR-15415
2017-04-11 11:01:27 +02:00
Arjen Poutsma 82e864b217 Polishing
- Renamed `defaultCodec` to `defaultCodecs`, and `customCodec` to
`customCodecs`
- Added `@Override` annotations where necessary
- Fixed non-parameterized usage for parameterized types.
2017-04-11 11:01:27 +02:00
Sebastien Deleuze d098a4b96b Make CodecException handling consistent
This commit makes CodecException handling consistent between functional
and annotation-based APIs. It now returns by default 4xx status code
for decoding error and 5xx for encoding error + print the error reason
in logs without the full stack trace in both variants.

Issue: SPR-15355
2017-04-10 16:07:56 +02:00
Sebastien Deleuze 9b85c5b636 Rename RouterDsl to RouterFunctionDsl 2017-04-10 10:37:24 +02:00
Sebastien Deleuze 18d8876dc8 Update RouterFunctionExtensions documentation 2017-04-10 10:37:23 +02:00
Juergen Hoeller 5986f881d0 HandlerMethod evaluates ResponseStatus annotation for early caching
Issue: SPR-15227
2017-04-08 15:56:05 +02:00
Rossen Stoyanchev 91977c81ad Support Optional without @RequestParam in WebFlux
The java.util.Optional wrapper should not affect the support for
"request param" arguments with or without the annotation as it
works on the Spring MVC side.
2017-04-07 17:15:07 -04:00
Rossen Stoyanchev 3780d040ee Polish and minor fixes in ViewResolutionResultHandler 2017-04-07 17:15:07 -04:00
Rossen Stoyanchev e4c62cc029 Controller API for view rendering
Issue: SPR-15211
2017-04-07 17:15:07 -04:00
Arjen Poutsma e556aaccee Use PathPattern.getPathRemaining in WebFlux fn
This commit uses the newly introduced
`PathPattern.getPathRemaining(String)` in the functional web framework.
With this change, all path predicates can be used for nested router
functions, so the `pathPrefix` predicate is no longer required and has
been removed.

Issue: SPR-15336
2017-04-07 11:25:15 +02:00
Rossen Stoyanchev b245918574 Fix compiler warning 2017-04-06 16:08:25 -04:00
Rossen Stoyanchev e49d797104 Polish HttpMessageWriterView and view resolution 2017-04-06 14:21:48 -04:00
Rossen Stoyanchev 10aa56aa8d Remove file committed by mistake 2017-04-06 14:20:40 -04:00
Rossen Stoyanchev 43eea41dd6 Polish 2017-04-06 12:54:49 -04:00
Arjen Poutsma 99474376e6 Server HttpMessage[Reader|Writer] in WebFlux fn
This commit introduces support for the server-side methods on
HttpMessageReader and HttpMessageWriter. It does so by introducing an
Optional ServerHttpRequest in BodyInserter.Context, and an Optional
ServerHttpResponse in BodyExtractor.Context. On the client-side, these
optionals return Optional.empty(); on the server-side, they return the
respective server-side messages.

Issue: SPR-15370
2017-04-05 11:36:56 +02:00
Sebastien Deleuze cfc89ebe16 Add WebClient.ResponseSpec Kotlin extensions 2017-04-03 10:41:01 +02:00
Amey Jadiye 472954bbb7 Polish javadoc
Closes gh-1370
2017-04-02 08:06:57 +02:00
Sebastien Deleuze 73b44828e9 Resolve async model attributes in AbstractView
This change allows the functional WebFlux API to support natively
reactive types and also makes it possible for View implementations to
disable async attributes resolution if they want for example take
advantage of stream rendering.

It also makes AbstractView#getModelAttributes() asynchronous.

Issue: SPR-15368
2017-03-30 21:48:45 +02:00
Rossen Stoyanchev 840d7abbf6 Add ResponseSpec to WebClient
Replace the overloaded "retrieve" methods with a single retrieve() +
ResponseSpec exposing shortcut methods (bodyToMono, bodyToFlux)
mirroring the ClientResponse shortcuts it delegates to.

Unlike exchange() however with retrieve() there is no access to other
parts of ClientResponse so ResponseSpec exposes additional shortcuts
for obtain ResponseEntity<T> or ResponseEntity<List<T>>.

Issue: SPR-15294
2017-03-30 12:24:16 -04:00
Arjen Poutsma e6b4edc757 Simplify access to response body in WebClient
This commit makes a change to WebClient in oder to facilitate getting
the response body as a `Mono<Object>` or `Flux<Object>` without having
to deal with `ClientResponse`.

Specifically, this commit:

 - Adds `RequestHeaderSpec.retrieve` methods, next to `exchange`, that
 return the response body (and not a `ClientResponse`). Two convenience
 methods return the response body as `Mono` or `Flux`.
 - Adds ClientResponse.toRequestEntity to convert the ClientResponse
 into a RequestEntity.

Issue: SPR-15294
2017-03-30 08:58:04 -04:00
Sebastien Deleuze 9f321e8d56 Suppress warnings in tests 2017-03-30 14:28:10 +02:00
Sebastien Deleuze e2fd398bad Specify explicitly Kotlin extensions return type
The main purpose is to specify nullability.
2017-03-30 14:25:13 +02:00
Rossen Stoyanchev cd8c365a0d ServerCodecConfigurer as input in HandlerAdapter
The ServerCodecConfigurer is now passed all the way into the
RequestMappingHandlerAdapter which automatically enables the same
defaults even without the Java config and provides extra flexibility
in passing message codec configuration for the future.
2017-03-29 16:33:51 -04:00
Rossen Stoyanchev a8162c03f9 Add ArgumentResolverConfigurer
Replace the List<HandlerMethodArgumentResolver> with a dedicated
configurer that currently has one method accepting custom resolver
registrations.
2017-03-29 15:39:31 -04:00
Arjen Poutsma 118f33aeda Request body improvements in WebClient, WebTestClient
This commit makes changes to WebClient and WebTestClient in oder to
limit setting the body according to HTTP method and also to facilitate
providing the request body as Object.

Specifically, this commit:

 - Moves methods that operate on the request body to a RequestBodySpec
 in both WebClient and WebTestClient, and rename them to `body`.
 These methods now just *set* the body, without performing
 an exchange (which now requires an explicit exchange call).
 - Parameterizes UriSpec in both WebClient and WebTestClient, so that
 it returns either a RequestHeadersSpec or a RequestBodySpec.

Issue: SPR-15394
2017-03-29 12:22:15 -04:00
Rossen Stoyanchev c5bcefbd07 Complete RequestMappingHandlerAdapter refactoring
ControllerMethodResolver now also encapsulates initialization, storage,
and use of HandlerMethodArgumentResolver's by annotated method type.
2017-03-28 17:53:42 -04:00
Rossen Stoyanchev e06871ef17 Internal RequestMappingHandlerAdapter refactoring
Extract controller method caches including associated code and
discovery of @ControllerAdvice components into a separate, package
private helper class (ControllerMethodResolver).
2017-03-27 18:29:03 -04:00
Rossen Stoyanchev f8a21ab11b Add ClientCodecConfigurer
Issue: SPR-15247
2017-03-27 14:57:55 -04:00
Rossen Stoyanchev dc3851df00 Extract AbstractCodecConfigurer base class
Issue: SPR-15247
2017-03-27 14:57:49 -04:00
Sebastien Deleuze 3598addc0e Use FormHttpMessageReader by default in ServerCodecConfigurer 2017-03-26 03:21:05 +02:00
Rossen Stoyanchev 5414cd0cf8 Collape ServerHttpMessage[Reader|Writer]
This commit folds ServerHttpMessage[Reader|Writer] into its parent
HttpMessage[Reader|Writer] with the server methods pre-implemented
by default to be simple pass-through delegates.
2017-03-24 17:48:40 -04:00
Rossen Stoyanchev 4a7218f54f Introduce ServerCodecConfigurer
Issue: SPR-15247
2017-03-24 17:47:44 -04:00
Brian Clozel 2baceac5ff Resolve ResourceUrlProvider from current request
This commit changes `ResourceTransformerSupport` to look for the
`ResourceUrlProvider` in the current request if none is configured on
the resource transformer itself.

Issue: SPR-15369
2017-03-24 16:09:14 +01:00
Brian Clozel fdd503152d VersionResourceResolver should delegate to the chain
Prior to this commit, the `VersionResourceResolver` implementations of
`resolveUrlPathInternal` would delegate to the resolver chain but would
never use the give result if the current request didn't match a
configured version strategy pattern.

This is a problem if the resolver supposed to resolve the resource path
is configured after a `VersionResourceResolver` in the resolver chain;
this means that other resolver never gets to participate in the result
of the chain.

Issue: SPR-15372
2017-03-24 14:14:43 +01:00
Juergen Hoeller 65ba865d70 Support for populating model attributes through data class constructors
Includes a new overloaded ModelAndView constructor with an HttpStatus argument, as well as a HandlerMethodArgumentResolverSupport refactoring (revised checkParameterType signature, actually implementing the HandlerMethodArgumentResolver interface).

Issue: SPR-15199
2017-03-24 12:15:45 +01:00
Rossen Stoyanchev 0662dbf044 String decoding for text only vs any MIME type
Follow-up to:
3d68c496f1

StringDecoder can be created in text-only vs "*/*" mode which in turn
allows a more intuitive order of client side decoders, e.g. SSE does
not have to be ahead of StringDecoder.

The commit also explicitly disables String from the supported types in
Jackson2Decoder leaving it to the StringDecoder in "*/*" mode which
comes after. This does not change the current arrangement since the
the StringDecoder ahead having "*/*" picks up JSON content just the
same.

From a broader perspective this change allows any decoder to deal with
String if it wants to after examining the content type be it the SSE
or another, custom decoder. For Jackson there is very little value in
decoding to String which works only if the output contains a single
JSON string but will fail to parse anything else (JSON object/array)
while StringDecoder in "*/*" mode will not fail.

Issue: SPR-15374
2017-03-23 16:53:06 -04:00
Arjen Poutsma a287e67992 Introduce 'useRegisteredExtensionsOnly' property in classes using MediaTypeFactory
This commit introduces a `useRegisteredExtensionsOnly` property that
indicates whether classes that use the `MediaTypeFactory` for supplying
default media types can do so.

 - In classes that were introduced in Spring 5.0, the
 `useRegisteredExtensionsOnly` property takes the place of the
 `useJaf` property that was removed in 0aaa652
 - In classes that existed before Spring 5.0, the
 `useRegisteredExtensionsOnly` property is added in addition to the
 deprecated `useJaf`, the latter delegating to the former, but with
 flipped behavior.

Issue: SPR-14908
2017-03-23 17:16:46 +01:00
Arjen Poutsma fd1db57e05 Change MediaTypeFactory to return Optional
This commit changes the `MediaTypeFactory` to return
`Optional<MediaType>` (instead of a plain `MediaType`) for the
`getMediaType` methods.

Issue: SPR-14908
2017-03-23 10:14:43 +01:00
Rossen Stoyanchev 3d68c496f1 String encoding for any MIME type
CharSequenceEncoder now supports all MIME types, however since encoding
Flux<String> can overlap with other encoders (e.g. SSE) there are now
two ways to create a CharSequenceEncoder -- with support for text/plain
only or with support for any MIME type.

In WebFlux configuration we insert one CharSequenceEncoder for
text/plain (as we have so far) and a second instance with support for
any MIME type at the very end.

Issue: SPR-15374
2017-03-22 18:01:32 -04:00
Arjen Poutsma 290e9bea14 Change MethodNotAllowedException to use HttpMethod
Changed the MethodNotAllowedException to use HttpMethod, instead of
Strings.
2017-03-22 16:38:41 +01:00
Arjen Poutsma 722e23066c Allow for subclassing ServerResponse
This commit changes `ServerResponse` and subtypes to use properties
instead of fields during response rendering. This allows for overriding
these methods in a response subclass.
2017-03-22 12:52:02 +01:00
Arjen Poutsma 24f7f26fe6 Add RenderingResponse.from
This commit introduces RenderingResponse.from(RenderingResponse),
allowing for easier response filtering.
2017-03-22 12:30:48 +01:00
Arjen Poutsma 54abda5e9e Add RenderingResponse integration test
This commit adds an integration test for the `RenderingResponse`.
2017-03-22 11:56:24 +01:00
Arjen Poutsma d17b99fe37 Fix ofResponseProcessor signature
This commit changes the `HandlerFilterFunction.ofResponseProcessor`
method signature to return `Mono<ServerResponse>`, to better cooperate
with response builders (which all return a `Mono`).
2017-03-22 11:55:15 +01:00
Rossen Stoyanchev a999f40daa Polish + minor refactoring of SSE reader and writer
Instead of accepting List<Encoder|Decoder> and then look for the first
to support JSON, always expect a single JSON [Encoder|Decoder] and use
that unconditionally.

When writing use the nested ResolvableType instead of the Class of the
actual value which should better support generics.

Remove the SSE hint and pass "text/event-stream" as the media type
instead to serve as a hint. We are expecting a JSON encoder and using
it unconditionally in any case so this should be good enough.
2017-03-21 17:32:14 -04:00
Rossen Stoyanchev d0e0b6c8c9 Minor Jackson encoder/decoder refactoring
Consolidate JsonView hint extraction in shared base class.

Rename base class from AbstractJackson2Codec to Jackson2CodecSupport
since the class mainly provides support methods.
2017-03-21 14:51:46 -04:00
Juergen Hoeller e892e02f41 Polishing 2017-03-21 17:44:47 +01:00
Rossen Stoyanchev 124cdb5c58 Polish Javadoc of [Server]HttpMessage[Reader|Writer] 2017-03-21 10:57:21 -04:00
Rossen Stoyanchev 54013a0920 @EnableWebFlux uses ServerHttpMessage[Reader|Writer]
ServerHttpMessage[Reader|Writer] are now expected for WebFlux,
annotated controller endpoint and subsequently the instanceof checks
for HttpMessage[Reader|Writer] vs ServerHttpMessage[Reader|Writer] can
be removed from AbstractMessageReaderArgumentResolver and
AbtractMessageWriterResultHandler.
2017-03-21 10:15:56 -04:00
Rossen Stoyanchev c8671041f1 EncoderHttpMessageWriter supports streaming MediaTypes
Support for flushing in EncoderHttpMessageWriter is now driven from a
configurable list of "streaming" media types with the list including
"application/stream+json" by default.

As a result Jackson2ServerHttpMessageWriter is no longer needed.
2017-03-21 10:15:56 -04:00
Rossen Stoyanchev f65544c192 Introduce ServerHttp[Encoder|Decoder]
ServerHttpEncoder and ServerHttpDecoder are HTTP-specific
specializations that can prepare encoding and decoding hints from
extra information available on the server side.

As a result Jackson2ServerHttpMessageReader is no longer needed.
2017-03-21 10:15:56 -04:00
Rossen Stoyanchev 5f8bc4552f [Encoder|Decoder]HttpMessageWriter server support
There is a natural way to implement ServerHttpMessage[Reader|Writer]
from [Encoder|Decoder]HttpMessageWriter by resolving hints first via
a protected method and then delegating to the regular read or write.

There is no downside either since it does not prevent
[Encoder|Decoder]HttpMessageWriter from being used for both client and
server scenarios while they're more useful.

As a positive side effect AbstractServerHttpMessage[Reader|Writer] can
be removed further simplfications can be made (in a future commit) to
accept ServerHttpMessageWriter for configuration purposes on the server
side and remove instanceof checks for ServerHttpMessageWriter.
2017-03-21 10:15:56 -04:00
Rossen Stoyanchev 1329ccf1bc Update tests to new mime types
This commit updates the test code base to conform to changes in media
types returned by the MediaTypeFactory.

Issue: SPR-14908
2017-03-21 09:39:16 -04:00
Arjen Poutsma 0aaa6528dc Remove JAF references
This commit updates the main code base to conform to the dropped JAF
dependency in MediaTypeFactory. Specifically, it

 - Removes JAF detection (JAF_PRESENT constants)
 - Deprecated useJaf properties, with no direct replacement.
 - Updated docs to remove JAF references, in favor of MediaTypeFactory.

Issue: SPR-14908
2017-03-21 09:11:10 -04:00
Rossen Stoyanchev 76fe5f6fce ResourceHttpMessageWriter refactoring
Fold ResourceRegionHttpMessageWriter into ResourceHttpMessageWriter.
The latter was a private helper (not meant to be exposed) and the two
have much in common now sharing a number of private helper methods.

The combined class does not extend AbstractServerHttpMessageConverter
from which it was not using anything.

Internally the combined class now delegates directly to ResourceEncoder
or ResourceRegionEncoder as needed. The former is no longer wrapped
with EncoderHttpMessageWriter which is not required since "resource"
MediaType determination is a bit different.

The consolidation makes it easy to see the entire algorithm in one
place especially for server side rendering (and HTTP ranges). It
also allows for consistent determination of the "resource" MediaType
via MediaTypeFactory for all use cases.
2017-03-20 09:21:35 -04:00
Sam Brannen d46c307f55 Clean up warnings in spring-webflux module 2017-03-18 16:58:03 +01:00
Sam Brannen ee379f8fc9 Ensure RouterFunctionsTests class compiles in Eclipse
Due to a type inference bug in Eclipse, an additional “hint” is
required in order for RouterFunctionsTests to compile in Eclipse.
2017-03-18 15:06:30 +01:00
Rossen Stoyanchev c735ffb39b Fix content type issue in ResourceRegionHttpMessageWriter
ResourceRegionHttpMessageWriter no longer extends from
EncoderHttpMessageWriter freeing it to pass the correct content type
into the encoder.

Considering that the main benefit of EncoderHttpMessageWriter is to
deal with content type fallback cases, there is nothing to be missed.

Furthermore ResourceRegionHttpMessageWriter is a package private class
that is used internally within ResourceHttpMessageWriter and never
exposed externally as a an actual HttpMessageWriter.

Issue: SPR-15358
2017-03-17 17:29:05 -04:00
Rossen Stoyanchev 2979b37ae3 Consistent use of Mediatype in EncoderHttpMessageWriter
EncoderHttpMessageWriter now consistently uses the same MediaType to
set on the response and to pass to the encoder.

Issue: SPR-15357
2017-03-17 16:33:33 -04:00
Arjen Poutsma 1940f8cf89 Support ResponseStatusException in ServerResponse
This commit adds support for the ResponseStatusException in the
`ServerResponse.writeTo` method.

Issue: SPR-15344
2017-03-17 12:50:12 +01:00
Rossen Stoyanchev f6e2c585c8 Refactor tests to use toExchange() shortcuts
Issue: SPR-15350
2017-03-16 11:55:09 -04:00
Arjen Poutsma 1dc38660e5 Support ResponseStatusException in WebFlux fn
This commit introduces support for the ResponseStatusException in the
functional web framework.

Issue: SPR-15344
2017-03-16 09:40:48 +01:00
Rossen Stoyanchev d39da1d06d Polish + minor HttpHandler refactoring
CompositeHttpHandler is public and called ContextPathCompositeHandler.

Also an overhaul of the Javadoc on HttpHandler, WebHttpHandlerAdapter,
and ContextPathCompositeHandler.
2017-03-15 17:05:20 -04:00
Sebastien Deleuze 170057005e Use .nest() instead of .route() in Kotlin Web DSL
The goal is to have better consistency between Java
and Kotlin functional Web API.
2017-03-15 17:21:04 +01:00
Sebastien Deleuze abc0c6e3e8 Replace RouterFunction.route() by a router() Kotlin helper 2017-03-15 17:17:31 +01:00
Rossen Stoyanchev 164204ca04 Reactive type checks for all argument method resolvers
All method argument resolvers now explicitly check for the presence
of a reactive type wrapper and reject it where not expected.

Issue: SPR-15297
2017-03-14 19:56:31 -04:00
Rossen Stoyanchev a04fef8450 Rename AbstractHandlerResultHandler to HRHSupport 2017-03-14 19:56:31 -04:00
Rossen Stoyanchev a7582fcc23 Polish method parameter handling 2017-03-13 15:38:08 -04:00
Rossen Stoyanchev 5ae9afd5a5 Refactor SyncInvocableHandlerMethod
Switch from extension to delegation model, i.e. delegating to
InvocableHandlerMethod, so that only sync invocation is exposed and
only resolvers of type SyncHandlerMethodArgumentResolver are allowed
to be configured in a cleaner fashion.
2017-03-13 15:38:03 -04:00
Rossen Stoyanchev f490f3ca63 Polish SyncHandlerMethodArgumentResolver hiearchy 2017-03-13 15:37:40 -04:00
Sebastien Deleuze 3c26e7f014 Add seeOther shortcut to ServerResponse.BodyBuilder 2017-03-13 11:32:49 +01:00
Rossen Stoyanchev 2cd6240dab Polish WebHttpHandlerBuilder 2017-03-10 17:04:11 -05:00
Brian Clozel b799013567 Update to Reactor Aluminium SNAPSHOT
Currently the BOM versions are:

* reactor-core 3.0.6.BUILD-SNAPSHOT
* reactor-netty 0.6.2.BUILD-SNAPSHOT

This commit fixes as well a few deprecations in reactor-core.
2017-03-10 15:20:40 +01:00
Sebastien Deleuze 9963c4a495 Fix Kotlin warnings 2017-03-10 10:35:30 +01:00
Rossen Stoyanchev 9aa25c3982 Polish ServerSentEventHttpMessageReader 2017-03-08 16:38:58 -05:00
Rossen Stoyanchev d57d3efc89 Polish default config for ExchangeStrategies
Add default readers and writers from separate methods instead of
having them interleaved which is hard to read and easy to miss.

Issue: SPR-15331
2017-03-08 14:33:44 -05:00
Rossen Stoyanchev 37726f4214 Improved annnotation support in ResolvableMethod 2017-03-06 09:19:57 -05:00
Rossen Stoyanchev 0296d003af Improved generics support in ResolvableMethod 2017-03-06 09:19:57 -05:00
Rossen Stoyanchev cdf19d1db1 @RequestParam tests use ResolvableMethod 2017-03-03 23:43:01 -05:00
Rossen Stoyanchev 6950cc0e64 Move ResolvableMethod
From spring-webflux to spring-web test sources since it is perfectly
usable for testing Spring MVC annotation method support.

Potentially to be promoted further up for use in any module that has
annotation method support. It has spring-core dependencies only
2017-03-03 22:12:33 -05:00
Rossen Stoyanchev 8ed22394cf Refactor ResolvableMethod 2017-03-03 22:12:28 -05:00
Rossen Stoyanchev ccb2c6530e Support for @ControllerAdvice in WebFlux
Issue: SPR-15132
2017-03-02 03:30:34 -05:00
Rossen Stoyanchev 24034447f6 Polish ExceptionHandler initialization
In preparation for SPR-15132
2017-03-01 18:08:41 -05:00
Rossen Stoyanchev d8b150e83d Refactor BindingContext initialization
In preparation for SPR-15132.

Turn the BindingContextFactory into ModelInitializer (both package
private) since creating BindingContext itself is quite simple.

The ModelInitializer also has only one field and no need to be aware
of fields the RequestMappingHandlerAdapter.
2017-03-01 18:08:41 -05:00