Commit Graph

502 Commits

Author SHA1 Message Date
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
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
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
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
Arjen Poutsma 11ed847aca AbstractRequestBodyPublisher improvements
Reactored Servlet 3.1 and Undertow request support
(AbstractResponseBodySubscriber) to use an internal state machine,
making thread-safity a lot easier.
2016-06-28 16:29:02 +02:00
Arjen Poutsma 3a681fba89 AbstractResponseBodySubscriber improvements
- AbstractResponseBodySubscriber now checks if the current state is
   expected before changing to a new state.
 - Included comments by @violetagg
2016-06-28 11:33:58 +02:00
Sebastien Deleuze 13b6f4fee4 Add SseEventEncoder to WebReactiveConfiguration 2016-06-28 11:11:45 +02:00
Rossen Stoyanchev cbe2cbcc88 CodecHttpMessageConverter supports a default charset 2016-06-27 09:34:19 -04:00
Rossen Stoyanchev 67175005e3 Add failing Jackson-related response body tests 2016-06-27 09:01:22 -04:00
Rossen Stoyanchev 699b057126 ResponseBodyResultHandler ignores ResponseEntity
Currently ResponseEntityResultHandler is ordered lower than
ResponseBodyResultHandler by default whch means a ResponseEntity
should not be picked by the ResponseBodyResultHandler.

However as it is easy to have both ResponseEntity and @ResponseBody
e.g. in @RestControler (or even by mistake) and in general it makes
sense for ResponseBodyResultHandler to explicitly recognize and
ignore the ResponseEntity return type.
2016-06-27 09:00:46 -04:00
Sebastien Deleuze c24b504a07 Speedup flushing tests 2016-06-27 08:59:24 +02:00
Rossen Stoyanchev 0ff7df8b5c Improve default content type handling
We now also check the default content type if the content type is
application/octet-stream as we do today.

Uncommented failing test that now passes.
2016-06-24 18:14:11 -04:00
Rossen Stoyanchev 351e834716 Polish 2016-06-24 18:03:56 -04:00
Rossen Stoyanchev 95751acb33 Support async wrappers for ResponseEntity
Before this commit only ResponseEntity with async body was supported,
e.g. ResponseEntity<Mono<String>>

This commit also adds suppport for an asyn wrapper around,
e.g. Mono<ResponseEntity<String>.
2016-06-24 17:17:17 -04:00
Rossen Stoyanchev 49bb83c0ec Refactor view resolution tests 2016-06-24 15:39:45 -04:00
Rossen Stoyanchev cae8800183 Refactor @ResponseBody and ResponseEntity tests
Introduce separate test classes for each base class in the hierarchy
above @ResponseBody and ResponseEntity result handlers.

Also start porting existing unit test cases for @ResponseBody and
ResponseEntity return value handlers.
2016-06-24 13:25:41 -04:00
Sebastien Deleuze 3fe87ee225 Change SseEvent#mimeType to SseEvent#mediaType 2016-06-24 17:21:01 +02:00
Sebastien Deleuze e6a0b39df5 Remove SseHttpMessageConverter
CodecHttpMessageConverter is now suitable for SSE since it now
handles default content type.
2016-06-24 17:11:29 +02:00
Sebastien Deleuze 59d3721a40 Support default content type in CodecHttpMessageConverter 2016-06-24 17:09:33 +02:00
Arjen Poutsma 52325a21ff Fixed Undertow flush support
Reactored Servlet 3.1 and Undertow response support into an
AbstractResponseBodySubscriber that uses an internal state machine,
making thread-safity a lot easier.
2016-06-24 15:28:12 +02:00
Sebastien Deleuze 6b3d5f1bc5 Turn FlushingDataBuffer to an empty DataBuffer 2016-06-24 15:28:12 +02:00
Sebastien Deleuze 3c80c19c19 Take in account Rossen and Arjen feedbacks 2016-06-24 15:28:12 +02:00
Arjen Poutsma 81496624a9 Fixed Servlet flush
Servlet flush will now occur on the next possible write if it cannot be
done immediately.
2016-06-24 15:28:12 +02:00
Sebastien Deleuze 9004812231 Add Server-Sent Events support
Flux<SseEvent> is Spring Web Reactive equivalent to Spring MVC
SseEmitter type. It allows to send Server-Sent Events in a reactive way.
Sending Flux<String> or Flux<Pojo> is equivalent to sending
Flux<SseEvent> with the data property set to the String or
Pojo value. For example:

@RestController
public class SseController {

	@RequestMapping("/sse/string")
	Flux<String> string() {
		return Flux.interval(Duration.ofSeconds(1)).map(l -> "foo " + l);
	}

	@RequestMapping("/sse/person")
	Flux<Person> person() {
		return Flux.interval(Duration.ofSeconds(1)).map(l -> new Person(Long.toString(l), "foo", "bar"));
	}

	@RequestMapping("/sse-raw")
	Flux<SseEvent> sse() {
		return Flux.interval(Duration.ofSeconds(1)).map(l -> {
			SseEvent event = new SseEvent();
			event.setId(Long.toString(l));
			event.setData("foo\nbar");
			event.setComment("bar\nbaz");
			return event;
		});
	}
}
2016-06-24 15:27:26 +02:00
Sebastien Deleuze aeb35787d7 Add flushing support
This commit add flushing support thanks to the FlushingDataBuffer
wrapper that allows to identify the elements that should trigger a
flush.
2016-06-24 15:23:26 +02:00
Rossen Stoyanchev 9aa6f5caac Add support for ResponseEntity result handling 2016-06-21 17:27:52 -04:00
Sebastien Deleuze 59b7c25003 Use ResolvableType instead of raw Class in JacksonJsonDecoder 2016-06-21 16:48:18 +02:00
Sebastien Deleuze b5ec47d360 Polishing 2016-06-20 17:10:31 +02:00
Sebastien Deleuze a0e2231779 Use specified ResolvableType in JacksonJsonEncoder
This commit also fixes an issue in the HTTP client that used the
wrapper type instead of the element type. As a consequence, due
to type erasure, we now have to specify the type of the content
in DefaultHttpRequestBuilder#contentStream().
2016-06-20 16:23:02 +02:00
Sebastien Deleuze 5141a198d9 Avoid using deprecated methods in StringEncoder 2016-06-20 13:28:59 +02:00
Rossen Stoyanchev 551b7cd60e Add global Validator bean to WebReactiveConfiguration 2016-06-10 16:06:12 -04:00
Rossen Stoyanchev 2f8baac4e0 Validation support for @RequestBody with @Validated 2016-06-10 15:52:29 -04:00
Rossen Stoyanchev 0a2c3c3744 Polish RequestBodyArgumentResolver 2016-06-10 14:53:19 -04:00
Arjen Poutsma ea21643a29 Various DataBuffer improvements
- Added fromIndex parameter to indexOf and lastIndexOf
- Moved DataBuffer.tokenize to StringEncoder, as that's the only place
  it's used.
2016-06-10 15:27:56 +02:00
Arjen Poutsma 622d11dbce Upgraded Netty to 4.1.0.Final 2016-06-10 15:21:36 +02:00
Arjen Poutsma 54c2e866c3 Renamed getSupportedMimeTypes() in [En|De]coder
Renamed getSupportedMimeTypes() to getEncodableMimeTypes and
getDecodableMimeTypes. This will allow for both Encoder and Decoder to
be implemented in the same class.

This issue fixes #113.
2016-06-10 11:00:28 +02:00
Arjen Poutsma b5394a1f50 Polishing 2016-06-10 10:39:26 +02:00
Arjen Poutsma 61240ee517 Fixed javadoc typo 2016-06-09 13:34:51 +02:00
Rossen Stoyanchev 4fd80bbb67 Add Jackons decoder tests related List vs Flux 2016-06-08 18:10:27 -04:00
Rossen Stoyanchev 22a6ca1f41 Remove Pojo from tests that shouldn't depend on it
The Pojo test class from the codec package will end up in spring-core.
This commit ensures it is used only from classes that also belong to
spring-core.
2016-06-08 16:09:54 -04:00
Rossen Stoyanchev 4e3c439593 Polish Encoder and Decoder 2016-06-08 16:04:52 -04:00
Rossen Stoyanchev a8e5e40d97 @RequestBody raises 415 if no matching converter 2016-06-07 22:14:59 -04:00
Rossen Stoyanchev 36765f0f52 Add protected method to reactive config 2016-06-06 22:24:46 -04:00
Rossen Stoyanchev 7ec85b21bb Remove unused test class 2016-06-06 17:44:08 -04:00
Rossen Stoyanchev 0a88d5983a Polish ResponseBodyArgumentResolver 2016-06-06 17:43:47 -04:00
Rossen Stoyanchev 5c236e1edf Update to latest Reactor snapshot 2016-06-06 10:12:11 -04:00
Rossen Stoyanchev 03b474edfe Add Web Reactive Java config 2016-06-06 09:50:46 -04:00
Rossen Stoyanchev 505569c992 Add Encoder constructor to HttpMessageConverterView 2016-06-06 09:50:16 -04:00
Rossen Stoyanchev b45a48d0fc Support for custom argument resolvers 2016-06-06 09:49:59 -04:00
Rossen Stoyanchev a163938758 Message converters are configurable 2016-06-03 17:56:08 -04:00
Rossen Stoyanchev b20ea75766 Update to latest Reactor snapshot 2016-06-03 17:56:08 -04:00
Rossen Stoyanchev 03a997c9d4 Remove outdated DataBufferFactory properties
Removed in favor of accessing the factory from the response.
2016-06-01 18:07:54 -04:00
Rossen Stoyanchev 431fedccc7 Upgrade to RxJava 1.1.5
After the fix for ReactiveX/RxNetty#509 we can remove the workaround
to concatenate with an empty Observable for the request body and
upgrade to the latest RxJava 1.1.5.

Issues: #103
2016-06-01 17:32:05 -04:00
Sebastien Deleuze 8cf5ea91f8 Sync with TestSubscriber changes in reactor-core 2016-06-01 17:55:53 +02:00
Rossen Stoyanchev 65246f8cfd Remove FIXME on retain in ReactorServerHttpRequest
The converters release so this is the right thing to do, not a
temporary fix.
2016-06-01 10:17:12 -04:00
Rossen Stoyanchev a40a8b06bf Polish view resolution 2016-05-31 22:14:17 -04:00
Rossen Stoyanchev 8cc72b320b View resolution with content negotiation
ViewResolutionResultHandler and ResponseBodyResultHandler now share
a common base class ContentNegotiatingResultHandlerSupport that
supports content negotiation.

For view resolution we compare against the supported media types of
resolved View instances, which may include default View's delegating
to an HttpMessageConverter (e.g. JSON, XML, rendering).
2016-05-31 21:51:24 -04:00
Rossen Stoyanchev 5db1a54ff0 Add HttpMessageConverterView 2016-05-31 17:49:21 -04:00
Rossen Stoyanchev a37b2e3a84 Refactor View contract
View now returns Mono<Void> rather than Flux<DataBuffer> which aligns
more closely with the reactive HttpMessageConverter vs the Encoder.

The change was prompted by the upcoming implementation of a View that
delegates to an existing HttpMessageConverter e.g. for JSON, XML.

The resulting change also brings the reactive View closer in spirit to
the View from spring-webmvc which returns void.
2016-05-31 16:50:38 -04:00
Rossen Stoyanchev f8a7024b73 Polish SimpleResultHandler 2016-05-31 16:50:32 -04:00
Rossen Stoyanchev 1b308cffbf Introduce base class for ResponseBodyResultHandler
The ContentNegotiatingResultHandlerSupport base class encapsulates the
logic for content negotiation needed for both @ResponseBody and view
resolution result handling.
2016-05-31 16:33:01 -04:00
Stephane Maldini 3f7178ba9f Sync Reactor 2016-05-31 13:00:51 +01:00
Stephane Maldini 7fc3031c7a update after Schedulers change 2016-05-31 11:11:38 +01:00
Sebastien Deleuze 3f80b4ab2e Polish 2016-05-30 15:26:55 +02:00
Sebastien Deleuze 97155f1a30 Rename ReactiveHttpOutputMessage.setBody() to writeWith() 2016-05-30 15:09:37 +02:00
Rossen Stoyanchev 58307ebac4 Support Model-related return values
This commit adds support for Model-related return values types such as
Map, Model, @ModelAttribute annotated, and non-simple types, which
helps to clarify the logic in ViewResolutionResultHandler.
2016-05-27 20:22:58 -04:00
Rossen Stoyanchev 33c5a19769 Handle unresolved view name 2016-05-27 15:22:22 -04:00
Rossen Stoyanchev a72462cd8c Polish view resolution tests 2016-05-27 15:22:22 -04:00
Rossen Stoyanchev f7d4688b84 Improve 404 "handler not found" handling
Remove handler inserted at the end to generate error in favor of doing
the same using the otherwiseIfEmpty operator.
2016-05-27 15:21:28 -04:00
Brian Clozel c6ed12297f Add Host property in HttpServerSupport
And change the defaults to:

* "0.0.0.0" for the host
* any available port, starting at 8080
2016-05-27 15:50:41 +02:00
Arjen Poutsma 03fe209862 Renamed ReactiveHttpOutputMessage dataBufferFactory() method to bufferFactory() 2016-05-27 10:37:04 +02:00
Arjen Poutsma d36286c7d1 Renamed DataBufferAllocator to DataBufferFactory 2016-05-27 09:51:42 +02:00
Arjen Poutsma 6f46164727 Changed reduceToSingleBuffer to splitOnNewline
In order to be more "reactive", changed StringDecoder's default from
merging all buffers in the stream to a single buffer into splitting the
buffers along newline (\r, \n) characters.
2016-05-27 09:22:57 +02:00
Arjen Poutsma 74abe92804 Added DataBuffer indexOf and lastIndexOf
This commit introduces DataBuffer.indexOf(IntPredicate) and
lastIndexOf(IntPredicate), for finding the index of a byte in a
DataBuffer.
It also introduces DataBufferUtils.tokenize, which tokenizes a
DataBuffer into separate tokens, given a delimiter function.
2016-05-27 09:22:57 +02:00
Rossen Stoyanchev f0c8c4e7a4 Add request path based default view name support 2016-05-26 18:08:18 -04:00
Rossen Stoyanchev 793638e610 Rename ViewResolverResultHandler to ViewResolution~ 2016-05-26 17:48:35 -04:00
Rossen Stoyanchev 8b99c51969 Fix compiler warnings 2016-05-26 17:37:39 -04:00
Rossen Stoyanchev eb9fe235fe Properly handle Mono.empty() for view resolution
This commit ensures correct handling for Mono.empty() return value
where the declared return type is Mono<String> or Mono<View>.
2016-05-26 17:34:52 -04:00
Rossen Stoyanchev 91a5759cf5 Polish result handlers default order 2016-05-26 16:17:56 -04:00
Rossen Stoyanchev bc782902d7 Remove java.util.Optional from View contract 2016-05-26 16:00:08 -04:00
Rossen Stoyanchev 4d04bd5690 Consolidate view resolution under result.view
While View and ViewResolver play the same role as in spring-webmvc they
are now abstracted behind the HandlerResultHandler abstraction so that
top-level contracts don't reference them and the DispatcherHandler is
also unaware of their existence.

Furthermore view resolution and response body handling which are now at
the same level of abstraction (each is a HandlerResultHandler) will
also share code for content negotiation, so it makes sense for them to
be side by side.

This commit moves the reactive.view package to reactive.result.view
with the View and ViewResolver contracts (previously in the top-level
reactive package) also moving there.
2016-05-26 15:55:22 -04:00