Skip to content

Commit e3fae27

Browse files
committed
Rename Mono#otherwise[Empty] to switch[onError/IfEmpty]
Issue: SPR-15318
1 parent cec36fe commit e3fae27

File tree

19 files changed

+23
-23
lines changed

19 files changed

+23
-23
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Mono<Void> apply(HttpServerRequest request, HttpServerResponse response)
5757
ReactorServerHttpResponse resp = new ReactorServerHttpResponse(response, bufferFactory);
5858

5959
return this.httpHandler.handle(req, resp)
60-
.otherwise(ex -> {
60+
.switchOnError(ex -> {
6161
logger.error("Could not complete request", ex);
6262
response.status(HttpResponseStatus.INTERNAL_SERVER_ERROR);
6363
return Mono.empty();

spring-web/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Observable<Void> handle(HttpServerRequest<ByteBuf> nativeRequest,
6666
RxNettyServerHttpResponse response = new RxNettyServerHttpResponse(nativeResponse, bufferFactory);
6767

6868
Publisher<Void> result = this.httpHandler.handle(request, response)
69-
.otherwise(ex -> {
69+
.switchOnError(ex -> {
7070
logger.error("Could not complete request", ex);
7171
nativeResponse.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
7272
return Mono.empty();

spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpReques
106106
if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
107107
return FORM_READER
108108
.readMono(FORM_DATA_VALUE_TYPE, request, Collections.emptyMap())
109-
.otherwiseIfEmpty(EMPTY_FORM_DATA)
109+
.switchIfEmpty(EMPTY_FORM_DATA)
110110
.cache();
111111
}
112112
}

spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public WebSessionManager getSessionManager() {
7676
public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
7777
ServerWebExchange exchange = createExchange(request, response);
7878
return getDelegate().handle(exchange)
79-
.otherwise(ex -> {
79+
.switchOnError(ex -> {
8080
if (logger.isDebugEnabled()) {
8181
logger.debug("Could not complete request", ex);
8282
}

spring-web/src/main/java/org/springframework/web/server/handler/ExceptionHandlingWebHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Mono<Void> handle(ServerWebExchange exchange) {
9999
}
100100

101101
for (WebExceptionHandler handler : this.exceptionHandlers) {
102-
completion = completion.otherwise(ex -> handler.handle(exchange, ex));
102+
completion = completion.switchOnError(ex -> handler.handle(exchange, ex));
103103
}
104104

105105
return completion;

spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public Mono<WebSession> getSession(ServerWebExchange exchange) {
105105
.concatMap(this.sessionStore::retrieveSession)
106106
.next()
107107
.flatMap(session -> validateSession(exchange, session))
108-
.otherwiseIfEmpty(createSession(exchange))
108+
.switchIfEmpty(createSession(exchange))
109109
.map(session -> extendSession(exchange, session)));
110110
}
111111

spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpResponseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void writeAndFlushWithFluxOfDefaultDataBuffer() throws Exception {
9696
public void writeWithError() throws Exception {
9797
TestServerHttpResponse response = new TestServerHttpResponse();
9898
IllegalStateException error = new IllegalStateException("boo");
99-
response.writeWith(Flux.error(error)).otherwise(ex -> Mono.empty()).block();
99+
response.writeWith(Flux.error(error)).switchOnError(ex -> Mono.empty()).block();
100100

101101
assertFalse(response.statusCodeWritten);
102102
assertFalse(response.headersWritten);

spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public Mono<Void> handle(ServerWebExchange exchange) {
125125
return Flux.fromIterable(this.handlerMappings)
126126
.concatMap(mapping -> mapping.getHandler(exchange))
127127
.next()
128-
.otherwiseIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
128+
.switchIfEmpty(Mono.error(HANDLER_NOT_FOUND_EXCEPTION))
129129
.flatMap(handler -> invokeHandler(exchange, handler))
130130
.flatMap(result -> handleResult(exchange, result));
131131
}
@@ -141,7 +141,7 @@ private Mono<HandlerResult> invokeHandler(ServerWebExchange exchange, Object han
141141

142142
private Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result) {
143143
return getResultHandler(result).handleResult(exchange, result)
144-
.otherwise(ex -> result.applyExceptionHandler(ex).flatMap(exceptionResult ->
144+
.switchOnError(ex -> result.applyExceptionHandler(ex).flatMap(exceptionResult ->
145145
getResultHandler(exceptionResult).handleResult(exchange, exceptionResult)));
146146
}
147147

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategi
168168
return Flux.fromStream(viewResolverStream)
169169
.concatMap(viewResolver -> viewResolver.resolveViewName(name(), locale))
170170
.next()
171-
.otherwiseIfEmpty(Mono.error(new IllegalArgumentException("Could not resolve view with name '" +
171+
.switchIfEmpty(Mono.error(new IllegalArgumentException("Could not resolve view with name '" +
172172
name() +"'")))
173173
.flatMap(view -> view.render(model(), contentType, exchange));
174174
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface RouterFunction<T extends ServerResponse> {
4848
*/
4949
default RouterFunction<T> and(RouterFunction<T> other) {
5050
return request -> this.route(request)
51-
.otherwiseIfEmpty(Mono.defer(() -> other.route(request)));
51+
.switchIfEmpty(Mono.defer(() -> other.route(request)));
5252
}
5353

5454
/**
@@ -63,7 +63,7 @@ default RouterFunction<T> and(RouterFunction<T> other) {
6363
default RouterFunction<?> andOther(RouterFunction<?> other) {
6464
return request -> this.route(request)
6565
.map(RouterFunctions::cast)
66-
.otherwiseIfEmpty(
66+
.switchIfEmpty(
6767
Mono.defer(() -> other.route(request).map(RouterFunctions::cast)));
6868
}
6969

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public static HttpWebHandlerAdapter toHttpHandler(RouterFunction<?> routerFuncti
234234
.defaultIfEmpty(notFound())
235235
.flatMap(handlerFunction -> wrapException(() -> handlerFunction.handle(request)))
236236
.flatMap(response -> wrapException(() -> response.writeTo(exchange, strategies)))
237-
.otherwise(ResponseStatusException.class,
237+
.switchOnError(ResponseStatusException.class,
238238
ex -> {
239239
exchange.getResponse().setStatusCode(ex.getStatus());
240240
if (ex.getMessage() != null) {

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected PathExtensionContentTypeResolver initContentNegotiationStrategy() {
276276
public Mono<Void> handle(ServerWebExchange exchange) {
277277

278278
return getResource(exchange)
279-
.otherwiseIfEmpty(Mono.defer(() -> {
279+
.switchIfEmpty(Mono.defer(() -> {
280280
logger.trace("No matching resource found - returning 404");
281281
exchange.getResponse().setStatusCode(HttpStatus.NOT_FOUND);
282282
return Mono.empty();

spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange, Str
159159
List<? extends Resource> locations, ResourceResolverChain chain) {
160160

161161
return chain.resolveResource(exchange, requestPath, locations)
162-
.otherwiseIfEmpty(Mono.defer(() ->
162+
.switchIfEmpty(Mono.defer(() ->
163163
resolveVersionedResource(exchange, requestPath, locations, chain)));
164164
}
165165

spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected Mono<Resource> resolveResourceInternal(ServerWebExchange exchange, Str
7575
List<? extends Resource> locations, ResourceResolverChain chain) {
7676

7777
return chain.resolveResource(exchange, requestPath, locations)
78-
.otherwiseIfEmpty(Mono.defer(() -> {
78+
.switchIfEmpty(Mono.defer(() -> {
7979
String webJarsResourcePath = findWebJarResourcePath(requestPath);
8080
if (webJarsResourcePath != null) {
8181
return chain.resolveResource(exchange, webJarsResourcePath, locations);
@@ -91,7 +91,7 @@ protected Mono<String> resolveUrlPathInternal(String resourceUrlPath,
9191
List<? extends Resource> locations, ResourceResolverChain chain) {
9292

9393
return chain.resolveUrlPath(resourceUrlPath, locations)
94-
.otherwiseIfEmpty(Mono.defer(() -> {
94+
.switchIfEmpty(Mono.defer(() -> {
9595
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
9696
if (webJarResourcePath != null) {
9797
return chain.resolveUrlPath(webJarResourcePath, locations);

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ protected Mono<Object> readBody(MethodParameter bodyParameter, boolean isBodyReq
130130
}
131131
else {
132132
Mono<?> mono = reader.readMono(bodyType, elementType, request, response, readHints);
133-
mono = mono.otherwise(ex -> Mono.error(getReadError(bodyParameter, ex)));
133+
mono = mono.switchOnError(ex -> Mono.error(getReadError(bodyParameter, ex)));
134134
if (isBodyRequired || (adapter != null && !adapter.supportsEmpty())) {
135-
mono = mono.otherwiseIfEmpty(Mono.error(getRequiredBodyError(bodyParameter)));
135+
mono = mono.switchIfEmpty(Mono.error(getRequiredBodyError(bodyParameter)));
136136
}
137137
Object[] hints = extractValidationHints(bodyParameter);
138138
if (hints != null) {

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Mono<Object> resolveArgument(
103103
handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange);
104104
return arg;
105105
})
106-
.otherwiseIfEmpty(getDefaultValue(
106+
.switchIfEmpty(getDefaultValue(
107107
namedValueInfo, parameter, bindingContext, model, exchange));
108108
}
109109

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
189189
.then(() -> this.methodResolver.getRequestMappingMethod(handlerMethod)
190190
.invoke(exchange, bindingContext)
191191
.doOnNext(result -> result.setExceptionHandler(exceptionHandler))
192-
.otherwise(exceptionHandler));
192+
.switchOnError(exceptionHandler));
193193
}
194194

195195
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod,

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult result)
193193
}
194194

195195
return valueMono
196-
.otherwiseIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
196+
.switchIfEmpty(exchange.isNotModified() ? Mono.empty() : NO_VALUE_MONO)
197197
.flatMap(returnValue -> {
198198

199199
Mono<List<View>> viewsMono;

src/docs/asciidoc/web/web-flux-functional.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class PersonHandler {
9595
Mono<Person> personMono = this.repository.getPerson(personId);
9696
return personMono
9797
.then(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person)))
98-
.otherwiseIfEmpty(notFound);
98+
.switchIfEmpty(notFound);
9999
}
100100
}
101101
----

0 commit comments

Comments
 (0)