From 3a48682226615aaea3b63755c25763877c35dfd8 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 4 Dec 2019 18:17:46 +0000 Subject: [PATCH] Replace ReadCancellationException with takeWhile Closes gh-24125 --- .../web/reactive/function/BodyExtractors.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java index 391a5fbf90d..5dd63b72efb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -264,18 +264,11 @@ public abstract class BodyExtractors { () -> consumeAndCancel(message).then(Mono.empty()) : Mono::empty; } - private static Mono consumeAndCancel(ReactiveHttpInputMessage message) { - return message.getBody() - .map(buffer -> { - DataBufferUtils.release(buffer); - throw new ReadCancellationException(); - }) - .onErrorResume(ReadCancellationException.class, ex -> Mono.empty()) - .then(); - } - - @SuppressWarnings("serial") - private static class ReadCancellationException extends RuntimeException { + private static Flux consumeAndCancel(ReactiveHttpInputMessage message) { + return message.getBody().takeWhile(buffer -> { + DataBufferUtils.release(buffer); + return false; + }); } }