Commit Graph

502 Commits

Author SHA1 Message Date
Rossen Stoyanchev d2e105f28d Add @Since 5.0 and package-info for reactive classes 2016-07-14 17:40:17 -04:00
Rossen Stoyanchev 5d1b542698 Move spring-web-reactive classes to spring-web 2016-07-14 12:30:35 -04:00
Rossen Stoyanchev 2e8326220b Move spring-web-reactive classes to spring-core 2016-07-14 12:30:30 -04:00
Rossen Stoyanchev 1022683d1c Fix compiler warnings 2016-07-14 12:18:47 -04:00
Rossen Stoyanchev cb798726bd Update build for spring-web-reactive module 2016-07-14 12:18:39 -04:00
Arjen Poutsma 56e50d6d68 Moved body processor to writeWithInternal()
Moved ResponseBodyProcessor creation from constructor to
writeWithInternal(), in preparation of supporting both
Publisher<DataBuffer> as well as Publisher<Publisher<DataBuffer>>.
2016-07-13 12:04:40 +02:00
Arjen Poutsma 7519d1de41 Moved log4j config to test tree
Moved log4j.properties from the main source tree to the test tree.
2016-07-13 09:56:45 +02:00
Arjen Poutsma f82f17d7f7 Moved Servlet Publisher and Processor
In preparation of supporting both Publisher<DataBuffer> and
Publisher<Publisher<DataBuffer>> as response body, moved
RequestBodyPublisher and ResponseBodyProcessor into
ServletServerHttpRequest and ServletServerHttpResponse respectively.
2016-07-13 09:53:39 +02:00
Arjen Poutsma 392a1660a4 Polishing 2016-07-13 09:53:39 +02:00
Arjen Poutsma e64907eed8 Removed ServletAsyncContextSynchronizer 2016-07-13 09:53:39 +02:00
Arjen Poutsma d2fce24eb4 Introduced ResponseBodyWriteResultPublisher
Refactored Publisher<Void> in AbstractResponseBodyProcessor into
separate ResponseBodyWriteResultPublisher.
2016-07-13 09:53:39 +02:00
Brian Clozel e906a78e0f Move server testing infrastructure to test sources 2016-07-12 17:36:30 +02:00
Arjen Poutsma d736245f28 Changed from interval() to intervalMillis() 2016-07-12 13:25:18 +02:00
Stephane Maldini c2c7e3b596 Polish timed operators and remove useTimer() 2016-07-12 12:13:50 +01:00
Rossen Stoyanchev aa47616be2 Split TestRestController into use-case sub-classes 2016-07-11 18:08:11 -04:00
Rossen Stoyanchev 7e07fb16d8 Split RequestMappingIntegrationTests into sub-classes 2016-07-11 18:08:11 -04:00
Rossen Stoyanchev 35f791acf8 Extract base class for RequestMappingIntegrationTests 2016-07-11 18:08:11 -04:00
Rossen Stoyanchev 6fde86903d Declare HTTP method mappings TestRestController 2016-07-11 18:07:55 -04:00
Rossen Stoyanchev aa1397b8ba Polish method order in RequestMappingIntegrationTests 2016-07-11 18:07:46 -04:00
Rossen Stoyanchev 407715b89e Helpers for get/post in RequestMappingIntegrationTests
This commit replaces the current helper methods in
RequestMappingIntegrationTests with generic helper methods to perform
HTTP GET and POST requests.

This results in more transparent code that shows the exact HTTP
inputs and outputs and is also more flexible to change for
variations in testing.
2016-07-08 12:17:36 -04:00
Brian Clozel 99697118d8 Add RxJava1 support for request building/extracting
This commit adds the required infrastructure to build HTTP requests as
well as extracting relevant information from HTTP responses using the
RxJava 1.x API, where Observable and Single don't extend Publisher.
2016-07-08 14:22:48 +02:00
Brian Clozel 4892436efe Refactor HTTP client contracts
This commit refactors the `ClientHttpRequestFactory` into an
`ClientHttpConnector` abstraction, in order to reflect that
`ClientHttpRequest`s only "exist" once the client is connected
to the origin server.

This is why the HTTP client is now callback-based, containing all
interactions with the request within a
`Function<ClientHttpRequest,Mono<Void>>` that signals when it's done
writing to the request.

The `ClientHttpRequest` contract also adopts `setComplete()`
and promotes that method to the `ReactiveHttpOutputMessage` contract.

This commit also adapts all other APIs to that change and fixes a few
issues, including:

* use `HttpMessageConverter`s instead of `Encoders`/`Decoders`
* better handle type information about request content publishers
* support client cookies in HTTP requests
* temporarily remove the RxNetty client support
2016-07-08 14:20:07 +02:00
Brian Clozel b5bce1f017 Update after `reactor.core.converter.Converters` changes
Reactor's `DependencyUtils` has been renamed to `Converters` and
all the `from` converter methods have been disambiguated to
`fromPublisher`, `toPublisher`.
2016-07-08 12:00:06 +02:00
Violeta Georgieva d68232c880 Refactor AbstractRequestBodyPublisher states
The state machine is refactored in order to solve various concurrency
issues.
2016-07-08 09:31:51 +03:00
Rossen Stoyanchev d7a43d2003 Polish tests 2016-07-07 23:04:27 -04:00
Rossen Stoyanchev 7534092ef3 Comprensive support for empty request body
This commit adds support for handling an empty request body with both
HttpEntity where the body is not required and with @RequestBody where
the body is required depending on the annotation's required flag.

If the body is an explicit type (e.g. String, HttpEntity<String>) and
the body is required an exception is raised before the method is even
invoked or otherwise the body is passed in as null.

If the body is declared as an async type (e.g. Mono<String>,
HttpEntity<Mono<String>>) and is required, the error will flow through
the async type. If not required, the async type will be passed with no
values (i.e. empty).

A notable exception is rx.Single which can only have one value or one
error and cannot be empty. As a result currently the use of rx.Single
to represent the request body in any form effectively implies the body
is required.
2016-07-07 15:58:06 -04:00
Rossen Stoyanchev a584311178 Fix StringDecoder#decodeToMono issue with empty input
Before this change decodeToMono always created a StringBuilder to
aggregate resulting in an "" (empty string) rather than an empty
Mono for an empty input stream.

Now we aggregate in the DataBuffer instead and then decode to String.
2016-07-07 15:58:06 -04:00
Rossen Stoyanchev 1e1e2f8b1b Support HttpEntity method arguments
The RequestBodyArgumentResolver has been refactored to have a shared
base class and tests with the new HttpEntityMethodArgumentResolver.

An HttpEntity argument is not expected to have an async wrapper because
the request headers are available immediately. The body however can be
asynchronous, e.g. HttpEntity<Flux<String>>.
2016-07-07 15:58:06 -04:00
Brian Clozel 4c3c54463c Upgrade build to Spring 5.0.0-BUILD-SNAPSHOT
* update bean validation API version
* MethodParameter now validates indices, see 39e3f2ebf6
* `getCharSet()` is now `getCharset()`
2016-07-07 18:11:04 +02:00
Rossen Stoyanchev 9cc01fc185 Add @RequestBody tests 2016-07-06 14:10:51 -04:00
Rossen Stoyanchev 54bfbbc607 Rename decodeOne->decodeToMono and readOne->readMono 2016-07-06 12:38:05 -04:00
Rossen Stoyanchev 6525504e17 Restore local vars in JacksonJsonEncoder 2016-07-06 09:35:25 -04:00
Rossen Stoyanchev 9ee4f6ee30 Polish tests 2016-07-06 08:59:46 -04:00
Arjen Poutsma b0de99bc8c Refactor ResponseBodySubscriber to Processor
This commit changes the AbstractResponseBodySubscriber into a
AbstractResponseBodyProcessor<DataBuffer, Void>, so that the processor
can be used as a return value for writeWith.

Additional, this commit no longer closes the response after an eror
occurred.

This fixes #59.
2016-07-06 13:18:42 +02:00
Violeta Georgieva 7763391e84 AbstractResponseBodySubscriber improvements
When the thread is writing to the response in
RECEIVED.onWritePossible(), the execution may stop because isReady()
returned false. In this case the buffer is partially written.
When there is partially written case:
1. The state will be changed from WRITING to RECEIVED
2. A check for "write possible" will be performed:
  - If onWritePossible event has been already called by the web
  container while in WRITING state then this check will trigger
  RECEIVED.onWritePossible() because isReady() will be true and the
  writing will continue.
  - Otherwise the writing will be resumed when the web container sends
  onWritePossible event.
2016-07-06 10:14:05 +03:00
Rossen Stoyanchev 55193194c2 Polish tests 2016-07-05 20:39:56 -04:00
Rossen Stoyanchev 9c438a8f78 Fix failing test 2016-07-05 18:20:31 -04:00
Rossen Stoyanchev 33b6dca2a6 Polish tests 2016-07-05 18:14:47 -04:00
Rossen Stoyanchev 7af7a55ede Polish and simplify JacksonJsonEncoder 2016-07-05 12:02:47 -04:00
Rossen Stoyanchev 2068f667f3 Expose getStatusCode from ServerHttpResponse 2016-07-05 11:10:36 -04:00
Rossen Stoyanchev 7401d10f91 Polish AbstractServerHttpResponse 2016-07-05 11:06:02 -04:00
Sebastien Deleuze 8690464a9b Remove @Ignore on streamResult() test
This test was fixed by previous commit that allows to
JSON encode correctly streams with more than 2 elements.
2016-07-04 15:51:44 +02:00
Sebastien Deleuze 7ed03d01c6 Fix JacksonJsonEncoder for streams with more than 2 elements 2016-07-04 15:45:32 +02:00
Sebastien Deleuze c1518c3fde Avoid exception while setting the status code of a committed response
Before this commit, it was not possible to set the status code of an
HTTP response without throwing an exception if it was already
committed. The consequence was a lot of errors in the logs for long
lived HTTP exchanges like Server-Sent Events for example.

After this commit, ServerHttpResponse#setStatusCode() returns
true if the operation succeeded and false if the status code has not
been set because the response has already been committed.

In term of implementation, that makes status code managed
consistently with headers and cookies:
AbstractServerHttpResponse#setStatusCode() stores the status
code that will be effectively set later in the response lifecycle by
the HTTP server via AbstractServerHttpResponse#writeStatusCode()
when the response will be committed.
2016-07-04 13:16:19 +02:00
Sebastien Deleuze b7b6704c7e Support rx.Completable 2016-07-04 11:05:49 +02:00
Sebastien Deleuze a1d4fe6938 Upgrade dependencies 2016-07-04 10:17:54 +02:00
Sebastien Deleuze f254680f29 Remove unused imports 2016-07-04 10:06:02 +02:00
Sebastien Deleuze 0f01729b27 Allow to configure Tomcat baseDir
This commit also set Tomcat baseDir to java.io.tmpdir for
integration tests in order to avoid creation of temporary directories
in the project root.
2016-07-04 09:52:39 +02:00
Sebastien Deleuze b7b0313c21 Speed up RequestMappingIntegrationTests
Reactor Core + Spring Reactive now handle correctly
shorter interval for the stream result test.
2016-07-04 08:45:47 +02:00
Rossen Stoyanchev 8c76581442 Provide rich type information to ConversionService
When using the ConversionService to check and bridge to and from
reactive types we now generallly provide the full type information
available from method signatures. However that full type information
is not always necessary such as when we perform additional checks on
the generics of the reactive type (e.g. Mono<ResponseEntity>).

This allows us to switch to use DefaultFormattingConversionService
instead of GenericConversionService while also ensuring that the
CollectionToObjectConverter doesn't think it can convert List<?> to
any reactive type.

The ObjectToObjectConverter can also interfere because it is smart
enough to find the "from(Publisher<?>)" method on Flux and Mono.
To make up for that on the response side we now check if a type
is assignable to Publisher first in which case it is a simple cast.

In turn that means we don't need a PublisherToFluxConverter which can
be problematic in its own right because it can convert from Mono to
Flux which technically doesn't lose data but switches stream semantics.

Issue: #124, #128
2016-07-03 21:55:32 -04:00