Go to file
Brian Clozel 038af9a303 Improve unknown status codes handling by WebClient
Prior to this commit, `WebClient` would throw `IllegalArgumentException`
when receiving an HTTP response with an unknown HTTP status code.

This commit is a follow up of SPR-16748 (supporting non-standard HTTP
status codes on the reactive `ClientHttpResponse`), and is mirroring
SPR-15978 (supporting non-standard HTTP status codes in `RestTemplate`).

With this change, `WebClient` now tolerates unknown status codes in some
cases, while not offering that choice as a first class citizen:
`HttpStatus` is still the preferred way to deal with HTTP status codes.

Here's how `WebClient` will behave when fetching the full response:

```
// Given a remote endpoint returning a "123" HTTP status code
Mono<ClientResponse> result = this.webClient.get()
				.uri("/status/123")
				.exchange();

// will still throw an IllegalArgumentException
HttpStatus status = result.block().statusCode();

// is safe and will return 123
int statusCode = result.block().rawStatusCode();
```

Resolving directly the response body with `retrieve()` is different.

```
// will send an error signal with a UnknownHttpStatusCodeException
Mono<String> result = this.webClient.get()
				.uri("/status/123")
				.retrieve()
				.bodyToMono(String.class);
```

In general, `WebClient` will provide high-level support
for well-known HTTP status codes, like error handling with
`WebClient.ResponseSpec#onStatus`.

For such support with unknown status codes, it is better to rely
on lower level constructs such as `ExchangeFilterFunction`.

Issue: SPR-16819
2018-07-12 19:08:08 +02:00
buildSrc Latest dependency updates (POI 3.17, Rome 1.8, EhCache 3.4, Caffeine 2.5.6, RxJava 2.1.4, Tomcat 8.5.21, JRuby 9.1.13, Rhino 1.7.7.2) 2017-09-23 11:28:19 +02:00
gradle Update eclipse setting and instructions 2018-06-25 17:56:53 -07:00
spring-aop Upgrade to Netty 4.1.27 and Commons Pool 2.6 2018-07-12 16:53:37 +02:00
spring-aspects JtaAnnotationTransactionAspect configured by default (in aspectj mode) 2018-06-29 19:43:38 +02:00
spring-beans RootBeanDefinition publicly exposes target type as ResolvableType 2018-07-10 19:28:12 +02:00
spring-context Upgrade to Netty 4.1.27 and Commons Pool 2.6 2018-07-12 16:53:37 +02:00
spring-context-indexer Move indexer implementation to index.processor subpackage (for Jigsaw) 2018-07-03 17:55:24 +02:00
spring-context-support Polishing 2018-06-28 14:51:33 +02:00
spring-core Switch defaults and model for logging sensitive data 2018-07-11 11:10:03 -04:00
spring-expression Polishing 2018-06-29 22:36:08 +02:00
spring-framework-bom Remove dependency management noise from POMs 2018-06-11 15:57:54 +02:00
spring-instrument Use consistent class design 2018-06-28 10:28:44 +02:00
spring-jcl LogFactoryService class for standard Commons Logging service discovery 2018-07-03 18:57:12 +02:00
spring-jdbc Polishing 2018-07-09 15:53:44 +02:00
spring-jms Polishing 2018-07-04 15:07:17 +02:00
spring-messaging Remove no-op classes in web-related Java config 2018-07-11 11:10:03 -04:00
spring-orm Polishing 2018-07-09 15:53:44 +02:00
spring-oxm Use tabs rather than spaces in tests 2018-06-28 10:28:44 +02:00
spring-test Correlated WebFlux server log messages 2018-07-05 08:27:13 -04:00
spring-tx Polishing 2018-07-09 15:53:44 +02:00
spring-web Improve expired session check algorithm 2018-07-11 15:59:18 -04:00
spring-webflux Improve unknown status codes handling by WebClient 2018-07-12 19:08:08 +02:00
spring-webmvc Warn when SimpleAsyncTaskExecutor is used 2018-07-11 11:10:03 -04:00
spring-websocket Conditional registration of task scheduler for SockJS 2018-07-11 11:10:03 -04:00
src Warn when SimpleAsyncTaskExecutor is used 2018-07-11 11:10:03 -04:00
.editorconfig Add EditorConfig 2017-06-12 08:07:54 +02:00
.gitignore
.mailmap
CODE_OF_CONDUCT.adoc
CONTRIBUTING.md Fix typo 2018-04-24 10:05:43 +02:00
README.md Update README.md 2017-11-28 09:28:34 -05:00
build.gradle Upgrade to Netty 4.1.27 and Commons Pool 2.6 2018-07-12 16:53:37 +02:00
gradle.properties Next Development Version 2018-04-03 20:11:32 +00:00
gradlew Upgrade to Gradle 4.1 2017-08-08 17:26:21 +02:00
gradlew.bat
import-into-eclipse.md Update eclipse setting and instructions 2018-06-25 17:56:53 -07:00
import-into-idea.md Polish 2017-05-29 17:04:10 +02:00
settings.gradle Cleanup settings.gradle pluginManagement configuration 2018-04-04 11:08:13 +02:00

README.md

Spring Framework

This is the home of the Spring Framework, the foundation for all Spring projects. Together the Spring Framework and the family of Spring projects make up what we call "Spring".

Spring provides everything you need beyond the Java language to create enterprise applications in a wide range of scenarios and architectures. Please read the Overview section in the reference for a more complete introduction.

Code of Conduct

This project is governed by the Spring Code of Conduct. By participating you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io.

Access to Binaries

For access to artifacts or a distribution zip, see the Spring Framework Artifacts wiki page.

Documentation

The Spring Frameworks maintains reference documentation (published and source), Github wiki pages, and an API reference. There are also guides and tutorials across Spring projects.

Build from Source

See the Build from Source wiki page and also CONTRIBUTING.md.

Stay in Touch

Follow @SpringCentral, @SpringFramework, and its team members on Twitter. In-depth articles can be found at The Spring Blog, and releases are announced via our news feed.

License

The Spring Framework is released under version 2.0 of the Apache License.