Commit Graph

627 Commits

Author SHA1 Message Date
Stephane Maldini
85a4e5065d Add log4j2 config to spring-web-reactiv 2016-11-23 13:16:54 -05:00
Rossen Stoyanchev
637b6387ea Starting point for reactive WebSocket support
Includes basic abstractions and an RxNetty support to start.

Issue: SPR-14527
2016-11-22 16:24:02 -05:00
Rossen Stoyanchev
a224874b43 Improve resolution of multi-value async model attrs
Multi-value async attributes like Flux and Observable in the model
are treated with Collection semantics and resolved to Mono<List<?>>
prior to rendering.
2016-11-16 14:18:09 -05:00
Brian Clozel
cb44f2746e Prevent resource transformation of gzipped CSS files
When resolved through the `GzipResourceResolver`, CSS files can be
resolved as their pre-gzipped variant, if a ".gz" file is present in the
configured resource locations.

Such resources are gzipped and thus should not be transformed by
`CssLinkResourceTransformer`s, since rewriting those would need to
uncompress/transform/recompress. This would lead to poorer performances
than resolving plain resources and delegating compression to the
container.

This commit checks for `GzippedResource` instances in
`CssLinkResourceTransformer` and avoids processing them.

Issue: SPR-14773
2016-11-16 10:26:09 +01:00
Arjen Poutsma
6de062d198 Fix RouterFunction.andRoute()
Fixed RouterFunction.andRoute signature.

Issue: SPR-14904
2016-11-14 17:17:05 +01:00
Juergen Hoeller
dda9762072 Moved WebExchangeDataBinder to web.bind.support (alongside WebRequestDataBinder)
Issue: SPR-14542
2016-11-08 11:01:58 +01:00
Juergen Hoeller
f0be79e0a1 Promoted BindingContext to web.reactive root (since HandlerResult requires it there)
Issue: SPR-14542
2016-11-08 09:33:49 +01:00
Rossen Stoyanchev
6b73700f74 Reactive support for @ModelAttribute methods
Issue: SPR-14542
2016-11-07 15:03:15 +02:00
Rossen Stoyanchev
e59dcedfee BindingResult inserted before rendering
Issue: SPR-14542
2016-11-07 15:03:15 +02:00
Rossen Stoyanchev
ae003e89c1 HandlerResult provides access to BindingContext
Issue: SPR-14542
2016-11-07 15:03:15 +02:00
Rossen Stoyanchev
6abd4d5ff5 Async model attributes resolved before rendering
Issue: SPR-14542
2016-11-07 15:03:15 +02:00
Rossen Stoyanchev
d163240ed4 Reactive support for Errors argument
Issue: SPR-14542
2016-11-07 15:02:13 +02:00
Rossen Stoyanchev
816e32872a Reactive support for @ModelAttribute argument
Issue: SPR-14542
2016-11-07 15:02:13 +02:00
Rossen Stoyanchev
3230ca6d39 Add ConcurrentModel
This commit adds a Model implementation based on ConcurrentHashMap for
use in Spring Web Reactive.

Issue: SPR-14542
2016-11-07 15:02:13 +02:00
Sebastien Deleuze
b447d7dbe6 Rename expectErrorMatch() to expectErrorMatches() 2016-11-04 17:15:03 +01:00
Sebastien Deleuze
b338e6d7aa Rename expectErrorWith() to expectErrorMatch() 2016-11-04 16:14:09 +01:00
Rossen Stoyanchev
475b876f08 Add ResponseEntity test 2016-11-04 13:18:53 +02:00
Rossen Stoyanchev
c430402872 Improve support for Mono<ResponseEntity<?>>
If the body class is not resolvable from the return type and there is
a body instance we now fall back on the class of the body instance.

Issue: SPR-14877
2016-11-04 12:51:00 +02:00
Juergen Hoeller
84d3808b3b Upgrade to Mockito 2.2
Issue: SPR-14880
2016-11-03 22:53:35 +01:00
Brian Clozel
95abd18fea Fix Exception Handling result handler resolution
Prior to this commit, the wrong `HandlerResultHandler` could be
resolved when handling exceptions; this could happen only if the
original handler and exception handler had different signatures:

```
Publisher<String> originalHandler() { ... }

@ExceptionHandler(MyCustomException.class)
ResponseEntity<Mono<String>> handleException() { ... }
```

In that case, the `ResponseBodyResultHandler` would be used when
handling exceptions instead of the `ResponseEntityResultHandler`.

This commit ensures that the `HandlerResult` returned by the exception
handler is used to resolve the `HandlerResultHandler`. The latter will
process the result and use it to write to the HTTP response.

Issue: SPR-14876
2016-11-03 17:13:54 +01:00
Brian Clozel
0006957274 Support ResponseStatus on reactive controllers
This commit adds support for `@ResponseStatus` annotations on reactive
controller methods. `HandlerResultHandler`s implementations now
set the status on the `ServerWebExchange`, if and only if the
invocation of the controller method succeeded.

Issue: SPR-14830
2016-11-03 12:00:30 +01:00
Sebastien Deleuze
8705df502d Rename Verifier to StepVerifier
Issue: SPR-14800
2016-11-02 19:01:40 +01:00
Rossen Stoyanchev
388e173ba3 Fix NPE in custom @InitBinder resolver initialization
Issue: SPR-14869
2016-11-02 10:00:19 +02:00
Rossen Stoyanchev
6c098b3301 Polish 2016-11-02 09:53:27 +02:00
Sebastien Deleuze
b4b7c278df Update tests according to latest reactor-test changes
- ScriptedSubscriber has been renamed to Verifier
 - The Publisher is passed to create() instead of verify()
 - No more need to specify the generic type explicitly
 - Version is now sync with reactor-core

Issue: SPR-14800
2016-11-01 22:28:50 +01:00
Rossen Stoyanchev
99cacaa72d Improve reactive support for access to Principal
The method to access the Principal from the ServerWebExchange is now
a Mono<Principal> (rather than Optional<Principal>).

There is also support for Principal as a controller method argument.

Issue: SPR-14680, SPR-14865
2016-11-01 18:44:14 +02:00
Rossen Stoyanchev
e1a382b61f Polish 2016-11-01 18:15:11 +02:00
Rossen Stoyanchev
33dbbce182 ApplicationContext-based HttpHandler setup
This commit adds support for detecting the target WebHandler along with
WebFilters, WebExceptionHandlers, and other spring-web reactive
strategies in an ApplicationContext.

WebReactiveConfigurationSupport has @Bean factory methods for
DispatcherHandler and ResponseStatusExceptionHandler.

WebHttpHandlerBuilder has a static factory method that initializes the
builder from an ApplicationContext. This method is also used in the
DispatcherHandler#toHttpHandler(ApplicationContext) shortcut method.

Issue: SPR-14837
2016-10-31 20:45:26 +02:00
Rossen Stoyanchev
3da0295c12 Support for reactive controller @InitBinder methods
Issue: SPR-14543
2016-10-31 16:11:44 +02:00
Rossen Stoyanchev
0b76b6d7e9 Sync semantics for WebExchangeDataBinder factory
The createBinder method in BindingContext now returns the binder
instance rather than a Mono with the expectation that binder
initialization (e.g. @InitBinder) does not require blocking.

Issue: SPR-14543
2016-10-31 16:11:44 +02:00
Rossen Stoyanchev
b55ab1119e Sync argument resolution and HandlerMethod invocation
HandlerMethodArgumentResolver is a non-blocking contract, however only
implementations that read the request body require blocking.

This commit introduces SyncMethodArgumentResolver as an extension of
the non-blocking contract that allows synchronous implementations to
use synchronous argument resolution.

There is also a SyncInvocableHandlerMethod extension that uses only
sync argument resolvers and allows a synchronous invocation.

Issue: SPR-14543
2016-10-31 16:11:44 +02:00
Juergen Hoeller
ac80ac6f8b Consistent instanceof/casting of Class references 2016-10-30 21:40:27 +01:00
Juergen Hoeller
7627c38695 Exceptions thrown from @ExceptionHandler methods logged at warn level (instead of debug)
Issue: SPR-14861
2016-10-30 21:40:20 +01:00
Sam Brannen
a04b6c5142 Clean up warnings in Gradle build 2016-10-28 16:25:29 +02:00
Juergen Hoeller
1b0b269370 DefaultServerResponseBuilder uses Reactor's new thenEmpty method (fixing deprecation error) 2016-10-27 17:41:33 +02:00
Sebastien Deleuze
2075932780 Add support for RxJava 2 Maybe type
Issue: SPR-14843
2016-10-25 16:49:22 +02:00
Arjen Poutsma
20dec61d04 Refactored BodyInserters
This commit introduces a couple of changes to BodyInserters:

- Refactored writeWithMessageWriters into BiFunction
- BodyInserters.fromResource now uses ResourceMessagewriter from context
- BodyInserters.fromServerSentEvents now uses SseHttpMessageWriter from context
2016-10-25 11:11:58 +02:00
Brian Clozel
99a3210859 Refactor tests with ScriptedSubscriber
Reactor recently added the `ScriptedSubscriber` in its new
`reactor-addons` module. This `Subscriber` revissits the previous
`TestSubscriber` with many improvements, including:

* scripting each expectation
* builder API that guides you until the final verification step
* virtual time support

This commit refactor all existing tests to use this new
infrastructure and removed the `TestSubscriber` implementation.

Issue: SPR-14800
2016-10-25 10:44:44 +02:00
Brian Clozel
61cf9fdda5 Remove factory methods from WebReactiveConfigurer
This commit removes factory methods for `RequestMappingHandlerMapping`
and `RequestMappingHandlerAdapter` from `WebReactiveConfigurer`.
`WebReactiveConfigurer` should promote only common customizations;
those factory methods should be overridden when extending
`WebReactiveConfigurationSupport`, in advanced configuration scenarios.
2016-10-21 21:19:32 +02:00
Arjen Poutsma
08931950f4 Add byte[] encoder and decoder
This commit adds a ByteArrayDecoder and ByteArrayEncoder.
2016-10-21 12:34:06 +02:00
Juergen Hoeller
3726c6f18d Polishing 2016-10-21 12:26:27 +02:00
Rossen Stoyanchev
b92d541ba0 Add contextPath support for reactive web applications
This commit introduces support for running multiple HttpHandler's under
distinct context paths which effectively allows running multiple
applications on the same server. ContextPathIntegrationTests contains
an example of two applications with different context paths.

In order to support this the HttpHandler adapters for all supported
runtimes now have a common base class HttpHandlerAdapterSupport
which has two constructor choices -- one with a single HttpHandler and
another with a Map<String, HttpHandler>.

Note that in addition to the contextPath under which an HttpHandler is
configured there may also be a "native" contextPath under which the
native runtime adapter is configured (e.g. Servlet containers). In such
cases the contextPath is a combination of the native contextPath and
the contextPath assigned to the HttpHandler. See for example
HttpHandlerAdapterSupportTests.

Issue: SPR-14726
2016-10-20 17:42:38 -04:00
Arjen Poutsma
fa9cc1eb1a Add bodyToMono/bodyToFlux convenience methods
This commit adds a bodyToMono and bodyToFlux convenience method to
ClientResponse/ServerRequest, similar to the body(Publisher) method that
is on ClientRequest/ServerResponse.
2016-10-20 16:58:30 +02:00
Arjen Poutsma
59e4326989 Various improvements to web.reactive.function
This commit introduces the following changes to web.reactive.function:

- Added RouterFunction.andRoute(), a combination of RouterFunction.and()
with RouterFunctions.route()
- ServerRequest.pathVariable() returns String instead of
Optional<String>. An exception is thrown if the variable is not present.
- Added HandlerFilterFunction.andThen and HandlerFilterFunction.apply()
2016-10-20 15:11:16 +02:00
Sebastien Deleuze
921bf5fb70 Use the official RxJava to Reactive Streams adapter
This commit removes the usage of Reactor adapters (about to
be moved from Reactor Core to a new Reactor Adapter module).
Instead, RxReactiveStreams is now used for adapting RxJava
1 and Flowable methods are used for RxJava 2.

Issue: SPR-14824
2016-10-20 15:08:05 +02:00
Arjen Poutsma
7e907c1e83 Align web.reactive.function with WebClient
This commit changes web.reactive.function to reflect the introduction of
the new WebClient. Changes include:

- Request -> ServerRequest
- Response -> ServerResponse
- FilterFunction -> HandlerFilterFunction
- StrategiesSupplier -> HandlerStrategies
2016-10-20 12:35:52 +02:00
Arjen Poutsma
0cfb6b37f2 Align Reactive WebClient with web.reactive.function
This commit refactors the web client to be more similar to
web.reactive.function. Changes include:

- Refactor ClientWebRequest to immutable ClientRequest with builder and
   support for BodyInserters.
- Introduce ClientResponse which exposes headers, status, and support
   for reading from the body with BodyExtractors.
- Removed ResponseErrorHandler, in favor of having a ClientResponse
   with "error" status code (i.e. 4xx or 5xx). Also removed
   WebClientException and subclasses.
- Refactored WebClientConfig to WebClientStrategies.
- Refactored ClientHttpRequestInterceptor to ExchangeFilterFunction.
- Removed ClientWebRequestPostProcessor in favor of
   ExchangeFilterFunction, which allows for asynchronous execution.

Issue: SPR-14827
2016-10-20 12:35:23 +02:00
Arjen Poutsma
dc1926a861 Moved BodyExtractor and BodyInserter to http.codec
This commit moves the web.reactive.function.[BodyInserter|BodyExtractor]
to http.codec, so that they can be used from the client as well.

Furthermore, it parameterized both inserter and extractor over
ReactiveHttpOutputMessage and ReactiveHttpInputMessage respectively, so
that they can be limited to only be used on the client or server.
2016-10-20 11:44:01 +02:00
Rossen Stoyanchev
72397e3505 Polish
Issue: SPR-14798
2016-10-19 16:30:52 -04:00
Sebastien Deleuze
50f2cda009 Better encapsulation for CORS default permit configuration
This commit also improves CorsRegistration Javadoc.

Issue: SPR-14798
2016-10-19 15:31:22 -04:00