From d9dc0ffec3527b2cd8b75fdd7274d19d4cd58d3d Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 26 Aug 2021 13:48:12 +0300 Subject: [PATCH] Add an actionable message when attribute of multipart is a file and not accessed as such Closes: #19677 --- .../MultipartPopulatorGenerator.java | 4 ++-- .../runtime/multipart/MultipartSupport.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/MultipartPopulatorGenerator.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/MultipartPopulatorGenerator.java index f05f9dd80b16b..e02091633f902 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/MultipartPopulatorGenerator.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/MultipartPopulatorGenerator.java @@ -394,11 +394,11 @@ static String generate(ClassInfo multipartClassInfo, ClassOutput classOutput, In String.class, Class.class, java.lang.reflect.Type.class, MediaType.class, - ResteasyReactiveRequestContext.class), + ResteasyReactiveRequestContext.class, String.class), formStrValueHandle, populate.readStaticField(typeField), populate.readStaticField(genericTypeField), populate.readStaticField(mediaTypeField), - rrCtxHandle)); + rrCtxHandle, formAttrNameHandle)); } } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/multipart/MultipartSupport.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/multipart/MultipartSupport.java index 979fb51e18c84..1ee6f0fe2278b 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/multipart/MultipartSupport.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/multipart/MultipartSupport.java @@ -20,6 +20,7 @@ import javax.ws.rs.ext.MessageBodyReader; import org.jboss.logging.Logger; +import org.jboss.resteasy.reactive.multipart.FileUpload; import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; import org.jboss.resteasy.reactive.server.core.ServerSerialisers; import org.jboss.resteasy.reactive.server.core.multipart.DefaultFileUpload; @@ -31,6 +32,7 @@ /** * This class isn't used directly, it is however used by generated code meant to deal with multipart forms. */ +@SuppressWarnings("unused") public final class MultipartSupport { private static final Logger log = Logger.getLogger(RequestDeserializeHandler.class); @@ -42,8 +44,22 @@ private MultipartSupport() { @SuppressWarnings({ "unchecked", "rawtypes" }) public static Object convertFormAttribute(String value, Class type, Type genericType, MediaType mediaType, - ResteasyReactiveRequestContext context) { + ResteasyReactiveRequestContext context, String attributeName) { if (value == null) { + FormData formData = context.getFormData(); + if (formData != null) { + Collection fileUploadsForName = formData.get(attributeName); + if (fileUploadsForName != null) { + for (FormData.FormValue fileUpload : fileUploadsForName) { + if (fileUpload.isFileItem()) { + log.debug("Attribute '" + attributeName + + "' of the multipart request is a file and therefore its value is not set. To obtain the contents of the file, use type '" + + FileUpload.class + "' as the field type."); + break; + } + } + } + } return null; }