Commit Graph

494 Commits

Author SHA1 Message Date
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
Arjen Poutsma c85d1dc126 Merge pull request #133 from violetagg/onwritepossible-concurrency
AbstractResponseBodySubscriber improvements
2016-07-06 10:37:49 +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
Rossen Stoyanchev fb2e796048 HandlerResult now requires MethodParameter as input
HandlerAdapter's should always be able to provide a MethodParameter
which in turn ensures that HandlerResultHandler's have full type
information from method declarations.

This commit also introduces ResolvableMethod for use in tests to make
it easy to obtain MethodParameter return types.

Issue: #128
2016-07-03 21:54:20 -04:00
Rossen Stoyanchev dffd6d674a Shorten returnValueType name in HandlerResult 2016-07-01 18:00:31 -04:00
Rossen Stoyanchev df64262db6 Complete reactive conversion support refactoring
This commit ensures stream semantics (Flux vs Mono) are adhered to also
on the target side.
2016-07-01 17:42:36 -04:00
Rossen Stoyanchev 71f4dff011 Polish validation in RequestBodyArgumentResolver 2016-07-01 17:42:36 -04:00
Rossen Stoyanchev a68ff94fbc Polish "decodeOne" related changes 2016-07-01 17:42:36 -04:00
Sebastien Deleuze 917a2fb9d0 Add Decoder#decodeOne()
This commit adds a Decoder#decodeOne() method in order
to handle correctly the streaming versus one value
deserialization based on the type provided by the user.

For example, if a List parameter is provided in a controller
method, Jackson will be called once, while if the user provides
a Flux or an Observable parameter, Jackson will be called for
each element.
2016-07-01 17:42:36 -04:00
Sebastien Deleuze 12d7b78169 Refactor reactive type conversion support
This commit replaces Reactive Streams converters for RxJava1 and
CompletableFuture with Reactor specific ones. The results in conversion
that preserves stream semantics, i.e. Mono vs Flux.

For example this is allowed:
Flux -> Observable
Mono -> Single
Mono -> CompletableFuture

This is not allowed:
Flux -> Single
Mono -> Observable
Flux -> CompletableFuture

As a result it is now possible to check through the ConversionService
if a target type to convert to is a stream of many or of one which is
useful for decoding purposes.

The commit also adds PublisherToFluxConverter to allow conversion from
raw Publisher to Flux. The reverse is not necessary since Flux is a
Publisher and it's a no-op conversion.
2016-07-01 17:41:37 -04:00
Rossen Stoyanchev 952395192f Collapse core.codec and core.codec.support into one 2016-06-30 16:12:36 -04:00
Rossen Stoyanchev 2f2546c8a4 Simplify initialization of WebSession Mono
The DefaultWebSessionManager now uses Mono.defer to protect the call
to getSession from parsing session cookies immediately. This allows
pre-initializing the Mono<WebSession> upfront vs using a lock.
2016-06-30 16:00:49 -04:00
Rossen Stoyanchev 4e2802338a Add MockWebSessionManager 2016-06-30 15:53:58 -04:00
Rossen Stoyanchev 43a1ea6bac Remove class checked in by mistake 2016-06-30 14:10:15 -04:00
Rossen Stoyanchev 39253b314a Fix tests by moving JAXB2 types back into sub-package 2016-06-30 14:09:09 -04:00
Rossen Stoyanchev 6d089cdc08 Move remaining JAXB2 test files from core to http 2016-06-30 13:48:41 -04:00
Sebastien Deleuze b115f1885d Move JSON and XML codecs to org.springframework.http.codec 2016-06-30 17:01:50 +02:00
Sebastien Deleuze 8d654584a8 Make JsonObjectDecoder package private 2016-06-30 16:30:16 +02:00
Arjen Poutsma 3403a6ca38 Merge pull request #127 from violetagg/ondataavailable-state
AbstractRequestBodyPublisher.onDataAvailable improvement
2016-06-30 16:07:01 +02:00
Violeta Georgieva ea18e73803 AbstractRequestBodyPublisher.onDataAvailable improvement
When in state DATA_AVAILABLE if there are simultaneous invocations of
AbstractRequestBodyPublisher.RequestBodySubscription.request and
ReadListener.onDataAvailable, the first one will process the available
data, the second one should not throw an exception because thus it will
signal to web container that there are problems while there are not.
2016-06-30 16:56:15 +03:00
Arjen Poutsma 1d48e7c5b9 Allow to set response status on Undertow
Refactored Undertow support to register a response listener only when
the body is written to, as opposed to registering it at startup. The
reason for this is that getting the response channel from the
HttpServerExchange commits the status and response, making it impossible
to change them after the fact.

Fixed issue #119.
2016-06-30 15:27:08 +02:00
Arjen Poutsma 2418ff0ad4 Merge pull request #126 from violetagg/onwritepossible-state
Make AbstractResponseBodySubscriber.onWritePossible thread-safe
2016-06-30 11:07:50 +02:00
Violeta Georgieva e545b20289 Make AbstractResponseBodySubscriber.onWritePossible thread-safe
When there are simultaneous invocations of onWritePossible, only the
first one should succeed. This can happens when
AbstractResponseBodySubscriber.onNext and
WriteListener.onWritePossible() are called respectively by the
application and the web container.
2016-06-30 11:59:38 +03:00
Rossen Stoyanchev e9d8152ab2 Port fix for SPR-14397
This is a port of the following commit, adapted for Java 8+:
89396ff01f
2016-06-29 17:34:45 -04:00
Rossen Stoyanchev 478b4149f7 Add netty-buffer as a compile dependency
This is a temporary measure for M1 as the dependency will go away once
issue #116 is addressed.
2016-06-29 12:04:51 -04:00
Sebastien Deleuze 76baf85cfb Polish JacksonJsonDecoder 2016-06-29 14:22:21 +02:00
Sebastien Deleuze 1f2fbba89b Make JsonObjectDecoder mandatory in JacksonJsonDecoder 2016-06-29 10:34:46 +02:00
Arjen Poutsma 92821d9300 Merge pull request #123 from violetagg/onsubscribe-state
Make AbstractResponseBodySubscriber.onSubscribe thread-safe
2016-06-29 09:51:30 +02:00
Violeta Georgieva 0605c0f3be Make AbstractResponseBodySubscriber.onSubscribe thread-safe
When there are simultaneous invocations of onSubscribe, only the first one should succeed, the rest should cancel the provided subscriptions
2016-06-29 10:47:23 +03:00