Commit Graph

666 Commits

Author SHA1 Message Date
Arjen Poutsma
582e625fcf Allow HandlerFunction to return Mono<ServerResponse>
This commit makes it possible for handler functions to return
asynchronous status codes and headers, by making HandlerFunction.handle
return a Mono<ServerResponse> instead of a ServerResponse. As a
consequence, all other types that deal with HandlerFunctions
(RouterFunction, HandlerFilterFunction, etc.) had to change as well.

However, when combining the above change with method references (a very
typical use case), resulting signatures would have been something like:

```
public Mono<ServerResponse<Mono<Person>>> getPerson(ServerRequest request)
```

which was too ugly to consider, especially the two uses of Mono. It was
considered to merge ServerResponse with the last Mono, essentialy making
ServerResponse always contain a Publisher, but this had unfortunate
consequences in view rendering.

It was therefore decided to drop the parameterization of ServerResponse,
as the only usage of the extra type information was to manipulate the
response objects in a filter. Even before the above change this was
suggested; it just made the change even more necessary.

As a consequence, `BodyInserter` could be turned into a real
`FunctionalInterface`, which resulted in changes in ClientRequest.

We did, however, make HandlerFunction.handle return a `Mono<? extends
ServerResponse>`, adding little complexity, but allowing for
future `ServerResponse` subtypes that do expose type information, if
it's needed. For instance, a RenderingResponse could expose the view
name and model.

Issue: SPR-14870
2016-12-14 16:52:36 +01:00
Rossen Stoyanchev
2633b4e9ec RedirectView applies encodeUri + polish 2016-12-14 05:54:53 -05:00
Rossen Stoyanchev
d421112af3 Polish ServerWebExchange builder and ServerHttpResponse
Remove duplicated ServerHttpResponse#setComplete also declard in the
parent ReactiveHttpOutputMessage interface.

Also rename:
ServerWebExchange.MutativeBuilder --> ServerWebExchange.Builder
2016-12-13 17:59:51 -05:00
Brian Clozel
ba47d06cbb Update integration tests for reactor-netty
Now that reactor/reactor-netty#12 is fixed, we can restore the
previously ignored integration tests.
New tests are hanging, so this commit is converting the `StepVerifier`
`verify()` calls to using actual timeouts.

Issue: SPR-14975
2016-12-13 21:34:13 +01:00
Stephane Maldini
6922a1c534 Sync with latest reactor netty changes 2016-12-13 17:22:40 +00:00
Juergen Hoeller
5169c51a6c Polishing 2016-12-13 13:02:23 +01:00
Brian Clozel
52f664139f Improve VersionResourceResolve javadoc
The `pathPatterns` args are relative to the patterns configured for the
resource handler.

Issue: SPR-14817
2016-12-13 10:43:27 +01:00
Rossen Stoyanchev
885e76bdd0 Synchronized lazy start in JettyRequestUpgradeStrategy
Issue: SPR-14527
2016-12-12 21:10:59 -05:00
Rossen Stoyanchev
d6895aa098 Consistently extend WebSocketHandlerAdapterSupport
The WebSocketHandler adapters for all runtimes now extend
WebSocketHandlerAdapterSupport, which now also exposes
a shared DataBufferFactory property initialized from the response.

Issue: SPR-14527
2016-12-12 17:56:48 -05:00
Rossen Stoyanchev
5829e1c141 Polish method and field declaration order 2016-12-12 17:56:48 -05:00
Rossen Stoyanchev
f32a41933e Polish 2016-12-12 17:56:48 -05:00
Rossen Stoyanchev
db5bc4a24e Minor refactoring of suspend/resumeReceiving
suspend/resumeReceiving in the AbstractListenerWebSocketSession are
now abstract methods. In Tomcat/Jetty these methods are no-op
implementations that are then coupled with a buffering strategy via
Flux#onBackpressureBuffer. In Undertow they rely on flow control for
receiving WebSocket messages.

Issue: SPR-14527
2016-12-12 17:56:48 -05:00
Violeta Georgieva
08edec006b Refactor AbstractListenerWebSocketSession
- Added suspended flag to indicate whether the ReceivePublisher
is able to process the incoming messages.
- Use buffer strategy for the incoming messages.

Issue: SPR-14527
2016-12-12 17:56:48 -05:00
Rossen Stoyanchev
d1411d9fc2 Simple refactorings in AbstractListenerWebSocketSessionSupport
Dropped "Support" from the name since it not only provides support
methods but actually implements WebSocketSession.

Renamed inner classes:
WebSocketMessagePublisher -> WebSocketReceivePublisher
WebSocketMessageProcessor -> WebSocketSendProcessor

Add protected getter for sendProcessor.

Reduce scoping:
WebSocketReceivePublisher -> private
WebSocketSendProcessor -> protected
WebSocketSendProcessor#setReady -> public (class is still protected)

A few more method name alignments and Javadoc updates.

Issue: SPR-14527
2016-12-12 17:56:48 -05:00
Rossen Stoyanchev
fe7ee5ff33 Rename "Request/ResponseBody" publisher/processor
AbstractRequestBodyPublisher and AbstractResponseBodyProcessor are now
used for WebSocket messages too and have been renamed more generally to
AbstractListenerReadPublisher and AbstractListenerWriteProcessor.

Issue: SPR-14527
2016-12-12 17:56:48 -05:00
Violeta Georgieva
a2053a516e Initial reactive, WebSocket Jetty support
Issue: SPR-14527
2016-12-12 17:56:47 -05:00
Violeta Georgieva
80040ef43b Initial reactive, WebSocket Undertow support
Issue: SPR-14527
2016-12-12 17:56:47 -05:00
Violeta Georgieva
46b39f4372 Initial reactive, WebSocket Tomcat support
Issue: SPR-14527
2016-12-12 17:56:47 -05:00
Brian Clozel
933f1501e8 Do not include URL hash in resource paths
When getting the lookup path of a resource, both query params and hashes
should be removed from the request path.

This commit fixes the public path resolution for paths like
`/resources/main.svg#icon-hamburgermenu`.

Issue: SPR-14928
2016-12-12 15:14:50 +01:00
Juergen Hoeller
66e6b35e9f Reliable content length check in ResourceHandlerFunctionTests 2016-12-12 09:57:57 +01:00
bedrin
8315a4033f Add consumes attribute to @GetMapping
Issue: SPR-14988
2016-12-07 17:45:43 -05:00
Rossen Stoyanchev
1b0e95d7d8 Support for RequestUpgradeStrategy + Lifecycle
Issue: SPR-15527
2016-12-07 17:03:56 -05:00
Rossen Stoyanchev
2c2de82ffb Flush after each WebSocket message by default
Issue: SPR-14527
2016-12-06 17:08:30 -05:00
Rossen Stoyanchev
c097c0284a Reactor Netty WebSocket server-side support
Issue: SPR-14527
2016-12-06 17:08:30 -05:00
Rossen Stoyanchev
46f2aafdc0 Extract Netty WebSocket session + adapter base classes
Issue: SPR-14527
2016-12-06 17:08:30 -05:00
Arjen Poutsma
30bd3d8736 Allow use of WebFilters in RouterFunction
This commit changes RouterFunctions.toHttpHandler to return
HttpWebHandlerAdapter (instead of HttpHandler), so that WebFilters and
WebExceptionHandler can be applied to it.

Issue: SPR-14979
2016-12-06 17:12:40 +01:00
Rossen Stoyanchev
953f7d40cf Filter out hanging tests realted to Reactor Netty
Issue: SPR-14975
2016-12-05 16:03:12 -05:00
Rossen Stoyanchev
55d4268448 ReactiveAdapterRegistry is a bean 2016-12-02 20:41:39 -05:00
Rossen Stoyanchev
8ad95b09e8 ReactiveContext and BindStatus in spring-web-reactive
Issue: SPR-14533
2016-12-02 11:48:54 -05:00
Arjen Poutsma
136b33bc4a Allow serving static files from RouterFunctions
This commit adds the ability to serve Resources (static files) through a
RouterFunction. Two methods have been added to RouterFunctions: one that
exposes a given directory given a path pattern, and a generic method
that requires a lookup function.

Issue: SPR-14913
2016-12-02 15:47:26 +01:00
Sebastien Deleuze
300f2cd2dd Polish RedirectView
Issue: SPR-14534
2016-12-01 17:27:29 +01:00
Juergen Hoeller
8cb7e026e2 HttpRequestPathHelper in new web.server.support package
In general, web.util is supposed to remain lowest-level, not depending on any other web.* package. Since web.client also has a support package, a corresponding web.server.support package seemed appropriate for a helper class depending on ServerWebExchange in web.server itself.
2016-11-30 11:12:06 +01:00
Rossen Stoyanchev
122334c37a RxNettyWebSocketSession creates PONG frame correctly 2016-11-28 16:48:31 -05:00
Sebastien Deleuze
2e994f7dc3 Add RedirectView to Spring Web Reactive
Main differences with the Spring MVC original implementation:
 - Default redirect HTTP code is 303 See Other since we can assume
   all HTTP clients support HTTP 1.1 in 2016
 - No more http10Compatible property, use statusCode instead
 - By default the redirect is relative to the context path
 - A builder allow to set various properties if needed
 - In UrlBasedViewResolver, a Function<String, RedirectView>
   redirectViewProvider property allows to customize RedirectView
   instances in a flexible way

Issue: SPR-14534
2016-11-28 19:23:42 +01:00
Rossen Stoyanchev
25b95efad9 Shared ReactiveAdapterRegistry in web reactive config 2016-11-28 12:54:48 -05:00
Rossen Stoyanchev
5651c2180e Further refactoring of ReactiveAdapter/Registry
Simplify getAdapterFrom/To into a single getAdapter method that looks
for an exact match by type first and then isAssignableFrom.

Also expose shortcut methods in ReactiveAdapter to minimize the need
for access to the ReactiveTypeDescriptor.

Issue: SPR-14902
2016-11-28 12:43:22 -05:00
Rossen Stoyanchev
52096ab8b9 Refactor ReactiveAdapter hierarchy
Collapse ReactiveAdapter hierarchy into a single class that simply
delegates to functions for converting to/from a Publisher.

A private ReactorAdapter extension automaticlaly wraps adapted,  "raw"
Publisher's as Flux or Mono depending on the semantics of the target
reactive type.

Issue: SPR-14902
2016-11-27 21:41:07 -05:00
Rossen Stoyanchev
2e7d16df04 Improved reactive type descriptor support
ReactiveTypeDescriptor is now a top-level type with named constructors.
It also contains and provides a getter for the actual type.

Issue: SPR-14902
2016-11-27 21:41:07 -05:00
Sebastien Deleuze
a143b57d4b Polish Kotlin nullable support
This commit polishes Kotlin nullable support by reusing
MethodParameter#isOptional() instead of adding a new
MethodParameter#isNullable() method, adds
Kotlin tests and introduces Spring Web Reactive
support.

Issue: SPR-14165
2016-11-24 18:28:50 +01:00
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