Commit Graph

260 Commits

Author SHA1 Message Date
Brian Clozel 69ce33e1ee Add WebClient and its WebResponseExtractor API
This commit adds the `WebClient`, which relies on several parts of our
infrastructure:
* a `ClientHttpRequestFactory` to drive the underlying client library
* a `HttpRequestBuilder` builder API to create the client request
* a `WebResponseExtractor` to extract the "low-level"
`ClientHttpResponse` into a higher level representation such as a
decoded body

The `WebResponseExtractors` helper class contains many extractor
implementations all based on the `Flux`/`Mono` composition API.
2016-02-02 14:06:02 +01:00
Brian Clozel f63960af0a Add client Request/Response impl. for RxNetty
This commit adds the `ClientHttpRequest` and `ClientHttpResponse`
implementations for the RxNetty HTTP client.
This client library is based on the `Single` and `Observable`
composition API, so this has to be converted to the `Flux`/`Mono`
variants.
2016-02-02 14:06:01 +01:00
Brian Clozel 255d2de553 Add client Request/Response impl. for Reactor-Net
This commit introduces the `ClientHttpRequest` and `ClientHttpResponse`
implementations for the Reactor-Net HTTP client. This client is already
based on the `Flux` and `Mono` contracts.

This commit also adds a `AbstractClientHttpRequest` to support the
`ClientHttpRequest` implementations; it mirrors the
`AbstractServerHttpResponse` contract with a `beforeCommit` to register
`Supplier`s that should be notified before the request is committed.
2016-02-02 14:06:01 +01:00
Brian Clozel a6469baa4f Add HttpRequestBuilder default implementation
This commit adds a `DefaultHttpRequestBuilder` and its companion static
builders in `HttpRequestBuilders`. This allows to build client requests
with a friendly builder API, inspired by Spring's MockMvc API.
2016-02-02 14:06:01 +01:00
Brian Clozel 0983d302c7 Add base contracts for the Web client
This commit adds the base contracts for the Web client.
The "Reactive" prefixes of the previously commited contracts has been
removed to match the server ones.

Both the `ClientHttpRequest` and the `ServerHttpResponse` extend
`ReactiveHttpOutputMessage`, which now has a `beforeCommit` method,
necessary in both client and server implementations.

`HttpRequestBuilder` will be used by the developers to create requests
with a nice builder API. `ClientHttpRequestFactory` will provide support
for many HTTP client libraries in this new client.
2016-02-02 14:06:01 +01:00
Arjen Poutsma a4be950e37 Polishing 2016-02-02 13:57:02 +01:00
Stephane Maldini 199252cda6 sync 2016-01-28 20:57:24 +00:00
Stephane Maldini 44f4930e29 sync 2016-01-28 20:36:29 +00:00
Stephane Maldini 9204fdc371 fix timer issues
sync reactor-core
2016-01-28 18:59:56 +00:00
Stephane Maldini 28dcf2e78f fix compile test issue 2016-01-28 18:29:54 +00:00
Sebastien Deleuze ee9c5833f5 Update our tests to use TestSubscriber 2016-01-28 10:24:05 +01:00
Rossen Stoyanchev b9f4698b69 Remove license from package infos 2016-01-27 17:45:54 -05:00
Rossen Stoyanchev 381855aaf3 Refine names in web.server and polish Javadoc
WebServerExchange -> ServerWebExchange

Follows the same convention as in the http package also better allowing
the possibility for a client equivalent in the future.

WebToHttpHandlerBuilder -> WebHttpHandlerBuilder
WebToHttpHandlerAdapter -> WebHttpHandlerAdapter

More consistent with Spring conventions.
2016-01-27 17:05:07 -05:00
Rossen Stoyanchev e59b927fd1 Refine web.server package structure
Introduce adapter and handler sub-packages under web.server following a
review prompted by the addition of the session package and the package
cycle it brought in based on dependency on session.WebSessionManager.
2016-01-27 16:26:47 -05:00
Rossen Stoyanchev 407d11a58a Server-side session support
This commit adds initial support for a maintaining a server-side
session with attributes across HTTP requests. The WebSession
abstraction can be accessed via WebServerExchange from a WebFilter or
the target WebHandler.

The session sub-package contains additional abstractions for creating
and managing sessions providing a basis for extensibility (e.g. Spring
Session). Those include WebSessionManager, SessionIdStrategy, and
SessionStore along with a cookie-based session id strategy and an
in-memory session store in use by default.

Note that the current API does not provide a way to invalidate or
re-create the session from server side code.
2016-01-27 16:24:20 -05:00
Rossen Stoyanchev 3744549a3e Add setComplete + beforeCommit to ServerHttpResponse
setComplete replaces writeHeaders as a more general lifecycle method
to perform any kind of handling at the end of request processing, for
example to ensure headers are written if not already.

beforeCommit provides an extension point for an action to be invoked
just before the response is committed, e.g. adding headers/cookies.
2016-01-27 16:24:20 -05:00
Stephane Maldini 03e6d7dabf minor sync 2016-01-27 20:49:18 +00:00
Stephane Maldini 8a6fa02887 Sync with RSC move graph to flow 2016-01-27 17:42:05 +00:00
Sebastien Deleuze dc91c81fc4 Polishing 2016-01-27 17:04:08 +01:00
Sebastien Deleuze 506c4bc27b Finish to cleanup Reactor Buffer usages
We use it only for Reactor Net support now.
2016-01-27 17:01:17 +01:00
Arjen Poutsma c84ef6cbf3 Incorporated misc. suggestions from the PR. 2016-01-27 16:07:02 +01:00
Arjen Poutsma 66c424daf9 Removed DataBufferAllocator.allocateHeapBuffer and allocateDirectBuffer in favor of allocateBuffer. 2016-01-27 16:04:03 +01:00
Arjen Poutsma b8f2388d60 Removed unused classes 2016-01-27 16:04:03 +01:00
Arjen Poutsma 225179bc6f Updated http and web packages to use DataBuffer 2016-01-27 16:04:03 +01:00
Arjen Poutsma 2981b5e6e8 Updated Encoder and Decoder to use DataBuffer 2016-01-27 16:04:03 +01:00
Arjen Poutsma 38ab47f8a0 Added DataBuffer abstraction
Added DataBuffer and DataBufferAllocator, and provided a default NIO
ByteBuffer-based implementation of those, as well as a Netty
ByteBuf-based version.
2016-01-27 16:04:03 +01:00
Stephane Maldini 641a57ec93 no need to convert to array list with last zip signature 2016-01-27 14:59:19 +00:00
Stephane Maldini 10f4f64e6f sync updates with mono 2016-01-26 23:15:55 +00:00
Arjen Poutsma 21fff02dbd Fixing the build that bad boy @smaldini broke 2016-01-26 12:43:59 +01:00
Stephane Maldini ac94bf1120 sync with reactor-stream package-scope change 2016-01-25 09:05:40 +00:00
Stephane Maldini a907898910 fix signature 2016-01-22 23:11:31 +00:00
Stephane Maldini 0ba5e1d21c sync update on reactor-io Buffer move 2016-01-21 11:59:59 +00:00
Rossen Stoyanchev 30b007dc26 Based on fix in core for SPR-13876 2016-01-20 18:01:32 -05:00
Stephane Maldini 4e162122af sync update on reactor-core 2016-01-20 20:50:28 +00:00
Stephane Maldini 7b3e9e0950 move queue.disruptor and packagescope RingBufferUtils/RequestTask 2016-01-20 18:01:07 +00:00
Sebastien Deleuze 4572cfa38c Fix RxJava1Converter -> RxJava1ObservableConverter 2016-01-20 11:45:18 +01:00
Rossen Stoyanchev 2dd9c92267 Update reactor converter package 2016-01-19 21:34:28 -05:00
Stephane Maldini 198e316412 demote cyclic dependency under reactor-core reactor package
-> reactor.Mono : reactor.core.publisher.Mono
-> reactor.Flux : reactor.core.publisher.Flux
-> reactor.Processors : reactor.core.publisher.Processors
-> reactor.Timers : reactor.core.timer.Timers
-> reactor.Subscribers : reactor.core.subscriber.Subscribers
2016-01-19 20:18:47 +00:00
Stephane Maldini 53b76e90fc move BackpressureUtils to subscription 2016-01-19 19:57:34 +00:00
Stephane Maldini bdfdd64db7 merge core.processor and core.publisher 2016-01-19 19:46:46 +00:00
Stephane Maldini 386dfb0881 update DependencyUtils package 2016-01-19 19:30:20 +00:00
Sebastien Deleuze de300e8c00 Fix the Javadoc external links by using a page without frames 2016-01-14 20:01:38 +01:00
Sebastien Deleuze 9436dd7412 Polish Javadoc 2016-01-14 19:18:38 +01:00
Sebastien Deleuze 398eb0b478 Polish packages documentation 2016-01-14 18:54:17 +01:00
Sebastien Deleuze ae6912086a Add packages documentation 2016-01-14 18:45:43 +01:00
Sebastien Deleuze 2cdce62c3d Update README with the Javadoc link 2016-01-14 16:15:34 +01:00
Sebastien Deleuze 14cb20a9f1 Disable uniqueVersion in order to get a reliable Javadoc link 2016-01-14 16:12:27 +01:00
Sebastien Deleuze 22bea1da01 Add sources and Javadoc to the build 2016-01-14 15:38:35 +01:00
Stephane Maldini 89da87a3e5 Async test case to explore jetty/tomcat issues 2016-01-14 12:38:21 +00:00
Sebastien Deleuze 72e5aa39ec Polish @RestController support 2016-01-14 11:06:04 +01:00
Stephane Maldini 1e28dee608 add streaming test, commented due to issue with a tomcat and jetty 2016-01-14 03:59:15 +00:00
Stephane Maldini 0f432f735a use reactor cookie support 2016-01-14 03:34:25 +00:00
Rossen Stoyanchev da90f03f4c Support type-level @ResponeBody (and @RestController) 2016-01-13 18:12:36 -05:00
Rossen Stoyanchev 437c127b62 Log and handle unresolved exceptions
Before this change use of ExceptionHandlingWebHandler did ensure no
error signals are allowed to escape (hence relying on runtime
behavior).

This change ensures the same is done even when
ExceptionHandlingWebHandler is not configured for use, at the lowest
level which is the WebToHttpHandlerAdapter.
2016-01-13 18:06:42 -05:00
Brian Clozel cf6ceeed62 Allow Splitting/aggregation operations in Decoders
When decoding buffers as plain strings, the StringDecoder returns a
Publisher that may produce one or more `onNext` events.
This is perfectly valid, but leads to errors when trying to convert the
resulting Publisher into a `reactor.Mono` or `rx.Single`.

If the original Publisher emits 2 or more `onNext` signals,
converting to:
* `rx.Single` will throw an error saying that the underlying Observable
"emitted too many elements"
* `reactor.Mono` may contain only the first emitted element

This commit adds a `AbstractRawByteStreamDecoder` that takes a
`SubscriberBarrier` to apply splitting/aggregation operations on the
received elements.
The `StringDecoder` class now inherits from this abstract class and
uses one of the provided `SubscriberBarrier` implementations to
buffer all received elements in a single buffer.
2016-01-13 12:23:47 +01:00
Sebastien Deleuze 99e51a9101 Replace Reactor Stream by Flux in tests when possible 2016-01-12 15:27:02 +01:00
Sebastien Deleuze d9b67f5e72 Use Mono semantics for JSON object/array serialization
Before this commit, a handler method returning a stream with a JSON
content-type was producing a JSON object for single element streams
or a JSON array for multiple elements streams.

This kind of dynamic change of the output based on the number of
elements was difficult to handle on client side and not consistent
with Spring MVC behavior.

With this commit, we achieve a more consistent behavior by using
the Mono semantics to control this behavior. Mono (and Promise/Single)
are serialized to JSON object and Flux (and Observable/Stream) are
serialized to JSON array.
2016-01-12 11:31:18 +01:00
Rossen Stoyanchev c3cde84e6b Polish cookie support
HttpCookie is now immutable with factory methods to create a client
cookie (name-value) vs a server cookie (name-value + attributes)
including a builder for the latter.
2016-01-11 22:54:46 -05:00
Sebastien Deleuze ae4b35ced7 Add Mono and Flux support in @RequestMapping handler methods 2016-01-11 13:02:36 +01:00
Rossen Stoyanchev 1faeb0ec87 Add HttpCookie + server support through HttpHeaders 2016-01-10 22:36:45 -05:00
Rossen Stoyanchev f8ef2e0220 Add base classes for ServerHttpRequest/Response impls 2016-01-10 15:46:56 -05:00
Rossen Stoyanchev eedc90818f Re-introduce writeHeaders() in ServerHttpResponse
This commit brings back the writeHeaders method on ServerHttpResponse
that was once added (2a6a4f) and then removed (9c7151).

This version is a little simpler since writeHeaders doesn't explicitly
flush/send headers which runtimes are expected to do by default.
Instead the main purpose of writeHeaders now is to ensure changes made
via HttpHeaders are applied to the underlying runtime response at some
point and we now do that once at the very end.

This approach provides the most flexibility (vs keeping HttpHeaders in
sync) because it allows a full and consistent set of mutative
operations for both headers and cookies (to be added) regardless of the
API exposed by the underlying runtime.
2016-01-10 06:25:12 -05:00
Rossen Stoyanchev 4f614fa0fd Add WebServerExchange
This change adds a WebServerExchange and updates all contracts at the
the same level (i.e. org.springframework.web.server) as well as the
org.springframework.web.reactive level to use it so that all
framework-related code will have access to server-side processing
features such as request attributes (and others to come).
2016-01-08 12:30:13 -05:00
Rossen Stoyanchev 54e4e012b2 Separate out web.server from http.server.reactive
This change separates out lower-level HTTP adapter code from the more
(framework-specific) HTTP processing into a separate package under
org.springframework.web.server (not under org.springframework.http).
2016-01-08 12:29:04 -05:00
Stephane Maldini 94be412327 Remove last Stream reference 2016-01-07 23:41:48 +00:00
Stephane Maldini b4c3a67d2c Use Stream instead of Streams and uncomment reactor test 2016-01-07 23:29:16 +00:00
Rossen Stoyanchev 97af9998d5 Refine exception handling
Refine exception handling responsibilities between the
DispatcherHandler and the HandlerAdapter.
2016-01-07 18:26:27 -05:00
Stephane Maldini 70b8848492 fix Streams to Stream in test 2016-01-07 22:28:35 +00:00
Rossen Stoyanchev 9a1492e401 Polish 2016-01-07 17:09:49 -05:00
Rossen Stoyanchev a712f43654 Polish 2016-01-07 15:26:11 -05:00
Rossen Stoyanchev c3a8bf4d17 Revert "Remove mandatory dependency on Reactor Stream"
This reverts commit d5e6f70483d4a6c8af3cc5e97e52a54e98199169.
2016-01-07 15:23:55 -05:00
Sebastien Deleuze 318092cfd0 Use Mono#defaultIfEmpty instead of Flux#defaultIfEmpty 2016-01-07 15:58:46 +01:00
Sebastien Deleuze 327c420409 Remove mandatory dependency on Reactor Stream with JarJar 2016-01-07 14:51:43 +01:00
Sebastien Deleuze 8ef7e2ff77 Use Reactor 2.5 Flux and Mono Rx light API
Flux and Mono are used both for implementation and exposed at API
level to express 1 versus N semantic and to provide default Rx
operators:
- Flux<T> for multiple values Publisher (issue #48)
- Mono<T> for single value Publisher (issue #50)
- Mono<Void> for Publisher with no value (issue #49)
2016-01-07 11:14:12 +01:00
Rossen Stoyanchev 8ef2ce44f4 Temporarily remove Reactor from integration tests
https://github.com/spring-projects/spring-reactive/issues/57
2015-12-31 13:18:13 -05:00
Rossen Stoyanchev 0aade73c88 Update Servlet + Undertow req & resp implementations
For those runtimes that don't directly support Reacitve Streams this
commit separates more formally Reactive Streams bridge code out of
the request and response implementations which become simple adapters
to the ServerHttpRequest/Response contracts like their RxNetty and
Reactor Net counterparts.
2015-12-31 12:55:09 -05:00
Rossen Stoyanchev 869f6bef40 Polish server request & response implementations 2015-12-31 12:27:40 -05:00
Rossen Stoyanchev 6b05d17248 Response headers always in sync with native response
ServerHttpResponse implementations now immediately propagate
HttpHeaders changes as they so there is no need to call applyHeaders().

The writeHeaders from ServerHttpResponse is also removed. RxNetty and
Reactor Net both support implicitly completing if the handler
completes without explicitly writing the headers or the response body.
2015-12-29 23:13:21 -05:00
Rossen Stoyanchev 34eb6d5426 Add support for @ExceptionHandler methods 2015-12-29 23:13:21 -05:00
Rossen Stoyanchev 8c89b478d9 Add operator for deferred writes 2015-12-29 23:13:21 -05:00
Rossen Stoyanchev 9789db23d2 Rename HandlerResult fields from value to result 2015-12-29 23:13:21 -05:00
Rossen Stoyanchev 84e3ad342b Remove @Ignore from 404 status code tests 2015-12-29 23:13:21 -05:00
Rossen Stoyanchev 9eb07b7780 Update package for reactor Signal 2015-12-29 23:13:21 -05:00
Rossen Stoyanchev a12c172ceb Switch to rxnetty-http dependency
The "rxnetty" artifact is old (October 2015). There is now rxnetty-http
and other modules that have more recent snapshots (December 2015).
2015-12-29 23:13:21 -05:00
Stephane Maldini da4e4aab39 test operator log 2015-12-18 16:56:17 +00:00
Stephane Maldini 15185c75a3 use Publishers.onErrorResumeNext 2015-12-17 13:34:09 +00:00
Rossen Stoyanchev 69973d984d Fix test failure 2015-12-16 12:30:15 -05:00
Rossen Stoyanchev 623874b4d0 Constant HandlerNotFoundException 2015-12-16 11:08:41 -05:00
Rossen Stoyanchev 1b3289d0d5 Add InternalServerErrorExceptionHandler 2015-12-15 17:04:53 -05:00
Rossen Stoyanchev f2cd92a243 Fix imports 2015-12-15 12:09:23 -05:00
Rossen Stoyanchev c13a8c9bb4 DispatcherHandler maps errors to ResponseStatusException
The DispatcherHandler now has an errorMapper property that is a
function for transforming errors. By default this property is set to an
instance of DispatcherHandlerExceptionMapper which wraps "standard"
framework exceptions and @ResponseStatus-annotated exceptions as
ResponseStatusException.

This makes it easy to handle the exceptions downstream uniformly.
2015-12-15 12:08:13 -05:00
Rossen Stoyanchev 1f15b7e074 Add ResponseStatusException
This change adds a ResponseStatusException to associate an exception
with a status code at runtime. Along with that is an
ResponseStatusExceptionHandler that handles ResponseStatusException
by setting the response status.
2015-12-15 12:06:53 -05:00
Rossen Stoyanchev 5231e7da7b Fix failing test 2015-12-10 16:50:28 -05:00
Rossen Stoyanchev a0018d13e1 Add DispatcherHandlerErrorTests
The tests demonstrate failures at various phases of request processing
and the resulting error signals.
2015-12-10 16:35:40 -05:00
Rossen Stoyanchev 4ba3d0736f Add HttpExceptionHandler 2015-12-10 16:35:40 -05:00
Rossen Stoyanchev 448aac813a Add MockServerHttpRequest/Response 2015-12-10 16:35:40 -05:00
Sebastien Deleuze 78454f5a2e Add a link to Spring Reactive Playground 2015-12-09 11:18:50 +01:00
Rossen Stoyanchev ef3560a55a Add HttpHandlerDecorator and fix test package 2015-12-08 22:50:25 -05:00
Rossen Stoyanchev 1dcaff8a5c Updates to Javadoc 2015-12-08 22:50:24 -05:00
Stephane Maldini fbb0c702c9 minor reactor server impl to fulfill core introspection 2015-12-09 01:58:53 +00:00