Skip to content

Commit

Permalink
Rest Client Reactive: Multipart file name set to actual filename for …
Browse files Browse the repository at this point in the history
…path and file

fixes #19805
  • Loading branch information
michalszynkiewicz committed Sep 1, 2021
1 parent 127200b commit df90167
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public class JaxrsClientReactiveProcessor {
String.class, Object.class);
private static final MethodDescriptor MULTIVALUED_MAP_ADD = MethodDescriptor.ofMethod(MultivaluedMap.class, "add",
void.class, Object.class, Object.class);
private static final MethodDescriptor PATH_GET_FILENAME = MethodDescriptor.ofMethod(Path.class, "getFileName",
Path.class);
private static final MethodDescriptor OBJECT_TO_STRING = MethodDescriptor.ofMethod(Object.class, "toString", String.class);

static final DotName CONTINUATION = DotName.createSimple("kotlin.coroutines.Continuation");
private static final DotName UNI_KT = DotName.createSimple("io.smallrye.mutiny.coroutines.UniKt");
Expand Down Expand Up @@ -989,7 +992,7 @@ private ResultHandle createMultipartForm(MethodCreator methodCreator, ResultHand
formClass.name() + "." + field.name());
}
ResultHandle filePath = methodCreator.invokeVirtualMethod(
MethodDescriptor.ofMethod(File.class, "getPath", String.class), fieldValue);
MethodDescriptor.ofMethod(File.class, "toPath", Path.class), fieldValue);
addFile(methodCreator, multipartForm, formParamName, partType, filePath);
} else if (is(PATH, fieldClass, index)) {
// and so is path
Expand All @@ -998,9 +1001,7 @@ private ResultHandle createMultipartForm(MethodCreator methodCreator, ResultHand
"No @PartType annotation found on multipart form field of type Path: " +
formClass.name() + "." + field.name());
}
ResultHandle filePath = methodCreator.invokeInterfaceMethod(
MethodDescriptor.ofMethod(Path.class, "toString", String.class), fieldValue);
addFile(methodCreator, multipartForm, formParamName, partType, filePath);
addFile(methodCreator, multipartForm, formParamName, partType, fieldValue);
} else if (is(BUFFER, fieldClass, index)) {
// and buffer
addBuffer(methodCreator, multipartForm, formParamName, partType, fieldValue, field);
Expand Down Expand Up @@ -1047,6 +1048,9 @@ private ResultHandle createMultipartForm(MethodCreator methodCreator, ResultHand
*/
private void addFile(MethodCreator methodCreator, AssignableResultHandle multipartForm, String formParamName,
String partType, ResultHandle filePath) {
ResultHandle fileNamePath = methodCreator.invokeInterfaceMethod(PATH_GET_FILENAME, filePath);
ResultHandle fileName = methodCreator.invokeVirtualMethod(OBJECT_TO_STRING, fileNamePath);
ResultHandle pathString = methodCreator.invokeVirtualMethod(OBJECT_TO_STRING, filePath);
if (partType.equalsIgnoreCase(MediaType.APPLICATION_OCTET_STREAM)) {
methodCreator.assign(multipartForm,
// MultipartForm#binaryFileUpload(String name, String filename, String pathname, String mediaType);
Expand All @@ -1055,8 +1059,8 @@ private void addFile(MethodCreator methodCreator, AssignableResultHandle multipa
MethodDescriptor.ofMethod(MultipartForm.class, "binaryFileUpload",
MultipartForm.class, String.class, String.class, String.class,
String.class),
multipartForm, methodCreator.load(formParamName), methodCreator.load(formParamName),
filePath, methodCreator.load(partType)));
multipartForm, methodCreator.load(formParamName), fileName,
pathString, methodCreator.load(partType)));
} else {
methodCreator.assign(multipartForm,
// MultipartForm#textFileUpload(String name, String filename, String pathname, String mediaType);;
Expand All @@ -1065,8 +1069,8 @@ private void addFile(MethodCreator methodCreator, AssignableResultHandle multipa
MethodDescriptor.ofMethod(MultipartForm.class, "textFileUpload",
MultipartForm.class, String.class, String.class, String.class,
String.class),
multipartForm, methodCreator.load(formParamName), methodCreator.load(formParamName),
filePath, methodCreator.load(partType)));
multipartForm, methodCreator.load(formParamName), fileName,
pathString, methodCreator.load(partType)));
}
}

Expand Down

0 comments on commit df90167

Please sign in to comment.