Skip to content

Commit

Permalink
Add an actionable message when attribute of multipart is a file and n…
Browse files Browse the repository at this point in the history
…ot accessed as such

Closes: quarkusio#19677
  • Loading branch information
geoand committed Aug 28, 2021
1 parent d14bae5 commit d9dc0ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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<FormValue> 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;
}

Expand Down

0 comments on commit d9dc0ff

Please sign in to comment.