From cfae40afb456c98b2a11be600096da89b8aacafd Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 14 Jan 2021 21:23:49 +0000 Subject: [PATCH] Return 415 for form data with @RequestBody in WebFlux Closes gh-26386 --- .../AbstractMessageReaderArgumentResolver.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java index 033581b81d..5d405af73d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -37,6 +37,7 @@ import org.springframework.core.codec.Hints; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.server.reactive.ServerHttpRequest; @@ -49,6 +50,7 @@ import org.springframework.web.bind.support.WebExchangeBindException; import org.springframework.web.bind.support.WebExchangeDataBinder; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport; +import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebInputException; import org.springframework.web.server.UnsupportedMediaTypeStatusException; @@ -155,8 +157,10 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho Object[] hints = extractValidationHints(bodyParam); if (mediaType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) { - return Mono.error(new IllegalStateException( - "In a WebFlux application, form data is accessed via ServerWebExchange.getFormData().")); + if (logger.isDebugEnabled()) { + logger.debug("Form data is accessed via ServerWebExchange.getFormData() in WebFlux."); + } + return Mono.error(new ResponseStatusException(HttpStatus.UNSUPPORTED_MEDIA_TYPE)); } if (logger.isDebugEnabled()) {