|
165 | 165 | import io.quarkus.gizmo.CatchBlockCreator;
|
166 | 166 | import io.quarkus.gizmo.ClassCreator;
|
167 | 167 | import io.quarkus.gizmo.FieldDescriptor;
|
| 168 | +import io.quarkus.gizmo.ForEachLoop; |
168 | 169 | import io.quarkus.gizmo.MethodCreator;
|
169 | 170 | import io.quarkus.gizmo.MethodDescriptor;
|
170 | 171 | import io.quarkus.gizmo.ResultHandle;
|
@@ -2220,58 +2221,90 @@ private AssignableResultHandle createRestClientField(String name, ClassCreator c
|
2220 | 2221 | return client;
|
2221 | 2222 | }
|
2222 | 2223 |
|
2223 |
| - private void handleMultipartField(String formParamName, String partType, String partFilename, |
2224 |
| - String type, String parameterSignature, |
| 2224 | + private void handleMultipartField(IndexView index, String formParamName, String mimeType, String partFilename, |
| 2225 | + Type type, String parameterSignature, |
2225 | 2226 | ResultHandle fieldValue, AssignableResultHandle multipartForm,
|
2226 | 2227 | BytecodeCreator methodCreator,
|
2227 | 2228 | ResultHandle client, String restClientInterfaceClassName, ResultHandle parameterAnnotations,
|
2228 | 2229 | ResultHandle genericType, String errorLocation) {
|
2229 | 2230 |
|
2230 | 2231 | BytecodeCreator ifValueNotNull = methodCreator.ifNotNull(fieldValue).trueBranch();
|
2231 | 2232 |
|
| 2233 | + if (isCollection(type, index)) { |
| 2234 | + Type componentType = null; |
| 2235 | + if (type.kind() == PARAMETERIZED_TYPE) { |
| 2236 | + Type paramType = type.asParameterizedType().arguments().get(0); |
| 2237 | + if ((paramType.kind() == CLASS) || (paramType.kind() == PARAMETERIZED_TYPE)) { |
| 2238 | + componentType = paramType; |
| 2239 | + } |
| 2240 | + } |
| 2241 | + if (componentType == null) { |
| 2242 | + componentType = Type.create(Object.class); |
| 2243 | + } |
| 2244 | + ForEachLoop loop = ifValueNotNull.forEach(fieldValue); |
| 2245 | + BytecodeCreator block = loop.block(); |
| 2246 | + doHandleMultipartField(formParamName, mimeType, partFilename, componentType, null, loop.element(), |
| 2247 | + multipartForm, |
| 2248 | + methodCreator, |
| 2249 | + client, restClientInterfaceClassName, parameterAnnotations, genericType, errorLocation, block); |
| 2250 | + } else { |
| 2251 | + doHandleMultipartField(formParamName, mimeType, partFilename, type, parameterSignature, fieldValue, multipartForm, |
| 2252 | + methodCreator, |
| 2253 | + client, restClientInterfaceClassName, parameterAnnotations, genericType, errorLocation, ifValueNotNull); |
| 2254 | + } |
| 2255 | + } |
| 2256 | + |
| 2257 | + private void doHandleMultipartField(String formParamName, String mimeType, String partFilename, Type type, |
| 2258 | + String parameterSignature, ResultHandle fieldValue, AssignableResultHandle multipartForm, |
| 2259 | + BytecodeCreator methodCreator, ResultHandle client, String restClientInterfaceClassName, |
| 2260 | + ResultHandle parameterAnnotations, ResultHandle genericType, String errorLocation, |
| 2261 | + BytecodeCreator bytecodeCreator) { |
2232 | 2262 | // we support string, and send it as an attribute unconverted
|
2233 |
| - if (type.equals(String.class.getName())) { |
2234 |
| - addString(ifValueNotNull, multipartForm, formParamName, partType, partFilename, fieldValue); |
2235 |
| - } else if (type.equals(File.class.getName())) { |
| 2263 | + String typeStr = type.name().toString(); |
| 2264 | + if (typeStr.equals(String.class.getName())) { |
| 2265 | + addString(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, fieldValue); |
| 2266 | + } else if (typeStr.equals(File.class.getName())) { |
2236 | 2267 | // file is sent as file :)
|
2237 |
| - ResultHandle filePath = ifValueNotNull.invokeVirtualMethod( |
| 2268 | + ResultHandle filePath = bytecodeCreator.invokeVirtualMethod( |
2238 | 2269 | MethodDescriptor.ofMethod(File.class, "toPath", Path.class), fieldValue);
|
2239 |
| - addFile(ifValueNotNull, multipartForm, formParamName, partType, partFilename, filePath); |
2240 |
| - } else if (type.equals(Path.class.getName())) { |
| 2270 | + addFile(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, filePath); |
| 2271 | + } else if (typeStr.equals(Path.class.getName())) { |
2241 | 2272 | // and so is path
|
2242 |
| - addFile(ifValueNotNull, multipartForm, formParamName, partType, partFilename, fieldValue); |
2243 |
| - } else if (type.equals(FileUpload.class.getName())) { |
| 2273 | + addFile(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, fieldValue); |
| 2274 | + } else if (typeStr.equals(FileUpload.class.getName())) { |
2244 | 2275 | addFileUpload(fieldValue, multipartForm, methodCreator);
|
2245 |
| - } else if (type.equals(InputStream.class.getName())) { |
| 2276 | + } else if (typeStr.equals(InputStream.class.getName())) { |
2246 | 2277 | // and so is path
|
2247 |
| - addInputStream(ifValueNotNull, multipartForm, formParamName, partType, partFilename, fieldValue, type); |
2248 |
| - } else if (type.equals(Buffer.class.getName())) { |
| 2278 | + addInputStream(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, fieldValue, typeStr); |
| 2279 | + } else if (typeStr.equals(Buffer.class.getName())) { |
2249 | 2280 | // and buffer
|
2250 |
| - addBuffer(ifValueNotNull, multipartForm, formParamName, partType, partFilename, fieldValue, errorLocation); |
2251 |
| - } else if (type.startsWith("[")) { |
| 2281 | + addBuffer(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, fieldValue, errorLocation); |
| 2282 | + } else if (typeStr.startsWith("[")) { |
2252 | 2283 | // byte[] can be sent as file too
|
2253 |
| - if (!type.equals("[B")) { |
2254 |
| - throw new IllegalArgumentException("Array of unsupported type: " + type |
| 2284 | + if (!typeStr.equals("[B")) { |
| 2285 | + throw new IllegalArgumentException("Array of unsupported type: " + typeStr |
2255 | 2286 | + " on " + errorLocation);
|
2256 | 2287 | }
|
2257 |
| - ResultHandle buffer = ifValueNotNull.invokeStaticInterfaceMethod( |
| 2288 | + ResultHandle buffer = bytecodeCreator.invokeStaticInterfaceMethod( |
2258 | 2289 | MethodDescriptor.ofMethod(Buffer.class, "buffer", Buffer.class, byte[].class),
|
2259 | 2290 | fieldValue);
|
2260 |
| - addBuffer(ifValueNotNull, multipartForm, formParamName, partType, partFilename, buffer, errorLocation); |
2261 |
| - } else if (parameterSignature.equals(MULTI_BYTE_SIGNATURE)) { |
2262 |
| - addMultiAsFile(ifValueNotNull, multipartForm, formParamName, partType, partFilename, fieldValue, errorLocation); |
2263 |
| - } else if (partType != null) { |
| 2291 | + addBuffer(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, buffer, errorLocation); |
| 2292 | + } else if (MULTI_BYTE_SIGNATURE.equals(parameterSignature)) { |
| 2293 | + addMultiAsFile(bytecodeCreator, multipartForm, formParamName, mimeType, partFilename, fieldValue, |
| 2294 | + errorLocation); |
| 2295 | + } else if (mimeType != null) { |
2264 | 2296 | if (partFilename != null) {
|
2265 | 2297 | log.warnf("Using the @PartFilename annotation is unsupported on the type '%s'. Problematic field is: '%s'",
|
2266 |
| - partType, formParamName); |
| 2298 | + mimeType, formParamName); |
2267 | 2299 | }
|
2268 | 2300 | // assume POJO:
|
2269 |
| - addPojo(ifValueNotNull, multipartForm, formParamName, partType, fieldValue, type); |
| 2301 | + addPojo(bytecodeCreator, multipartForm, formParamName, mimeType, fieldValue, typeStr); |
2270 | 2302 | } else {
|
2271 | 2303 | // go via converter
|
2272 |
| - ResultHandle convertedFormParam = convertParamToString(ifValueNotNull, client, fieldValue, type, genericType, |
| 2304 | + ResultHandle convertedFormParam = convertParamToString(bytecodeCreator, client, fieldValue, typeStr, |
| 2305 | + genericType, |
2273 | 2306 | parameterAnnotations);
|
2274 |
| - BytecodeCreator parameterIsStringBranch = checkStringParam(ifValueNotNull, convertedFormParam, |
| 2307 | + BytecodeCreator parameterIsStringBranch = checkStringParam(bytecodeCreator, convertedFormParam, |
2275 | 2308 | restClientInterfaceClassName, errorLocation);
|
2276 | 2309 | addString(parameterIsStringBranch, multipartForm, formParamName, null, partFilename, convertedFormParam);
|
2277 | 2310 | }
|
@@ -3327,9 +3360,9 @@ private void addFormParam(MethodInfo jandexMethod, BytecodeCreator methodCreator
|
3327 | 3360 | String restClientInterfaceClassName, ResultHandle client, AssignableResultHandle formParams,
|
3328 | 3361 | ResultHandle genericType,
|
3329 | 3362 | ResultHandle parameterAnnotations, boolean multipart,
|
3330 |
| - String partType, String partFilename, String errorLocation) { |
| 3363 | + String mimeType, String partFilename, String errorLocation) { |
3331 | 3364 | if (multipart) {
|
3332 |
| - handleMultipartField(paramName, partType, partFilename, parameterType.name().toString(), parameterSignature, |
| 3365 | + handleMultipartField(index, paramName, mimeType, partFilename, parameterType, parameterSignature, |
3333 | 3366 | formParamHandle,
|
3334 | 3367 | formParams, methodCreator,
|
3335 | 3368 | client, restClientInterfaceClassName, parameterAnnotations, genericType,
|
|
0 commit comments