Commit Graph

1118 Commits

Author SHA1 Message Date
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
Rossen Stoyanchev c1086f4114 Polish BindingContext
In preparation for SPR-15132.
2017-03-01 18:08:41 -05:00
Juergen Hoeller 2b3fb2f5cc Polishing 2017-02-28 18:37:33 +01:00
Arjen Poutsma 56d669f849 Add permanent/temporary redirect to ServerResponse
This commit adds the temporaryRedirect(URI) and permanentRedirect(URI)
static creation methods to ServerResponse.
2017-02-28 15:47:19 +01:00
Rossen Stoyanchev 5237e47e66 Polish 2017-02-27 17:26:20 -05:00
Rossen Stoyanchev 226c9f9a73 Add WebFlux redirect integration test case
Issue: SPR-15291
2017-02-27 17:14:56 -05:00
Sebastien Deleuze 40ae8d41a4 Introduce ServerResponse Kotlin extensions
Issue: SPR-15293
2017-02-27 19:46:07 +01:00
Sebastien Deleuze 710702acdc Polish Kotlin routing DSL
- typealias to replace types like RouterDsl.() -> Unit by Routes
 - String.invoke() as path("/foo") shortcut
 - String.route() as pathPrefix("/foo").route() shortcut
 - Avoid requiring PathPredicates.* import

Issue: SPR-15292
2017-02-27 19:14:24 +01:00
stonio 7d062df992 Use String#isEmpty()
Closes gh-1335
2017-02-22 11:55:17 +01:00
Juergen Hoeller d2cc97af47 Polishing 2017-02-21 22:41:40 +01:00
Juergen Hoeller 6242e30539 Polishing 2017-02-21 15:27:21 +01:00
Arjen Poutsma 7582adc0bc Fix trailing slash in nested path
This commit adds a trailing slash to the nested path if the request path
also ends with a slash. For instance, given the request "/foo/bar/", and
nested path pattern "/foo/**", we expect the nested path to be “/bar/”,
not “/bar".
2017-02-21 13:46:27 +01:00
Juergen Hoeller 1ddf8ec625 Polishing 2017-02-21 00:04:08 +01:00
Juergen Hoeller 73493bc490 Revised imports in tests (org.jetbrains.annotations.NotNull etc) 2017-02-20 23:00:22 +01:00
Arjen Poutsma 4221a344dc Treat empty Accept header as "*/*"
This commit changes the `accept` RequestPredicate so that it treats an
empty `Accept` header as having the value `*/*`, as per the HTTP spec.
2017-02-20 15:40:24 +01:00
Arjen Poutsma 1efcf26559 Defer evaluation of right-hand route in composed route 2017-02-20 10:59:53 +01:00
Arjen Poutsma 9ab8bd046c Improved logging in functional web framework
This commit improves predicate and route logging in the functional web
framework.
2017-02-20 10:59:23 +01:00
Sebastien Deleuze 4d48fde795 Fix RequestPredicate.route() implementation
Issue: SPR-14954
2017-02-16 23:34:28 +01:00
Sebastien Deleuze 305f303d46 Rename RouterDsl to Routes 2017-02-16 17:23:06 +01:00
Sebastien Deleuze 03f34e24ca Add nested route support to Kotlin DSL
Issue: SPR-14954
2017-02-16 17:22:55 +01:00
Arjen Poutsma 0922943c12 Rename RouterFunctions.subroute() to nest()
This commit renames the `RouterFunctions.subroute()` method to `nest()`, to
better represent what it does.

Issue: SPR-14954
2017-02-16 14:12:25 +01:00
Arjen Poutsma 1d589eb639 Add pathPrefix predicate
Added the `pathPrefix` predicate that tests the start of the request
path against a given pattern.

Issue: SPR-14954
2017-02-16 10:17:04 +01:00
Arjen Poutsma 36db6b2753 Removed json(), html() and xml() predicates
Removed `json()`, `html()` and `xml()` from `RequestPredicates`, since
they were confusingly named and would also require a counterpart that
reads the request `Content-Type` instead of the `Accept` header.
2017-02-15 11:06:08 +01:00
Sebastien Deleuze 7dd0f358ed Avoid using callable reference to stay Kotlin 1.0 compatible 2017-02-14 23:52:58 +01:00
Arjen Poutsma bb9d3e1680 Renamed RouterFunction composition methods
Renamed `RouterFunction.andSame()` to `and()`, and `and()` to
`andOther()`. The reason for this change is that we can expect most
RouterFunctions to be parameterized over ServerResponse, and thus it
makes sense to use the shortest composition method (`and()`) for
composing router functions of the same type.

When a user composes different response types, such as composing a
`RouterFunction<RenderingResponse>` with an
`RouterFunction<EntityResponse<?>`, the `andOther` method is to be used,
but this is a less common scenario.
2017-02-14 15:51:57 +01:00
Arjen Poutsma fcaf42507a Synchronise PathPatternParser access
This commit adds a synchronized block around the PathPatternParser,
since it is not thread-safe.
2017-02-14 12:11:48 +01:00
Sebastien Deleuze f380ab9d90 Polish RouterFunctionExtensions
Issue: SPR-15065
2017-02-13 23:08:56 +01:00
Rossen Stoyanchev 6f68af6860 Uncomment test following fix in reactor-netty 2017-02-13 15:02:42 -05:00
Arjen Poutsma febed19bf4 Use PathPatternParser in function.server
Use new PathPatternParser instead of PathMatcher in
web.reactive.function.server.
2017-02-13 16:44:03 +01:00
Arjen Poutsma a31429be2b Add json, html, and xml RequestPredicates
Added RequestPredicate for JSON, HTML, and XML requests. All three tests
for their respective mime type in the Accept header, as well as checking
for a file extension.
2017-02-13 15:37:50 +01:00
Arjen Poutsma dff9b3b85c Expose BodyInserter in EntityResponse 2017-02-13 15:09:43 +01:00
Sebastien Deleuze ef550c43d6 Flush JSON stream after each element
Issue: SPR-15104
2017-02-13 14:20:19 +01:00
Arjen Poutsma 45770d73ed Remove parameterisation from ClientRequest
This commit removes the parameterisation from ClientRequest, similarly
to ServerResponse. Dropping the parameterisation facilitates a
ClientRequest.from method that also copies the body of the target
request.

SPR-15234 Work in Progress
2017-02-13 13:54:23 +01:00
Brian Clozel 1901cc65fd Use ParsingPathMatcher by default in WebFlux
Issue:
2017-02-10 18:30:28 +01:00
Brian Clozel fa4202f1bd Revert Path Pattern changes in WebFlux
Issue: SPR-14544
2017-02-10 18:30:01 +01:00
Juergen Hoeller e9019cd7d1 Polishing 2017-02-10 10:56:40 +01:00
Brian Clozel 8d43f45515 Reduce API Surface in PathPatternRegistry
This commit reduces the exposition of `PathPattern` instances throughout
the `HandlerMapping` API and removes some methods from its public API.

Issue: SPR-14544
2017-02-09 22:09:46 +01:00
Arjen Poutsma 6dd0e6bfac Reverse "Correct generic type in BodyExtractor for form data"
This commit reverses 9efa976d31, and adds
code comments to highlight why some Body[Inserter|Extractor] instances
returned from Body[Inserters|Extractors] use
ServerHttp[Request|Response] instead of using
Reactive[Input|Output]Message.
2017-02-09 17:23:20 +01:00
Arjen Poutsma 11efbaead9 Ignore JsonStreamingIntegrationTests
Ignoring JsonStreamingIntegrationTests for now, @sdeleuze is aware of the need to fix.
2017-02-09 16:43:12 +01:00
Brian Clozel 09d18f2ef5 Refactor HandlerMapping path match configuration
Since the introduction of `PathPatternRegistry`, the various path match
configuration flags are no longer needed in several places and that
configuration can live in the registry itself.

Issue: SPR-14544
2017-02-09 15:58:16 +01:00
Arjen Poutsma da4af6157e Added ClientResponse.cookies()
Added cookies() method on ClientResponse, that exposes the response
cookies.

Issue: SPR-15236
2017-02-09 15:04:07 +01:00
Arjen Poutsma 2a512d7b9f Introduce EntityResponse
This commit introduces the EntityResponse, an entity-specific subtype of
ServerResponse that exposes the entity itself.
2017-02-09 13:46:00 +01:00
Brian Clozel 18c04815a7 Add PathPatternRegistry
This commit adds the new `PathPatternRegistry`, which  holds a
sorted set of `PathPattern`s and allows for searching/adding patterns

This registry is being used in `HandlerMapping` implementations and
separates path pattern parsing/matching logic from the rest. Directly
using `PathPattern` instances should improve the performance of those
`HandlerMapping` implementations, since the parsing and generation of
pattern variants (trailing slash, suffix patterns, etc) is done only
once.

Issue: SPR-14544
2017-02-09 11:21:33 +01:00
Andy Clement f58ffad939 Introduce PathPatternParser for optimized path matching
This commit introduces a PathPatternParser which parses request pattern
strings into PathPattern objects which can then be used to fast
match incoming string paths. The parser and matching supports the syntax
as described in SPR-14544. The code is optimized around the common usages
of request patterns and is designed to create very little transient
garbage when matching.

Issue: SPR-14544
2017-02-09 11:09:38 +01:00
Brian Clozel 6f029392c7 Move response status processing in InvocableHandlerMethod
Prior to this commit, WebFlux would look at the handler method
annotations (`@ResponseStatus`) for each handler execution, even calling
the expensive `synthesizeAnnotation`.

This commit moves this logic to the InvocableHandlerMethod so that this
executed once at instantiation time and for all result handlers.

Issue: SPR-15227
2017-02-09 10:30:02 +01:00
Rossen Stoyanchev 9efa976d31 Correct generic type in BodyExtractor for form data 2017-02-08 16:46:58 -05:00
Rossen Stoyanchev f2967467e0 Improve writing in mock reactive request and response
Before this change the write Publisher was saved and Mono.empty()
returned from the write metohd which did not properly implement
the write contract since no writing ("consuming") was done.

This can be a problem in some cases. For example the request may appear
to succeed even if the publisher produces an error later when
subscribed to later after request handling completes.

This commit introduces a writeHandler function in the mock request and
response. By default it "writes" by consuming the content immediately,
which allows it to return a Mono<Void> that properly reflects when
writing is done, and it also caches the data so it may be replayed
later for test assertions.

For streaming scenario a custom writeHandler may be registered which
allows the custom handling to determine how long to stream before
cancelling so request handling may complete.

Issue: SPR-14590
2017-02-07 21:57:38 -05:00
Sebastien Deleuze fe05d35292 Polish SseIntegrationTests 2017-02-06 18:24:55 +01:00
Sebastien Deleuze 6b9b0230c4 Introduce JSON streaming support
This commit introduces JSON streaming support which
consists of serializing HTTP request with
application/stream+json media type as line delimited JSON.

It also optimize Flux serialization for application/json by
using flux.collectList() and a single Jackson invocation
instead of one call per element previous strategy.
This change result in a x4 throughput improvement
for collection with a lot of small elements.

Issues: SPR-15095, SPR-15104
2017-02-06 18:14:53 +01:00
Arjen Poutsma 7796c4db14 Introduce RenderingResponse
This commit introduces the RenderingResponse, a template
rendering-specific subtype of ServerResponse that exposes model and
template data.
2017-02-03 11:25:48 +01:00
Eitan Adler 59bba3763d Polish javadoc
Closes gh-1311
2017-02-03 07:36:53 +01:00
Sebastien Deleuze 02c4aff4ce Upgrade to Kotlin 1.1.0-beta-38 2017-02-03 00:33:04 +01:00
Rossen Stoyanchev 1466c82f53 Better support for overriding base URI in WebClient
The base URI is ignored for requests that include a host.

WebClient exposes UriBuilder (rather than UriBuilderFactory) for
per-request URI building based on the base URI. That provides
full control to add or replace components of the base URI.
2017-02-02 17:24:18 -05:00
Rossen Stoyanchev 82a34f4b24 Update WebClient builder
Leave only one static, no-arg build() method for access to a Builder.

URI-related preferences are now exposed on the builder itself.

Improve Javadoc with base URI examples.
2017-02-02 17:17:37 -05:00
Rossen Stoyanchev 7399956708 Rename classes and methods containing "WebReactive"
Issue: SPR-15190
2017-02-02 11:25:54 -05:00
Sebastien Deleuze 123ee5f2da Add WebClient create() and build() static methods 2017-02-02 11:36:45 +01:00
Rossen Stoyanchev 080a3d6a41 Replace use of "Spring MVC" in spring-webflux module
Issue: SPR-15190
2017-02-01 17:50:24 -05:00
Rossen Stoyanchev fafd2d20e1 Rename spring-web-reactive to spring-webflux
Issue: SPR-15190
2017-02-01 17:02:52 -05:00