Commit Graph

1461 Commits

Author SHA1 Message Date
Juergen Hoeller b54aee27be Polishing 2016-12-21 14:42:43 +01:00
Juergen Hoeller 598122fe8a Avoid package cycle between http.server and web.util 2016-12-21 14:42:32 +01:00
Sebastien Deleuze a1ae9ac1bd Add ServerHttpRequest.Builder#header(String, String)
This method allows to set or override easily a specific header value.
2016-12-20 23:54:22 +01:00
Sebastien Deleuze 712a63205c Add HttpHeaders#setAcceptLanguageAsLocale(Locale)
Issue: SPR-15024
2016-12-20 22:33:09 +01:00
Juergen Hoeller 82c1c859d9 Polishing
(cherry picked from commit 9cb4de8)
2016-12-20 21:17:48 +01:00
Stephane Maldini 241d5f7a3b Sync reactor-netty client response update and uncomment in tests 2016-12-20 14:37:32 +00:00
Sebastien Deleuze 7bde85ae55 Fix previous commit 2016-12-19 10:21:36 +01:00
Sebastien Deleuze 879b387954 Disable temporarily reactor-netty integration tests 2016-12-19 09:55:58 +01:00
Juergen Hoeller 9ba4b47bee Defensive processing of timeout callback and timeout result
Issue: SPR-14978
2016-12-17 12:57:18 +01:00
Rossen Stoyanchev bd8af55bc7 getAcceptLanguageAsLocale(s) returns most preferred Locale
An update on the last commit switching from:
List<Locale> getAcceptLanguageAsLocales() to
Locale getAcceptLanguageAsLocale()

This best supports the scenario for the most preferred Locale.
If there is a need to look at the prioritized list of languages it's
best to use Locale.filter with the LocaleRange's.

This is explained in the Javadoc for getAcceptLanguage().

Issue: SPR-15024
2016-12-16 17:15:43 -05:00
Rossen Stoyanchev fa56361ad2 Add getAcceptLanguageAsLocales
The use of Locale.LanguageRange for the Accept-Language header makes
sense as it gives the most flexibility for a client to set a weighted
list and for a server to do filtering via Locale#filter.

This commit adds an additional convenience method that turns
the LangugeRange list to a list of Locale's also filtering out a
wildcard (i.e. "*"). A List<Locale> is the most basic way to access
prefered languages and needed when filtering is not required.

Issue: SPR-15024
2016-12-16 16:20:06 -05:00
Rossen Stoyanchev c85d768b3c WebExchangeDataBinder uses the new "requestParams" 2016-12-16 16:20:06 -05:00
Stephane Maldini 7d9e8def44 uncomment reactor-netty in tests 2016-12-16 20:09:32 +00:00
Rossen Stoyanchev 95818609fc Minor refactoring
Consolidate into one method potentially re-using UriComponentsBuilder
for the location. Also use StringUtils#applyRelativePath.

Issue: SPR-15020
2016-12-15 19:34:33 -05:00
Rob Winch db2ebd30da Add Support for ForwardedHeaderFilter sendRedirect
Previously ForwrdedHeaderFilter did not ensure that
HttpServletResponse.sendRedirect worked properly based on
X-Forwarded-* headers.

This commit updates ForwardedHeaderFilter to overrided the
HttpServletResponse.sendRedirect method to ensure
X-Forwarded-* headers are honored.

Issue SPR-15020
2016-12-15 17:04:57 -05:00
Rossen Stoyanchev 96474405dc Refactor ServerWebExchange/ServerHttpRequest builders
ServerWebExchange.Builder has an additional Consumer-style shortcut
method that accepts a builder for modifying the request.

ServerWebExchange and ServerHttpRequest builders have fewer methods,
more use-case focused vs matching directly to properties.
2016-12-15 17:02:05 -05:00
Rossen Stoyanchev 6119415427 Support for "request parameters"
ServerWebExchange now provides access to "requestParams" as a
MulitValueMap with query parameters and form data combined.

The combined map is then used for the params condition of
@RequestMapping purposes () and also for @RequestParam arguments.

Issue: SPR-15000
2016-12-15 14:24:39 -05:00
Sebastien Deleuze 36da299f96 Add set/getContentLanguage() to HttpHeaders
Issue: SPR-14536
2016-12-15 17:30:53 +01:00
Sebastien Deleuze 9764d57433 Add set/getAcceptLanguage() to HttpHeaders
Issue: SPR-15024
2016-12-15 17:19:37 +01:00
Juergen Hoeller 37c734ec90 Consistent DeferredResultHandler invocation outside of result lock
Issue: SPR-14978
2016-12-15 15:43:47 +01:00
Arjen Poutsma 97558ab4de Move Body[Inserter|Extractor] to web.reactive.function 2016-12-15 13:22:11 +01:00
Arjen Poutsma aa8f531526 Move WebClient to web.reactive.function.client 2016-12-15 13:22:11 +01:00
Sebastien Deleuze dfcd5b9ed9 Add a test to validate Reactor Netty automatic flushing
Issue: SPR-14992
2016-12-15 13:08:36 +01:00
Stephane Maldini c201a14ea2 Temp disabling reactor-netty to unblock pipeline 2016-12-15 04:11:34 +00:00
Rossen Stoyanchev 257318eb87 Minor refactoring + polish in server reactive package
Renamed:
AbstractListenerFlushProcessor -> AbstractListenerWriteFlushProcessor
2016-12-14 17:43:07 -05:00
Rossen Stoyanchev 4738a61e98 Early registration of ReadListener
This is similar to the WriteListener changes on the ServerHttpResponse
where we are more naturally exposed to a delayed write. Nevertheless
we could also have a delayed read and should be consistent. The early
initialization of the RequestBodyPublisher also simplifies the
internal implementation a bit.
2016-12-14 16:17:46 -05:00
Juergen Hoeller 29543856ec OkHttpClientHttpRequestFactory allows POST request without body
Issue: SPR-15015
2016-12-14 22:05:34 +01:00
Rossen Stoyanchev 5a29069798 Refactor AsyncListener registration + polish
Instead of registering an AsyncListener in ServletHttpHandlerAdapter
we now register an AsyncListener in each of the request and response
where the events need to be handled anyway. This allows removing the
package private delegation methods in the request and response.
2016-12-14 15:34:58 -05:00
Rossen Stoyanchev 70f14c14c8 Polish Undertow reactive server support 2016-12-14 14:51:33 -05:00
Rossen Stoyanchev d3e05296e1 Replace close method with Undertow exchange listener
The Undertow HttpServerExchange has a complete listener which we can
use instead of the close() method UndertowServerHttpRequest.
2016-12-14 13:48:40 -05:00
Violeta Georgieva 8d786e8bba Refactor the usage of Undertow ByteBufferPool
- lazy allocate the PooledByteBuffer, only if there is a request body
  for reading
- close the PooledByteBuffer once the request finishes
2016-12-14 12:49:09 -05:00
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
Sebastien Deleuze 4021d239ab Fix JsonObjectDecoder with '[' starting chunk
Issue: SPR-15013
2016-12-14 14:53:12 +01:00
Rossen Stoyanchev b70071fdda Remove temporary workaround in ReactorServertHttpResponse
We no longer should need the workaround for:
https://github.com/reactor/reactor-netty/issues/2

Issue: SPR-14643
2016-12-14 08:50:37 -05:00
Rossen Stoyanchev c66dd01724 Equal MockServerHttpResponse in spring-test and -web 2016-12-14 05:54:53 -05:00
Sebastien Deleuze 4519c236d6 Restore reactor-netty test in FlushingIntegrationTests 2016-12-14 11:05:18 +01:00
Sebastien Deleuze 1829adecb7 Disable temporarily reactor-netty in FlushingIntegrationTests 2016-12-14 09:34:19 +01:00
Rossen Stoyanchev 3df902c6cc Add ServerHttpRequest builder
Similar pattern as for ServerWebExchange with a default mutate method
on ServerHttpRequest returning a Builder and eventually creating an
immutable wrapper.

HttpHandlerAdapterSupport uses the builder to set the contextPath.
2016-12-13 17:59:51 -05:00
Rossen Stoyanchev f693e32973 Add ServerHttpResponseDecorator
For completeness and consistency with the existing
ServerHttpRequestDecorator and the ServerWebExchangeDecorator.
2016-12-13 17:59:51 -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
Rossen Stoyanchev 7193686bb0 Support encodeUrl mechanism via ServerHttpResponse
Issue: SPR-14529
2016-12-13 17:59:51 -05:00
Brian Clozel d4411f4cc6 Update AbstractClientHttpRequest with server changes
This commit updates `AbstractClientHttpRequest` to make it more similar
to its server counterpart.
2016-12-13 22:58:01 +01: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
Violeta Georgieva 9d03b77cdc Rename "ResponseBody" flush processor + use generics
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 46b39f4372 Initial reactive, WebSocket Tomcat support
Issue: SPR-14527
2016-12-12 17:56:47 -05:00
Violeta Georgieva 41ece612cf Generic AbstractRequest/ResponseBodyProcessor
In preparation for use with WebSockets.

Issue: SPR-14527
2016-12-12 17:56:47 -05:00
Juergen Hoeller e49813f2c4 Polishing 2016-12-12 22:49:40 +01:00
Juergen Hoeller aa29495d1d CommonsMultipartFile.getOriginalFilename() can be configured to preserve header-specified filename as-is
Issue: SPR-14613
2016-12-09 23:05:51 +01:00
Juergen Hoeller cf6a5835cc Polishing 2016-12-08 18:39:30 +01:00
Juergen Hoeller ee30ce95fe HttpInvokerClientInterceptor propagates client-side Error as-is
Issue: SPR-14985
2016-12-08 18:29:41 +01:00
Sebastien Deleuze 2735cba4b3 Append "data:" after line breaks for SSE JSON data fields
Issue: SPR-14899
2016-12-08 11:19:46 +01:00
bedrin 8315a4033f Add consumes attribute to @GetMapping
Issue: SPR-14988
2016-12-07 17:45:43 -05:00
Sebastien Deleuze 24b3614063 Add a 8 Kb flush threshold to RxNettyServerHttpResponse
Issue: SPR-14991
2016-12-07 11:13:45 +01:00
Brian Clozel ec8391a7fb Fix Netty4ClientHttpRequestFactory POST/PUT requests
This commit ensures that POST/PUT requests sent by the Netty client have
a Content-Length header set.

Integration tests have been refactored to use mockwebserver instead of
Jetty and have been parameterized to run on all available supported
clients.

Issue: SPR-14860
2016-12-07 09:23:53 +01:00
Arjen Poutsma 9e72033036 Add WebClient.filter method
This commit introduces a new method on WebClient: filter, which takes an
filter function, and returns a (filtered) WebClient.

Issue: SPR-14961
2016-12-06 13:03:58 +01:00
Arjen Poutsma 079eca9f63 Add status code check to bodyTo[Mono|Flux]
- Add 4xx/5xx status code check to ClientResponse.bodyToMono and bodyToFlux.
- Removed WebClient.retrieveMono and retrieveFlux.

Issue: SPR-14977
2016-12-06 09:29:21 +01:00
Rossen Stoyanchev 953f7d40cf Filter out hanging tests realted to Reactor Netty
Issue: SPR-14975
2016-12-05 16:03:12 -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
Juergen Hoeller 1039fa1d34 Avoid defensive check for Servlet 3.1 Part interface
Issue: SPR-14467
2016-12-01 20:11:54 +01:00
Juergen Hoeller f6fc0a86b3 Polishing
(cherry picked from commit 0028b29)
2016-12-01 20:11:47 +01:00
Juergen Hoeller 7a8ec4f6eb Consistent use of "URI variables" terminology
Issue: SPR-14969
2016-12-01 12:30:10 +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
Brian Clozel 3bd17175ed Update with new HttpServerResponse.sendFile signature
Reactor Netty's `HttpServerResponse` has a new `sendFile` signature that
takes a `Path` instead of a `File`.
2016-11-29 14:29:39 +01:00
Rossen Stoyanchev cb50f6bc8c ResponseEntity headers builder casts body to any type
Issue: SPR-14939
2016-11-28 17:22:24 -05:00
Sebastien Deleuze 0fcae5d2c5 Polishing
Issue: SPR-14952
2016-11-25 12:54:48 +01:00
Sebastien Deleuze 8d26c738a0 Polishing
This commit polishes previous one by also accepting
generic types explicitly declared with a class that
extends DataBuffer allowing to write Flux<DefaultDataBuffer>
for example.

Issue: SPR-14952
2016-11-25 10:33:13 +01:00
Daniel Fernández a98be035a3 Make the signature of RHOM#writeAndFlush() more flexible
This modifies the signature of
ReactiveHttpOutputMessage#writeAndFlush(...) in order to
be able to use Flux<Flux<DataBuffer>> objects as arguments of
this method.

Issue: SPR-14952
2016-11-25 09:59:33 +01: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
Raman Gupta fada91e538 Treat Kotlin nullable as non-required
Where `isOptional` is used, also check for `isNullable` i.e.
values are not considered required if they are Kotlin nullables:
- spring-messaging: named value method arguments
- spring-web: named value method arguments
- spring-webmvc: request parts

This means that Kotlin client code no longer has to explicity specify
"required=false" for Kotlin nullables -- this information is inferred
automatically by the framework.

Issue: SPR-14165
2016-11-24 17:18:55 +01:00
Arjen Poutsma 735e288d46 Add DataBuffer BodyInserter/BodyExtractor
Added a BodyExtractor for Flux<DataBuffer>, and a BodyInserter for
Publisher<DataBuffer>

Issue: SPR-14918
2016-11-24 17:04:50 +01:00
Violeta Georgieva 6f222609c2 Fix NPE in ServletServerHttpResponse.ResponseBodyProcessor.write
Issue: SPR-14941
2016-11-24 11:53:28 +01:00
Rossen Stoyanchev 3eb2432ced Fix TODO in ReactorHttpServer 2016-11-23 15:47:19 -05:00
Juergen Hoeller 1f4c6de287 Polishing 2016-11-23 21:10:01 +01:00
Rossen Stoyanchev 6b9b47ee13 Polish 2016-11-23 13:20:38 -05:00
Stephane Maldini 099f5a254e Upgrade to reactor-netty/-ipc to 0.6 snapshots 2016-11-23 12:50:01 -05:00
Juergen Hoeller 9bf4d7cf4e Polishing 2016-11-22 14:57:00 +01:00
Juergen Hoeller 85b0ce1ef7 Avoid defensive checks against java.time API
Issue: SPR-13188
2016-11-22 14:55:03 +01:00
Juergen Hoeller da63898d5f Polishing 2016-11-21 17:36:04 +01:00
Arjen Poutsma dbe81bef52 Add PATCH method operation to RestTemplate
This commit adds a HTTP PATCH operation to the RestTemplate:
patchForObject. As with most operations, there are three variants:
varargs, Map, and URI based.

Issue: SPR-14857
2016-11-17 10:19:09 +01:00
Mark Paluch 6261106a93 Fix TLS detection in URLs for Netty Client RequestFactory
Do not check on non-specified port when scheme is https.
Enables SSL for https URIs with a specified port.

Issue: SPR-14889
2016-11-11 16:39:18 +01:00
Juergen Hoeller dda9762072 Moved WebExchangeDataBinder to web.bind.support (alongside WebRequestDataBinder)
Issue: SPR-14542
2016-11-08 11:01:58 +01:00
Sebastien Deleuze 99a8510ace Introduce HttpHeaders get/setContentDisposition()
This commit introduces a new ContentDisposition class designed
to parse and generate Content-Disposition header value as defined
in RFC 2183. It supports the disposition type and the name,
filename (or filename* when encoded according to RFC 5987) and
size parameters.

This new class is usually used thanks to
HttpHeaders#getContentDisposition() and
HttpHeaders#setContentDisposition(ContentDisposition).

Issue: SPR-14408
2016-11-08 01:12:23 +01:00
Rossen Stoyanchev 816e32872a Reactive support for @ModelAttribute argument
Issue: SPR-14542
2016-11-07 15:02:13 +02:00
Juergen Hoeller 9b57437b7a Polishing 2016-11-07 12:55:35 +01:00
Juergen Hoeller 365ecd4cca Polishing 2016-11-04 14:14:31 +01:00
Juergen Hoeller 17f5f86a54 Polishing 2016-11-04 12:25:38 +01:00
Juergen Hoeller ac774cdcef Avoid deprecated Mockito methods
Issue: SPR-14880
2016-11-04 12:24:46 +01:00
Juergen Hoeller 84d3808b3b Upgrade to Mockito 2.2
Issue: SPR-14880
2016-11-03 22:53:35 +01:00
Sebastien Deleuze 8705df502d Rename Verifier to StepVerifier
Issue: SPR-14800
2016-11-02 19:01:40 +01:00
Sebastien Deleuze b4b7c278df Update tests according to latest reactor-test changes
- ScriptedSubscriber has been renamed to Verifier
 - The Publisher is passed to create() instead of verify()
 - No more need to specify the generic type explicitly
 - Version is now sync with reactor-core

Issue: SPR-14800
2016-11-01 22:28:50 +01:00
Rossen Stoyanchev 99cacaa72d Improve reactive support for access to Principal
The method to access the Principal from the ServerWebExchange is now
a Mono<Principal> (rather than Optional<Principal>).

There is also support for Principal as a controller method argument.

Issue: SPR-14680, SPR-14865
2016-11-01 18:44:14 +02:00
Rossen Stoyanchev 33dbbce182 ApplicationContext-based HttpHandler setup
This commit adds support for detecting the target WebHandler along with
WebFilters, WebExceptionHandlers, and other spring-web reactive
strategies in an ApplicationContext.

WebReactiveConfigurationSupport has @Bean factory methods for
DispatcherHandler and ResponseStatusExceptionHandler.

WebHttpHandlerBuilder has a static factory method that initializes the
builder from an ApplicationContext. This method is also used in the
DispatcherHandler#toHttpHandler(ApplicationContext) shortcut method.

Issue: SPR-14837
2016-10-31 20:45:26 +02:00
Rossen Stoyanchev 3da0295c12 Support for reactive controller @InitBinder methods
Issue: SPR-14543
2016-10-31 16:11:44 +02:00
Juergen Hoeller c4ee876416 Polishing 2016-10-31 12:45:41 +01:00
Juergen Hoeller 7f280a3b17 Polishing 2016-10-31 12:28:44 +01:00
Rossen Stoyanchev 00a35897fe ServerWebExchange provides access to form data
The ServerWebExchange now has a getFormData() method that delegates to
FormHttpMessageReader for the parsing and then caches the result so
it may be used multiples times during request processing.

Issue: SPR-14541
2016-10-28 22:58:31 +03:00
Rossen Stoyanchev 81b4dedd08 Polish form reader/writer 2016-10-28 21:29:02 +03:00
Sebastien Deleuze 46599e7d03 Add FormHttpMessageReader/Writer
Issue: SPR-14540
2016-10-28 19:08:01 +03:00
Rossen Stoyanchev c3f22b7364 Add "mutate" builder to ServerWebExchange
This commit adds a default mutate method to ServerWebExchange which
prepares an immutable wrapper and returns the provided mutated
properties.
2016-10-28 19:05:05 +03:00
Sebastien Deleuze b1030eba3f Fix JsonObjectDecoder chunks handling
Issue: SPR-14859
2016-10-28 16:44:53 +02:00
Arjen Poutsma 8f844461a0 Make HttpComponentsAsyncClientHttpRequest abortable
This commit aborts the HttpComponentsAsyncClientHttpRequest whenever the
returned Future is canceled.

Issue: SPR-14845
2016-10-28 14:19:15 +02:00
Arjen Poutsma 7b469f9c62 Improve WebClient error handling
This commit introduces two new `WebClient` methods: `retrieveMono` and
`retrieveFlux`, both of which offer direct access to the response body.
More importantly, these methods publish a WebClientException if the
response status code is in the 4xx or 5xx series.

Issue: SPR-14852
2016-10-28 13:15:29 +02:00
Arjen Poutsma c96badc794 Add ExchangeFilterFunction.ofRequestProcessor and ofResponseProcessor 2016-10-28 09:05:07 +02:00
Arjen Poutsma 20dec61d04 Refactored BodyInserters
This commit introduces a couple of changes to BodyInserters:

- Refactored writeWithMessageWriters into BiFunction
- BodyInserters.fromResource now uses ResourceMessagewriter from context
- BodyInserters.fromServerSentEvents now uses SseHttpMessageWriter from context
2016-10-25 11:11:58 +02:00
Arjen Poutsma 94930043fd Added MediaType.TEXT_EVENT_STREAM 2016-10-25 11:11:58 +02:00
Brian Clozel 99a3210859 Refactor tests with ScriptedSubscriber
Reactor recently added the `ScriptedSubscriber` in its new
`reactor-addons` module. This `Subscriber` revissits the previous
`TestSubscriber` with many improvements, including:

* scripting each expectation
* builder API that guides you until the final verification step
* virtual time support

This commit refactor all existing tests to use this new
infrastructure and removed the `TestSubscriber` implementation.

Issue: SPR-14800
2016-10-25 10:44:44 +02:00
Rossen Stoyanchev aea3a75018 Fix failing tests
Issue: SPR-14772, SPR-14803
2016-10-21 16:19:57 -04:00
Rossen Stoyanchev 5c9c5e0b45 Early registration of WriteListener
At present Tomcat expects a WriteListener to be registered immediately
on the initial thread so for the time being this commit ensures the
WriteListener is registered unconditionally for every request.

Issue: SPR-14772, SPR-14803
2016-10-21 15:29:57 -04:00
Rossen Stoyanchev e3673d43b9 Thread-safe reactive ServerHttpRequest
This commit replaces the lazy URI and headers initialization in the
reactive ServerHttpRequest in favor of eager initialization at
construction time. Both the URI and headers are nearly guaranteed to
be accessed for every request (URI for application path, headers for
"Origin" header).

Query params are still lazily parsed but parsing is idemptotent and
in the unlikely case of concurrent access (it's the framework that
typically accesses query params) it maybe parsed twice but should
be side effect free still.

Cookies are also parsed lazily and since we delegate to the "native"
request, it depends on the underlying runtime whether synchronization
is needed. This commit adds synchronization for the HttpServletRequest.
At present RxNetty, Reactor, and Undertow implementations provide
thread-safe access to cookies.
2016-10-21 15:17:28 -04:00
Arjen Poutsma 08931950f4 Add byte[] encoder and decoder
This commit adds a ByteArrayDecoder and ByteArrayEncoder.
2016-10-21 12:34:06 +02:00
Juergen Hoeller 3726c6f18d Polishing 2016-10-21 12:26:27 +02:00
Rossen Stoyanchev b92d541ba0 Add contextPath support for reactive web applications
This commit introduces support for running multiple HttpHandler's under
distinct context paths which effectively allows running multiple
applications on the same server. ContextPathIntegrationTests contains
an example of two applications with different context paths.

In order to support this the HttpHandler adapters for all supported
runtimes now have a common base class HttpHandlerAdapterSupport
which has two constructor choices -- one with a single HttpHandler and
another with a Map<String, HttpHandler>.

Note that in addition to the contextPath under which an HttpHandler is
configured there may also be a "native" contextPath under which the
native runtime adapter is configured (e.g. Servlet containers). In such
cases the contextPath is a combination of the native contextPath and
the contextPath assigned to the HttpHandler. See for example
HttpHandlerAdapterSupportTests.

Issue: SPR-14726
2016-10-20 17:42:38 -04:00
soldierkam 8143e5fe20 HttpClient instance should be shared for each call 2016-10-20 17:06:46 +02:00
Arjen Poutsma fa9cc1eb1a Add bodyToMono/bodyToFlux convenience methods
This commit adds a bodyToMono and bodyToFlux convenience method to
ClientResponse/ServerRequest, similar to the body(Publisher) method that
is on ClientRequest/ServerResponse.
2016-10-20 16:58:30 +02:00
Sebastien Deleuze 921bf5fb70 Use the official RxJava to Reactive Streams adapter
This commit removes the usage of Reactor adapters (about to
be moved from Reactor Core to a new Reactor Adapter module).
Instead, RxReactiveStreams is now used for adapting RxJava
1 and Flowable methods are used for RxJava 2.

Issue: SPR-14824
2016-10-20 15:08:05 +02:00
Arjen Poutsma 0cfb6b37f2 Align Reactive WebClient with web.reactive.function
This commit refactors the web client to be more similar to
web.reactive.function. Changes include:

- Refactor ClientWebRequest to immutable ClientRequest with builder and
   support for BodyInserters.
- Introduce ClientResponse which exposes headers, status, and support
   for reading from the body with BodyExtractors.
- Removed ResponseErrorHandler, in favor of having a ClientResponse
   with "error" status code (i.e. 4xx or 5xx). Also removed
   WebClientException and subclasses.
- Refactored WebClientConfig to WebClientStrategies.
- Refactored ClientHttpRequestInterceptor to ExchangeFilterFunction.
- Removed ClientWebRequestPostProcessor in favor of
   ExchangeFilterFunction, which allows for asynchronous execution.

Issue: SPR-14827
2016-10-20 12:35:23 +02:00
Arjen Poutsma dc1926a861 Moved BodyExtractor and BodyInserter to http.codec
This commit moves the web.reactive.function.[BodyInserter|BodyExtractor]
to http.codec, so that they can be used from the client as well.

Furthermore, it parameterized both inserter and extractor over
ReactiveHttpOutputMessage and ReactiveHttpInputMessage respectively, so
that they can be limited to only be used on the client or server.
2016-10-20 11:44:01 +02:00
Rossen Stoyanchev 72397e3505 Polish
Issue: SPR-14798
2016-10-19 16:30:52 -04:00
Sebastien Deleuze 50f2cda009 Better encapsulation for CORS default permit configuration
This commit also improves CorsRegistration Javadoc.

Issue: SPR-14798
2016-10-19 15:31:22 -04:00
Violeta Georgieva 25e7cd577d Handle AsyncListener.onComplete in Servlet adapter
Typically the Mono<Void> from the HttpHandler also reflects the
completion of the request and response body processors and at that
point invoking AsyncContext#complete() from HandlerResultSubscriber
should be sufficient.

This commit explicitly propagates the AsyncListener.onComplete event
to the request and response body processors for added safety.
Technically as mentioned those processors should have completed but
depending on how the controller is written there is a possibility
the body processors may not have completed.

Issue: SPR-14772
2016-10-19 14:28:24 -04:00
Rossen Stoyanchev ec1eb14280 Add getPrincipal to ServerWebExchange
ServerWebExchange now has a getPrincipal method and along with that a
ServerWebExchangeDecorator that can be used to wrap the exchange in
order to return the authenticated user.

Issue: SPR-14680
2016-10-17 17:48:22 -04:00
Philippe Marschall ae5b0c6fb5 Replace J2EE with Java EE
String with version 5 the name of Java Platform, Enterprise Edition
changed from J2EE to Java EE. However a lot of the documentation still
uses the term J2EE.

This commit includes the following changes:

 * replace J2EE with Java EE where appropriate

This is not a blind search and replace. The following occurrences
remain unchanged:

 * references to old J2EE releases, most notably 1.3 and 1.4.
 * references to "Expert One-On-One J2EE Design and Development"
 * references to "Core J2EE patterns"
 * XML namespaces
 * package names

Issue: SPR-14811
See gh-1206
2016-10-15 11:49:00 +03:00
Rossen Stoyanchev 6cb7d51ee5 Polish 2016-10-14 17:16:23 -04:00
soldierkam e5158d47e0 EncoderHttpMessageWriter tries to send wildcard type in response header 2016-10-14 16:58:31 -04:00
Violeta Georgieva ced6559941 Improve AbstractResponseBodyProcessor.onNext(..)
If the provided DataBuffer is empty then request the next DataBuffer.
2016-10-14 16:41:14 -04:00
Rossen Stoyanchev fada5aed6e Check status in AbstractServerHttpResponse setComplete 2016-10-14 15:32:34 -04:00
Rossen Stoyanchev 960cc42060 Fix test failure in WebSessionIntegrationTests 2016-10-13 18:02:41 -04:00
Rossen Stoyanchev d4446c79b6 Restore state field in AbstractServerHttpResponse
This commit fixes test failures introduced earlier in commit 9f8e84.
2016-10-13 17:10:51 -04:00
Rossen Stoyanchev c1e5e3a87e Polish AsyncListener in ServletHttpHandlerAdapter 2016-10-13 16:31:53 -04:00
Violeta Georgieva 7e94377382 Handle async operation events
Problem:
The following exception is observed on an async timeout:
"java.lang.IllegalStateException: It is invalid to call
isReady() when the response has not been put into non-blocking mode"

Current Implementation:
The async operation events sent by the web container are not propagated
to the internal implementation. When timeout/error happens and if the
application does not complete the async operation, the web container
will complete it. At that point if the application tries to read/write,
the operation will fail with an exception (above) that there is not
async operation started.

Proposed Solution:
On async timeout or error, make calls to:
- AbstractRequestBodyPublisher.onError,
- AbstractResponseBodyProcessor.onError,
- AbstractResponseBodyFlushProcessor.onError
As a result of these calls the async operation will be completed and no
more invocations of read/write will be made.
2016-10-13 16:14:33 -04:00
Rossen Stoyanchev 9f8e8458c1 Polish AbstractServerHttpResponse
This commit simplifies the logic for applying beforeCommit actions
replacing the use of chained Mono.then calls with a single
Flux.concat.

Also renamed writeStatusCode, writeHeaders, and writeCookies to
applyStatusCode, applyHeaders, and applyCookies respectively to
better reflect we're simply setting them on the underlying response
(not necessarily written yet).
2016-10-13 16:04:30 -04:00
Sam Brannen 8cf1933148 Only print request/response body if char enc is present in MVC Test
Commit e65a1a4372 introduced support in PrintingResultHandler for only
printing the request or response body in the Spring MVC Test framework
if the content type is known to be text-based (e.g., plain text, HTML,
XHTML, XML, JSON, etc.). For unknown content types the body is assumed
to be text-based and is therefore always printed. The latter behavior,
however, is undesirable since the content may in fact not be text-based.

This commit addresses this issue by making the printing of the request
or response body an opt-in feature. Specifically, if a character
encoding has been set, the request or response body will be printed by
the PrintingResultHandler. Note, however, that the character encoding
is set to ISO-8859-1 in MockHttpServletResponse by default.

In addition, MockHttpServletRequest's getContentAsString() method now
throws an IllegalStateException if the character encoding has not been
set.

Issue: SPR-14776
2016-10-13 16:55:14 +02:00
Rossen Stoyanchev 1de73b9b4f Polish 2016-10-11 20:20:40 -04:00
Rossen Stoyanchev b28b3e8877 Add WebExchangeDataBinder
Issue: SPR-14541
2016-10-11 20:20:40 -04:00
Sebastien Deleuze 9bf8489afd Remove duplicated elements in CorsConfiguration#combine()
Issue: SPR-14792
2016-10-11 10:38:34 +02:00
Sebastien Deleuze 196c73fa50 Polish CorsConfigurationTests 2016-10-11 10:03:12 +02:00
Rossen Stoyanchev 33c48e7a17 Polish reactive CORS support 2016-10-10 18:00:11 -04:00
Sebastien Deleuze e31a2f778b Add Reactive CORS support
This is a port of Spring MVC CORS support for Spring Web Reactive:
 - CORS classes keep the same name but are in the
   web.cors.reactive package
 - CorsConfiguration is reused because not tied to Servlet API
 - CORS HandlerMapping integration is done at
   AbstractHandlerMapping level
 - AbstractUrlHandlerMapping and AbstractHandlerMethodMapping
   have been slightly modified to call
   AbstractHandlerMapping#processCorsRequest()
 - Both global CORS configuration + @CrossOrigin support have
   been implemented

Issue: SPR-14545
2016-10-10 18:00:05 -04:00
Sebastien Deleuze 0cc330e8fc Fix HttpRequest#getURI() with Netty based engines
Host and port are now properly retrieved from Reactor
Netty and RxNetty (the scheme is not available).

Issue: SPR-14794
2016-10-10 23:35:23 +02:00
Brian Clozel ea5ff87f8e Fix NumberFormatException with X-Forwarded-Host
This commit fixes `NumberFormatException`s that were thrown when parsing
IPv6 host values in `X-Forwarded-Host` request headers.

Issue: SPR-14761
2016-10-07 23:11:34 +02:00
Brian Clozel 53441f8962 Configure default SSL context in Netty RequestFactory
This commit configures a default SslContext if none has been provided.
This also enforces separate Netty bootstrap instances for cleartext and
TLS exchanges.

Issue: SPR-14744
2016-10-06 15:57:26 +02:00
Juergen Hoeller cfa0f6c84b Consistent final logger fields 2016-10-04 23:00:36 +02:00
Sebastien Deleuze 324c310cbd Log unresolved exceptions at error level 2016-10-04 16:08:59 +02:00
Brian Clozel 11aa920785 Remove RxJava 1.x variants of WebClient adapters
Issue: SPR-14743
2016-10-04 14:47:55 +02:00
Sam Brannen 04b8ae921e Introduce getContentAsByteArray()/getContentAsString() in MockHtttpSvltReq
In order to improve debugging and logging within test suites, this
commit introduces getContentAsByteArray() and getContentAsString()
methods in MockHttpServletRequest, analogous to the existing methods in
MockHttpServletResponse.

Issue: SPR-14717
2016-10-03 18:05:58 +02:00
Sebastien Deleuze dbc86ec043 Refine Jackson canEncode() / canDecode() implementation
This commit refine Jackson canEncode() / canDecode()
implementation by using ObjectMapper canSerialize() /
canDeserialize() methods.

Issue: SPR-14748
2016-09-27 23:59:44 +02:00
Sebastien Deleuze 44ceecc8b3 Imply text/event-stream when serializing ServerSentEvent
Issue: SPR-14748
2016-09-27 09:27:33 +02:00
Juergen Hoeller fb7ae010c8 Avoid unnecessary generics on emptyMap/Set/List 2016-09-26 18:04:49 +02:00