From b0ab84657b712aac59951420f4e9d696c3d84ba2 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 6 Jul 2017 13:37:21 +0200 Subject: [PATCH] Disable "failOnServerError" in ReactorClientHttpRequest This commit disables the "failOnServerError" feature on the `HttpClientRequest`, as wrapped by ReactorClientHttpRequest. 5xx errors are supposed to be dealt with in the WebClient, not in the lower-level components. Issue: SPR-15739 --- .../reactive/ReactorClientHttpRequest.java | 4 ++-- .../client/WebClientIntegrationTests.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java index bce2e1a51e1..e1042cb478f 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { HttpClientRequest httpRequest) { this.httpMethod = httpMethod; this.uri = uri; - this.httpRequest = httpRequest.failOnClientError(false); + this.httpRequest = httpRequest.failOnClientError(false).failOnServerError(false); this.bufferFactory = new NettyDataBufferFactory(httpRequest.alloc()); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 162c8b3a541..3d66178fcb9 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -370,6 +370,26 @@ public class WebClientIntegrationTests { Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath()); } + @Test + public void retrieveBodyToMonoInternalServerError() throws Exception { + this.server.enqueue(new MockResponse().setResponseCode(500) + .setHeader("Content-Type", "text/plain").setBody("Internal Server error")); + + Mono result = this.webClient.get() + .uri("/greeting?name=Spring") + .retrieve() + .bodyToMono(String.class); + + StepVerifier.create(result) + .expectError(WebClientException.class) + .verify(Duration.ofSeconds(3)); + + RecordedRequest recordedRequest = server.takeRequest(); + Assert.assertEquals(1, server.getRequestCount()); + Assert.assertEquals("*/*", recordedRequest.getHeader(HttpHeaders.ACCEPT)); + Assert.assertEquals("/greeting?name=Spring", recordedRequest.getPath()); + } + @Test public void retrieveToEntityNotFound() throws Exception { this.server.enqueue(new MockResponse().setResponseCode(404)