|
20 | 20 | import org.glassfish.jersey.client.spi.ConnectorProvider; |
21 | 21 | import org.glassfish.jersey.jackson.JacksonFeature; |
22 | 22 | import org.glassfish.jersey.logging.LoggingFeature; |
23 | | -import org.glassfish.jersey.media.multipart.FormDataBodyPart; |
24 | | -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; |
25 | | -import org.glassfish.jersey.media.multipart.MultiPart; |
26 | | -import org.glassfish.jersey.media.multipart.MultiPartFeature; |
| 23 | +import org.glassfish.jersey.media.multipart.*; |
27 | 24 |
|
28 | 25 | import javax.net.ssl.*; |
29 | 26 | import javax.ws.rs.client.*; |
@@ -87,7 +84,7 @@ public ApiClient() { |
87 | 84 | this.dateFormat = new RFC3339DateFormat(); |
88 | 85 |
|
89 | 86 | // Set default User-Agent. |
90 | | - setUserAgent("Swagger-Codegen/3.10.0-RC1/java"); |
| 87 | + setUserAgent("Swagger-Codegen/3.10.1/java"); |
91 | 88 |
|
92 | 89 | // Setup authentications (key: authentication name, value: authentication). |
93 | 90 | authentications = new HashMap<String, Authentication>(); |
@@ -1176,7 +1173,13 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co |
1176 | 1173 | if (contentType.startsWith("multipart/form-data")) { |
1177 | 1174 | MultiPart multiPart = new MultiPart(); |
1178 | 1175 | for (Entry<String, Object> param: formParams.entrySet()) { |
1179 | | - if (param.getValue() instanceof File) { |
| 1176 | + if (param.getValue() instanceof byte[]) { |
| 1177 | + byte[] bytes = (byte[]) param.getValue(); |
| 1178 | + FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) |
| 1179 | + .fileName(param.getKey()).size(bytes.length).build(); |
| 1180 | + |
| 1181 | + multiPart.bodyPart(new FormDataBodyPart(contentDisp, bytes, MediaType.APPLICATION_OCTET_STREAM_TYPE)); |
| 1182 | + } else if (param.getValue() instanceof File) { |
1180 | 1183 | File file = (File) param.getValue(); |
1181 | 1184 | FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()) |
1182 | 1185 | .fileName(file.getName()).size(file.length()).build(); |
@@ -1345,7 +1348,25 @@ public <T> T invokeAPI(String path, String method, List<Pair> queryParams, List< |
1345 | 1348 | } |
1346 | 1349 | } |
1347 | 1350 |
|
1348 | | - Entity<?> entity = (body == null) ? Entity.json("{}") : serialize(body, formParams, contentType); |
| 1351 | + Entity<?> entity = (body == null && formParams.isEmpty()) ? Entity.json("{}") : serialize(body, formParams, contentType); |
| 1352 | + |
| 1353 | + // Generate and add Content-Disposition header as per RFC 6266 |
| 1354 | + if (contentType.startsWith("multipart/form-data")) { |
| 1355 | + for (Entry<String, Object> param : formParams.entrySet()) { |
| 1356 | + if (param.getValue() instanceof byte[]) { |
| 1357 | + MultiPart mp = ((MultiPart) entity.getEntity()); |
| 1358 | + List<BodyPart> bodyParts = mp.getBodyParts(); |
| 1359 | + if (!bodyParts.isEmpty()) { |
| 1360 | + BodyPart bodyPart = bodyParts.get(0); |
| 1361 | + if (bodyPart.getContentDisposition() != null) { |
| 1362 | + String contentDispositionValue = bodyPart.getContentDisposition().toString(); |
| 1363 | + invocationBuilder = invocationBuilder.header("Content-Disposition", contentDispositionValue); |
| 1364 | + entity = Entity.entity(param.getValue(), "application/octet-stream"); |
| 1365 | + } |
| 1366 | + } |
| 1367 | + } |
| 1368 | + } |
| 1369 | + } |
1349 | 1370 |
|
1350 | 1371 | Response response = null; |
1351 | 1372 | String message = "error"; |
|
0 commit comments