Commit Graph

1461 Commits

Author SHA1 Message Date
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
Josh Long 9b87ea017b fix spelling of word 'recommendation'
this PR fixes the spelling error for the word 'recommendation'
2016-09-21 15:03:04 -04:00
Juergen Hoeller 89717e1783 Reactive setup refinements 2016-09-21 11:24:20 +02:00
Brian Clozel 578af59f0c Polish byte-range resource handling 2016-09-20 23:46:21 +02:00
Juergen Hoeller 129d7bef6e Polishing 2016-09-20 22:41:20 +02:00
Juergen Hoeller d94ce0a1b2 Avoid package dependency cycles 2016-09-20 22:41:11 +02:00
Brian Clozel 5b33e02fb4 Add ClientHttpRequestInterceptor in WebClient
This commit adds a new chain-based, interception contract to be used
with `WebClient`. This is the HTTP client equivalent of the `WebFilter`
contract already implemented in web reactive server.

A `ClientHttpRequestInterceptor` implementation can transform the
outgoing HTTP request (method, URI or headers) before delegating it to
the next interceptor in the chain, or bypass the request processing
altogether and return a (cached) HTTP response.

Issue: SPR-14502
2016-09-20 18:15:07 +02:00
Brian Clozel c608103140 Add client HTTP request and response Mocks 2016-09-20 18:15:07 +02:00
Sebastien Deleuze f918a2b192 Rename beforeRead/Write() to resolveRead/WriteHints()
This commit also removes the ServerHttpResponse parameter, not
needed here since it is possible to override the write() method.

Issue: SPR-14557
2016-09-20 17:52:31 +02:00
Brian Clozel a7a9e36ca0 Add ResourceRegionHttpMessageWriter
This new `HttpMessageWriter` leverages the `ResourceRegionEncoder` to
write `ResourceRegion` to HTTP responses, thus supporting HTTP Range
requests.

Whenever possible, this message writer uses the zero copy support for
single range requests.

This `HttpMessageWriter` is never used directly, but is used as a
delegate by the `ResourceHttpMessageWriter`. When provided with the
`BOUNDARY_STRING_HINT`, the `ResourceRegionHttpMessageWriter`
adapts its behavior in order to write a single/multiple byte ranges.

Issue: SPR-14664
2016-09-20 16:18:45 +02:00
Brian Clozel 55d6f88dcd Add ResourceRegionEncoder
This commit adds the necessary infrastructure for the support of HTTP
Range requests. The new `ResourceRegionEncoder` can write
`ResourceRegion` objects as streams of bytes.

The `ResourceRegionEncoder` relies on an encoding hint
`BOUNDARY_STRING_HINT`. If present, the encoder infers that multiple
`ResourceRegion`s should be encoded and that the provided boundary
String should be used to separate ranges by mime boundaries.
If that hint is absent, only a single resource region is encoded.

Issue: SPR-14664
2016-09-20 16:14:22 +02:00
Sebastien Deleuze 1d46b8d7e1 Polish 2016-09-20 14:28:12 +02:00
Sebastien Deleuze 857e77eec2 Make ServerHttpMessageReader/Writer more powerful and flexible
This commit makes it possible, in addition to provide hints, to
perform additional operations with the request and the response
at ServerHttpMessageReader/Writer level.

AbstractServerHttpMessageReader/Writer now provide
convenient beforeRead/beforeWrite abstract methods for such need.

Issue: SPR-14557
2016-09-20 11:55:51 +02:00
Sebastien Deleuze 38f3d12e45 Do not provide hints for can*() methods anymore
Issue: SPR-14557
2016-09-20 11:55:51 +02:00
Sebastien Deleuze 1bf828a149 Polish 2016-09-19 16:32:50 +02:00
Sam Brannen b521aa879f Clean up warnings related to forthcoming removals in Tomcat 9 2016-09-17 16:16:06 +02:00
Rossen Stoyanchev b2ccdfbc9e Polish error logging for HTTP reactive server classes 2016-09-16 16:09:44 -04:00
Violeta Georgieva 80ff5ae9c5 Improve exception handling when clients disconnect.
Issue: SPR-14538
2016-09-16 16:09:43 -04:00
Brian Clozel c4b9b92247 Polish ResponseExtractors 2016-09-16 21:39:38 +02:00
Rob Winch b58a06208f Add HttpBasic ClientWebRequestPostProcessor
Issue: SPR-14682
2016-09-16 21:29:59 +02:00
Rossen Stoyanchev 0bace1b0ae Add getContextPath to ServerHttpRequest
Issue: SPR-14726
2016-09-16 15:21:48 -04:00
Rossen Stoyanchev cf2112f539 Update intializer for the reactive servlet adapter
Move the AbstractServletHttpHandlerAdapterInitializer together with
the other two base classes in spring-web-reactive. Since the
interface is in the web package, this avoids a package cycle.
Also add a mention in the reference.

Issue: SPR-14713
2016-09-16 12:57:16 -04:00
Arjen Poutsma 2b57a4d618 Add WebApplicationInitializers for Web Reactive
This commit introduces three new WebApplicationInitializers for use with
Spring Web Reactive:

 - The AbstractServletHttpHandlerAdapterInitializer registers a
 ServletHttpHandlerAdapter that wraps a user-provided HttpHandler.

 - The AbstractDispatcherHandlerInitializer registers a
 ServletHttpHandlerAdapter that wraps a DispatcherHandler (or any
 WebHandler). The handler is provided with an application context.

 - The AbstractAnnotationConfigDispatcherHandlerInitializer is a
 subclass of the above, creating an
 AnnotationConfigApplicationContext based no provided @Configuration
 classes.

Issue: SPR-14713
2016-09-16 12:57:16 -04:00
Sebastien Deleuze 9d8c089a21 Polish 2016-09-16 16:17:37 +02:00
Sebastien Deleuze 6cda08e94b Add Jackson @JsonView support
Issue: SPR-14693
2016-09-16 12:51:27 +02:00
Sebastien Deleuze e74c59bf30 Introduce ServerHttpMessageWriter/Reader to resolve hints
Issue: SPR-14693
2016-09-16 12:51:27 +02:00
Juergen Hoeller 6dc1898dbb Timeout exceptions as RuntimeExceptions
Issue: SPR-14669
2016-09-15 08:54:17 +02:00
Rossen Stoyanchev 765b47246a Improve async request timeout handling
Rather than setting the status to 503 directly from the timeout
interceptor which no longer seems to work reliably with Servlet
containers like Jetty even performing an additional ERROR dispatch back
to the original URL, we know rather set the DeferredResult to an
AsyncTimeoutException, which results in a dispatch and standard
handling within Spring MVC. This should be a more reliable way of
dealing with timeouts.

Issue: SPR-14669
2016-09-14 21:34:30 -04:00
Rossen Stoyanchev 8ccfecc406 Workaround for Content-Length issue in Reactor Netty
Issue: SPR-14643
2016-09-14 17:45:27 -04:00
Sebastien Deleuze fc52ddcd97 Polish 2016-09-13 15:03:13 +02:00
Sebastien Deleuze 4991b97887 Polish 2016-09-12 14:47:48 +02:00
Sebastien Deleuze aaba53f76a Allow to pass hints parameter in HttpMessageReader/Writer
Issue: SPR-14557
2016-09-12 11:13:27 +02:00
Sebastien Deleuze b91867cf45 Update Codec API to use Map<String, Object> for hints
Issue: SPR-14557
2016-09-12 11:08:01 +02:00
Brian Clozel cc5300c4d5 Align MVC checkNotModified with reactive support
Since SPR-14522, the web reactive framework supports checkNotModified
features. This commit aligns the existing MVC infrastructure with
web reactive's behavior.

Because of the new Servlet 3.0 baseline, some constraints
aren't relevant anymore and duplicate code has been removed in
`HttpEntityMethodProcessor`.

Issue: SPR-14659
2016-09-06 18:02:48 +02:00
Violeta Georgieva 00617d74de Fix AbstractRequestBodyPublisher to comply with the spec
As per specification "The Subscription MUST allow the Subscriber to
call Subscription.request synchronously from within onNext or
onSubscribe". With the current implementation if Subscription.request
is called more than once when Subscriber.onSubscribe ISE will be
thrown - java.lang.IllegalStateException: DEMAND.
With this fix the implementation will not throw ISE and will allow
many invocations of Subscription.request when
Subscriber.onSubscribe.
2016-09-02 23:37:20 +02:00
Rossen Stoyanchev a1ac51256a Add MockServerHttpRequest/Response to spring-test
Issue: SPR-14421
2016-09-02 12:15:00 -04:00
Rossen Stoyanchev 73752c295d Refactor location of MockServerHttpRequest/Response
This change puts the MockHttpServerRequest/Response under
org.springframework.mock.http.server.reactive.test which
mirrors the arrangement we have with the Servlet mock equivalents
and sets up the addition of MockHttpServerRequest/Response in
spring-test.

Issue: SPR-14421
2016-09-02 12:15:00 -04:00
Rossen Stoyanchev e17132c217 Polish MockServerHttpRequest
Issue: SPR-14421
2016-09-02 12:15:00 -04:00
Rossen Stoyanchev 0681519255 Add checkNotModified support for view resolution
Issue: SPR-14522
2016-09-01 18:07:23 -04:00
Rossen Stoyanchev 6071e01168 Add checkNotModified support in ServerWebExchange
Issue: SPR-14522
2016-09-01 17:44:51 -04:00
Sebastien Deleuze 02bed0a34b Polishing 2016-09-01 17:15:50 +02:00
Sebastien Deleuze 06d4bb6a1a Let users control SSE stream completion
This commit avoid merging automatically the SSE stream with
Flux.never(). Since browsers automatically reconnect when
the HTTP connection is closed, it is now the user responsability
to optionally perform a concatWith(Flux.never()) on streams that
complete in order to avoid receiving the data multiple times on
client side.

The behavior with hot streams that never complete does not change.

Issue: SPR-14578
2016-09-01 17:14:24 +02:00
Arjen Poutsma 16b525f698 Refactored SseEvent to ServerSentEvent
- Renamed SseEvent to ServerSentEvent to make the name less redundant.
 - ServerSentEvent is now immutable, having a builder to create new instances.
 - Realigned the class properties to more closely match the events
   described in the spec, so that `reconnectTime` becomes `retry`, and
   `name` becomes `event`.
2016-09-01 13:47:50 +02:00
Arjen Poutsma 35cf4f173b Copied getAndSub() over from Reactor
Operators.getAndSub was removed in Reactor 3.0.1, this commit copies the
implementation over to AbstractRequestBodyPublisher, which used it.
2016-09-01 11:16:01 +02:00
Juergen Hoeller e08b1b75b6 @PathVariable supports 'required' attribute (for model attribute methods)
Issue: SPR-14646
2016-08-31 14:43:39 +02:00
Juergen Hoeller ab9fea6b8d Polishing
(cherry picked from commit 3767092)
2016-08-31 02:08:31 +02:00
Juergen Hoeller 31c5644691 ResponseStatusExceptionHandler in web.server.handler (plus related polishing) 2016-08-30 23:58:14 +02:00
Juergen Hoeller 03609c1518 Consistent comma splitting without regex overhead
Issue: SPR-14635
2016-08-30 23:56:58 +02:00
Rossen Stoyanchev 391752abc2 Polish and update reactive getting started reference
This commit updates the instructions on getting started with
Spring Web Reactive and also updates constructors and setters to
streamline the getting started procedure.

Issue: SPR-14640
2016-08-30 14:36:19 -04:00
Juergen Hoeller 2aab08f093 Polishing 2016-08-30 12:59:40 +02:00
Juergen Hoeller 58ffca76c3 CommonsMultipartResolver explicitly converts FileSizeLimitExceededException
Issue: SPR-14638
2016-08-30 12:57:46 +02:00
Sebastien Deleuze e8530c917e Add Smile and CBOR Jackson data formats support
This commit adds Smile and CBOR Jackson HttpMessageConverters
and make it possible to create Smile and CBOR ObjectMapper via
Jackson2ObjectMapperBuilder, which now allows to specify any
custom JsonFactory.

Like with JSON and XML Jackson support, the relevant
HttpMessageConverters are automaticially configurered by
Spring MVC WebMvcConfigurationSupport if jackson-dataformat-smile
or jackson-dataformat-cbor dependencies are found in the classpath.

Issue: SPR-14435
2016-08-30 11:06:40 +02:00
Rossen Stoyanchev 3b95e0b6e0 Fix media type regression in resource handling
Issue: SPR-14577
2016-08-29 16:27:24 -04:00
Sebastien Deleuze 417a9d4559 Ensure correct array elements order in Jackson2JsonEncoder
Issue: SPR-14586
2016-08-29 16:22:25 +02:00
Sam Brannen d6d05e8ca0 Remove trailing whitespace in Java source code 2016-08-29 15:25:10 +02:00
Juergen Hoeller dfdfd72a3e Polishing
(cherry picked from commit 430180a)
2016-08-26 18:59:40 +02:00
Brian Clozel b84fefc430 Wrap RestTemplate extractor exceptions in RestClientExceptions
When using a `RestTemplate` instance within a Spring MVC application,
client exceptions may propagate in the MVC stack and can be wrongly
mapped by server `ExceptionHandlers`, leading to a wrong HTTP response
sent to the MVC client.

The `RestTemplate` instance uses `HttpMessageConverter` to decode
the remote service responses; and when those fail decoding an HTTP
response, they can throw an `HttpMessageNotReadableException`. That
exception then bubbles up through the `HttpMessageConverterExtractor`,
`RestTemplate` and the whole MVC stack, later mapped to HTTP 400
responses, since those exceptions can also be throws by the server stack
when the incoming requests can't be deserialized.

This commit wraps all `IOException` and `HttpMessageNotReadableException`
instances thrown by the extractor into `RestClientException`` instances.
It's now easier to consistently handle client exceptions and avoid such
edge cases.

Issue: SPR-13592
2016-08-26 17:56:00 +02:00
Brian Clozel d8fc13f6fc Fix server errors for invalid If-None-Match request headers
HttpEntityMethodProcessor should not throw IllegalArgumentExceptions for
invalid If-None-Match headers.

For those cases, this commit makes sure that both
`HttpEntityMethodProcessor` and `ServletWebRequest` have a consistent
behavior and stop processing the request as conditional and leave the
handler handle it.

Issue: SPR-14559
2016-08-26 15:48:47 +02:00
Juergen Hoeller 2e4a7480fc Consistent use of JDK 7 StandardCharsets over Charset.forName
Issue: SPR-14492
2016-08-26 14:16:19 +02:00
Juergen Hoeller a8f7f75f64 Moved encodeHttpHeaderFieldParam method to HttpHeaders itself (including tests)
This commit also sets the test source encoding to UTF-8.

Issue: SPR-14547
2016-08-26 11:14:02 +02:00
Brian Clozel f93cb2f539 Support ordered interceptors in RestTemplate
This commit sorts `ClientHttpRequestInterceptor`s when those are set in
`InterceptingHttpAccessor` (which `RestTemplate` extends from).

Interceptors can now be annotated with `@Order` or implements `Ordered`
to reflect their order of execution for each request.

Issue: SPR-13971
2016-08-25 17:14:09 +02:00
Arjen Poutsma ab7107c4c5 Added Host property to HttpHeaders
Added getHost/setHost to HttpHeaders, returning/taking a
InetSocketAddress.
2016-08-25 15:49:07 +02:00
Brian Clozel f2faf84f31 Add RFC5987 support for HTTP header field params
This commit adds support for HTTP header field parameters encoding, as
described in RFC5987.
Note that the default implementation still relies on US-ASCII encoding,
as the latest rfc7230 Section 3.2.4 says that:

> Newly defined header fields SHOULD limit their field values to
  US-ASCII octets

Issue: SPR-14547
2016-08-25 14:26:58 +02:00
Juergen Hoeller d9d84ff388 Polishing 2016-08-24 11:40:24 +02:00
Juergen Hoeller d047174c6b Unit test for empty Access-Control-Request-Headers (Chrome 52)
Includes optimized method/header resolution in CorsConfiguration.

Issue: SPR-14617
2016-08-24 11:40:18 +02:00
Brian Clozel e4575330c3 Support empty body in Jackson2JsonDecoder.decodeToMono
Prior to this commit, extracting an HTTP response with an empty body
and no Content-Type header using the WebClient would:

* trigger the use of the Jackson2JsonDecoder
* throw a NoSuchElementException because of the use of `Flux.single()`

This commit changes this behavior to `Flux.singleOrEmpty()` to avoid
throwing exceptions for empty Flux instances.

Issue: SPR-14582
2016-08-23 16:10:41 +02:00
Erik Olsson 64bc0ca744 Add ClientOptions support in ReactorClientHttpConnector
Default ClientOptions enable SSL support.

Issue: SPR-14593
2016-08-23 11:17:12 +02:00
Rob Winch d48c32e7f6 Fix reactor-core 3.0.0.RELEASE
Fix the build to work with reactor-core-3.0.0.RELEASE
2016-08-19 12:56:36 -05:00
Juergen Hoeller 7bb4ab6842 Various @since tags (and varargs on setInterceptors)
(cherry picked from commit 5222489)
2016-08-18 12:58:02 +02:00
Juergen Hoeller ab0d523cc0 Polishing
(cherry picked from commit 1932a9d)
2016-08-17 21:54:40 +02:00
Stephane Nicoll 2a4ee07cb3 Fix typo 2016-08-10 14:23:37 +02:00
Juergen Hoeller 59a24b406a Polishing 2016-08-10 14:20:42 +02:00
Rossen Stoyanchev cc288a0c4a Switch back to Reactor 3.0 snapshots 2016-08-08 16:42:30 -04:00
Juergen Hoeller aeec1245eb ClientWebRequestBuilders documentation fix
Issue: SPR-14561
2016-08-08 13:20:27 +02:00
Sebastien Deleuze 5531e80724 Anticipate reactor.test.TestSubscriber removal
reactor.test.TestSubscriber will not be part of Reactor Core
3.0.0 since it needs to be refactored to fit all the needs
expressed by the users. It is likely to be back later in one
of the Reactor Core 3.0.x releases.

This commit anticipate this removal by temporarily copying
TestSubscriber in spring-core test classes. As soon as
the new TestSubscriber will be available in Reactor Core,
Spring Framework reactive tests will use it again.
2016-08-08 11:24:21 +02:00
Sebastien Deleuze e86529ec90 Prevent StackOverflowError in AbstractJackson2HttpMessageConverter
Issue: SPR-14520
2016-08-04 11:20:38 -07:00
Juergen Hoeller 8109a8c288 Updated ServletHttpHandlerAdapter usage 2016-08-04 03:04:33 +02:00
Arjen Poutsma dfef4e09da Added HttpHandler contructor argument 2016-08-03 15:39:44 -07:00
Kamil Szymanski 4aea551e8e Use abbreviated expression lambda instead of statement lambda
Closes gh-1126
2016-07-30 12:54:59 +02:00
Rossen Stoyanchev d219054b0d Polish 2016-07-27 12:34:31 -04:00
Violeta Georgieva 301528665d Refactor AbstractResponseBodyFlushProcessor states
With the current state machine
- the implementation can hang after the last element when executing
on Jetty.
- in some cases there will be no flush after the last
Publisher<DataBuffer>.
2016-07-27 11:12:00 -04:00
Violeta Georgieva 4798a1eb02 Cancel Subscription when onError is invoked internally
AbstractResponseBodyProcessor.onError and
AbstractResponseBodyFlushProcessor.onError will be invoked when:
- The Publisher wants to signal with onError that there are failures.
Once onError is invoked the Subscription should be considered canceled.
- The internal implementation wants to signal with onError that there
are failures. In this use case the implementation should invoke
Subscription.cancel()
2016-07-27 11:12:00 -04:00
Violeta Georgieva 16939b7bc7 AbstractListenerServerHttpResponse improvements
This commit changes writeWithInternal(Publisher<DataBuffer> body).
It is implemented as writeAndFlushWith(Mono.just(body)).
2016-07-27 11:12:00 -04:00
Juergen Hoeller b9ab895743 Inferred generics for newSetFromMap arrangements
Issue: SPR-13188
2016-07-26 21:26:31 +02:00
Juergen Hoeller e03dea1d64 Polishing 2016-07-26 17:15:19 +02:00
Juergen Hoeller c13f8419f9 Minor revision of reactive support layout (ahead of 5.0 M1)
DataSourceUtils moved to main core.io.buffer package.
Consistently named Jackson2JsonDecoder/Encoder and Jaxb2XmlDecoder/Encoder.
Plenty of related polishing.
2016-07-26 15:39:32 +02:00
Juergen Hoeller c97bfd73ad Reintroduced XMLReaderFactory deprecation markers on JDK 9
Issue: SPR-14486
2016-07-25 14:12:29 +02:00
Sam Brannen 2b6971a20e Clean up deprecation warnings in spring-web 2016-07-23 17:17:50 +02:00
Sam Brannen 76aa7b1cd9 Delete unused imports in spring-web 2016-07-23 17:17:29 +02:00
Sam Brannen cb1b178405 Ensure Reactor & RxJava response extractors compile with Eclipse JDT 2016-07-23 17:15:18 +02:00
Brian Clozel b2e848737c Rename reactor.io.netty -> reactor.ipc.netty 2016-07-23 14:34:12 +02:00
Juergen Hoeller 382a931e7d Polishing 2016-07-22 22:28:20 +02:00
Juergen Hoeller e59a5993f3 Consistent support for multiple Accept headers
Issue: SPR-14506
2016-07-22 22:27:58 +02:00
Brian Clozel 6e54ed0df1 Add missing timeout in web-reactive IntegrationTests 2016-07-22 21:37:51 +02:00
Rossen Stoyanchev 10c90a677c Move http.converter.reactive to http.codec 2016-07-22 14:14:46 -04:00
Arjen Poutsma b0d7625e3e Reactor StringEncoder into CharSequenceEncoder
This commit refactors the StringEncoder to a CharSequenceEncoder, in
order to support StringBuilders, Groovy GStrings, etc.

Issue: https://github.com/spring-projects/spring-reactive/issues/120
2016-07-22 12:47:46 -04:00
Arjen Poutsma 436a98ec68 Polishing 2016-07-22 15:32:56 +02:00
Marius Grama 3635c9dbfe Update xmlunit library to version 2.1.0
xmlunit 2.1.0 is the latest release for xmlunit.
Most of the xmlunit functionality used within spring-framework
was done through the xmlunit 1.x helper class
`org.custommonkey.xmlunit.XMLAssert`.

As of xmlunit 2.0.0 most of the XML comparison methods are done
through hamcrest matchers exposed by the xmlunit-matchers
library. In some cases during the migration, the matchers
had to be customized with custom `NodeMatcher` or
`DifferenceEvaluator` instances in order to keep the assertions
correct (they were performed with xmlunit 1.x previously).

Issue: SPR-14043
2016-07-21 15:04:21 +02:00
Sebastien Deleuze 9fb8a2eb2e Add contextClass resolution to JacksonJsonDecoder
Issue: SPR-14158
2016-07-21 14:57:50 +02:00
Sebastien Deleuze 74158af1b9 Add JsonView and type resolution support to JacksonJsonDecoder
There is no contextClass support yet, we need to find a way to pass
this information to the codecs.

Issue: SPR-14158
2016-07-21 13:55:59 +02:00
Sebastien Deleuze 903770f008 Add JsonView and type resolution support to JacksonJsonEncoder
Issue: SPR-14158
2016-07-21 13:19:52 +02:00