.filter((request, next) -> next.exchange(request).flatMap(response ->
{
List<String> headerValues = response.headers().header("Foo");
- return headerValues.isEmpty() ? Mono.error(
- new Exception("Response does not contain Foo header")) :
+ return headerValues.isEmpty() ? Mono.error(GraphApiException.create(response)) :
Mono.just(response);
}))
.build();
server
.enqueue(new MockResponse()
- .setResponseCode(400)
+ .setResponseCode(200)
.setHeader("Content-Type", "text/plain")
.setBody("Hello Spring!"));
- Mono<String> result = webClient.get()
+ Mono<String> result;
+
+ result = webClient.get()
.uri("/greeting?name=Spring")
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.expectError(Exception.class)
+ .verify(Duration.ofSeconds(90));
+
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(200)
+ .setHeader("Content-Type", "text/plain")
+ .setHeader("Foo", "Bar")
+ .setBody("Hello Spring!"));
+
+ result = webClient.get()
+ .uri("/greeting?name=Spring")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result)
+ .expectNext("Hello Spring!")
+ .expectComplete()
.verify(Duration.ofSeconds(3));
}
}